mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Alternate handover batch TOCTOU fix (#397)
* Revert "Correct the prior documented TOCTOU" This reverts commitd50fe87801. * Correct the prior documented TOCTOUd50fe87801edited the challenge for the Batch to fix it. This won't produce Batch n+1 until Batch n is successfully published and verified. It's an alternative strategy able to be reviewed, with a much smaller impact to scope.
This commit is contained in:
@@ -52,18 +52,6 @@ impl<D: Db> SubstrateSignerDb<D> {
|
||||
D::key(b"SUBSTRATE_SIGNER", dst, key)
|
||||
}
|
||||
|
||||
fn first_batch_key(key: [u8; 32]) -> Vec<u8> {
|
||||
Self::sign_key(b"first_batch", key)
|
||||
}
|
||||
fn save_first_batch(txn: &mut D::Transaction<'_>, key: [u8; 32], id: u32) {
|
||||
txn.put(Self::first_batch_key(key), id.to_le_bytes());
|
||||
}
|
||||
fn first_batch<G: Get>(getter: &G, key: [u8; 32]) -> Option<u32> {
|
||||
getter
|
||||
.get(Self::first_batch_key(key))
|
||||
.map(|bytes| u32::from_le_bytes(bytes.try_into().unwrap()))
|
||||
}
|
||||
|
||||
fn completed_key(id: [u8; 32]) -> Vec<u8> {
|
||||
Self::sign_key(b"completed", id)
|
||||
}
|
||||
@@ -241,11 +229,6 @@ impl<D: Db> SubstrateSigner<D> {
|
||||
return;
|
||||
}
|
||||
|
||||
let group_key = self.keys.group_key().to_bytes();
|
||||
if SubstrateSignerDb::<D>::first_batch(txn, group_key).is_none() {
|
||||
SubstrateSignerDb::<D>::save_first_batch(txn, group_key, batch.id);
|
||||
}
|
||||
|
||||
self.signable.insert(id, batch);
|
||||
self.attempt(txn, id, 0).await;
|
||||
}
|
||||
@@ -287,13 +270,8 @@ impl<D: Db> SubstrateSigner<D> {
|
||||
Err(e) => todo!("malicious signer: {:?}", e),
|
||||
};
|
||||
|
||||
let batch = &self.signable[&id.id];
|
||||
let is_first_batch =
|
||||
SubstrateSignerDb::<D>::first_batch(txn, self.keys.group_key().to_bytes()).unwrap() ==
|
||||
batch.id;
|
||||
|
||||
let (machine, share) =
|
||||
match machine.sign(preprocesses, &batch_message(is_first_batch, batch)) {
|
||||
match machine.sign(preprocesses, &batch_message(&self.signable[&id.id])) {
|
||||
Ok(res) => res,
|
||||
Err(e) => todo!("malicious signer: {:?}", e),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user