Skip to content

Commit ffbe02b

Browse files
committed
fix(target_chains/starknet): verify new guardian set before writing to storage
1 parent 26bbe4a commit ffbe02b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

target_chains/starknet/contracts/src/wormhole.cairo

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,35 +158,41 @@ mod wormhole {
158158
) {
159159
self.owner.write(owner);
160160
let set_index = 0;
161-
store_guardian_set(ref self, set_index, initial_guardians).unwrap_with_felt252();
161+
store_guardian_set(ref self, set_index, @initial_guardians).unwrap_with_felt252();
162162
}
163163

164164
fn store_guardian_set(
165-
ref self: ContractState, set_index: u32, guardians: Array<felt252>
165+
ref self: ContractState, set_index: u32, guardians: @Array<felt252>
166166
) -> Result<(), SubmitNewGuardianSetError> {
167167
if guardians.len() == 0 {
168168
return Result::Err(SubmitNewGuardianSetError::NoGuardiansSpecified.into());
169169
}
170170
if guardians.len() >= 256 {
171171
return Result::Err(SubmitNewGuardianSetError::TooManyGuardians.into());
172172
}
173-
let set = GuardianSet { num_guardians: guardians.len(), expiration_time: 0 };
174-
self.guardian_sets.write(set_index, set);
173+
175174
let mut i = 0;
176175
let mut result = Result::Ok(());
177176
while i < guardians.len() {
178-
let key = *guardians.at(i);
179-
if key == 0 {
177+
if *guardians.at(i) == 0 {
180178
result = Result::Err(SubmitNewGuardianSetError::InvalidGuardianKey.into());
181179
break;
182180
}
181+
i += 1;
182+
};
183+
result?;
184+
185+
let set = GuardianSet { num_guardians: guardians.len(), expiration_time: 0 };
186+
self.guardian_sets.write(set_index, set);
187+
i = 0;
188+
while i < guardians.len() {
189+
let key = *guardians.at(i);
183190
// i < 256
184191
self
185192
.guardian_keys
186193
.write((set_index, i.try_into().expect(UNEXPECTED_OVERFLOW)), key.into());
187194
i += 1;
188195
};
189-
result?;
190196
self.current_guardian_set_index.write(set_index);
191197
Result::Ok(())
192198
}
@@ -210,10 +216,11 @@ mod wormhole {
210216
if set_index != current_set_index + 1 {
211217
return Result::Err(SubmitNewGuardianSetError::InvalidGuardianSetSequence.into());
212218
}
219+
store_guardian_set(ref self, set_index, @guardians)?;
213220
expire_guardian_set(
214221
ref self, current_set_index, execution_info.block_info.unbox().block_timestamp
215222
);
216-
store_guardian_set(ref self, set_index, guardians)
223+
Result::Ok(())
217224
}
218225

219226
fn parse_and_verify_vm(

0 commit comments

Comments
 (0)