mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 04:09:23 +00:00
Correct the prior documented TOCTOU
Now, if a malicious validator set publishes a malicious `Batch` at the last moment, it'll cause all future `Batch`s signed by the next validator set to require a bool being set (yet they never will set it). This will prevent the handover. The only overhead is having two distinct `batch_message` calls on-chain.
This commit is contained in:
@@ -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))
|
||||
.sign_simple(b"substrate", &batch_message(batch.id == 0, &batch))
|
||||
.to_bytes(),
|
||||
);
|
||||
|
||||
|
||||
@@ -137,8 +137,10 @@ 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), &this_batch.signature));
|
||||
assert!(PublicKey::from_raw(key).verify(
|
||||
&batch_message(this_batch.batch.id == 0, &this_batch.batch),
|
||||
&this_batch.signature
|
||||
));
|
||||
|
||||
batch = Some(this_batch.clone());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user