Alternate handover batch TOCTOU fix (#397)

* Revert "Correct the prior documented TOCTOU"

This reverts commit d50fe87801.

* Correct the prior documented TOCTOU

d50fe87801 edited 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:
Luke Parker
2023-10-13 12:14:59 -04:00
committed by GitHub
parent 7d0d1dc382
commit f6e8bc3352
9 changed files with 144 additions and 78 deletions

View File

@@ -165,7 +165,7 @@ pub async fn batch(
let signature = Signature(
schnorrkel::keys::Keypair::from_bytes(&schnorrkel_key_pair)
.unwrap()
.sign_simple(b"substrate", &batch_message(batch.id == 0, &batch))
.sign_simple(b"substrate", &batch_message(&batch))
.to_bytes(),
);

View File

@@ -137,10 +137,8 @@ pub(crate) async fn sign_batch(
messages::substrate::ProcessorMessage::SignedBatch { batch: this_batch },
) => {
if batch.is_none() {
assert!(PublicKey::from_raw(key).verify(
&batch_message(this_batch.batch.id == 0, &this_batch.batch),
&this_batch.signature
));
assert!(PublicKey::from_raw(key)
.verify(&batch_message(&this_batch.batch), &this_batch.signature));
batch = Some(this_batch.clone());
}