fix(target_chains/starknet): verify new guardian set before writing to storage
This commit is contained in:
parent
26bbe4a0ef
commit
ffbe02b4f6
|
@ -158,11 +158,11 @@ mod wormhole {
|
||||||
) {
|
) {
|
||||||
self.owner.write(owner);
|
self.owner.write(owner);
|
||||||
let set_index = 0;
|
let set_index = 0;
|
||||||
store_guardian_set(ref self, set_index, initial_guardians).unwrap_with_felt252();
|
store_guardian_set(ref self, set_index, @initial_guardians).unwrap_with_felt252();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn store_guardian_set(
|
fn store_guardian_set(
|
||||||
ref self: ContractState, set_index: u32, guardians: Array<felt252>
|
ref self: ContractState, set_index: u32, guardians: @Array<felt252>
|
||||||
) -> Result<(), SubmitNewGuardianSetError> {
|
) -> Result<(), SubmitNewGuardianSetError> {
|
||||||
if guardians.len() == 0 {
|
if guardians.len() == 0 {
|
||||||
return Result::Err(SubmitNewGuardianSetError::NoGuardiansSpecified.into());
|
return Result::Err(SubmitNewGuardianSetError::NoGuardiansSpecified.into());
|
||||||
|
@ -170,23 +170,29 @@ mod wormhole {
|
||||||
if guardians.len() >= 256 {
|
if guardians.len() >= 256 {
|
||||||
return Result::Err(SubmitNewGuardianSetError::TooManyGuardians.into());
|
return Result::Err(SubmitNewGuardianSetError::TooManyGuardians.into());
|
||||||
}
|
}
|
||||||
let set = GuardianSet { num_guardians: guardians.len(), expiration_time: 0 };
|
|
||||||
self.guardian_sets.write(set_index, set);
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let mut result = Result::Ok(());
|
let mut result = Result::Ok(());
|
||||||
while i < guardians.len() {
|
while i < guardians.len() {
|
||||||
let key = *guardians.at(i);
|
if *guardians.at(i) == 0 {
|
||||||
if key == 0 {
|
|
||||||
result = Result::Err(SubmitNewGuardianSetError::InvalidGuardianKey.into());
|
result = Result::Err(SubmitNewGuardianSetError::InvalidGuardianKey.into());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
i += 1;
|
||||||
|
};
|
||||||
|
result?;
|
||||||
|
|
||||||
|
let set = GuardianSet { num_guardians: guardians.len(), expiration_time: 0 };
|
||||||
|
self.guardian_sets.write(set_index, set);
|
||||||
|
i = 0;
|
||||||
|
while i < guardians.len() {
|
||||||
|
let key = *guardians.at(i);
|
||||||
// i < 256
|
// i < 256
|
||||||
self
|
self
|
||||||
.guardian_keys
|
.guardian_keys
|
||||||
.write((set_index, i.try_into().expect(UNEXPECTED_OVERFLOW)), key.into());
|
.write((set_index, i.try_into().expect(UNEXPECTED_OVERFLOW)), key.into());
|
||||||
i += 1;
|
i += 1;
|
||||||
};
|
};
|
||||||
result?;
|
|
||||||
self.current_guardian_set_index.write(set_index);
|
self.current_guardian_set_index.write(set_index);
|
||||||
Result::Ok(())
|
Result::Ok(())
|
||||||
}
|
}
|
||||||
|
@ -210,10 +216,11 @@ mod wormhole {
|
||||||
if set_index != current_set_index + 1 {
|
if set_index != current_set_index + 1 {
|
||||||
return Result::Err(SubmitNewGuardianSetError::InvalidGuardianSetSequence.into());
|
return Result::Err(SubmitNewGuardianSetError::InvalidGuardianSetSequence.into());
|
||||||
}
|
}
|
||||||
|
store_guardian_set(ref self, set_index, @guardians)?;
|
||||||
expire_guardian_set(
|
expire_guardian_set(
|
||||||
ref self, current_set_index, execution_info.block_info.unbox().block_timestamp
|
ref self, current_set_index, execution_info.block_info.unbox().block_timestamp
|
||||||
);
|
);
|
||||||
store_guardian_set(ref self, set_index, guardians)
|
Result::Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_and_verify_vm(
|
fn parse_and_verify_vm(
|
||||||
|
|
Loading…
Reference in New Issue