prevent exploit via compute_arguments_hash bypass

Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
Uncle Stinky 2026-09-26 14:30:22 +03:00
parent 0162da4604
commit 77bf4419e0
Signed by: st1nky
GPG Key ID: 016064BD97603B40
2 changed files with 10 additions and 14 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "ghost-weaver" name = "ghost-weaver"
version = "0.0.14" version = "0.0.15"
description = "Weaving a secure cryptographic tapestry across different external chains." description = "Weaving a secure cryptographic tapestry across different external chains."
license.workspace = true license.workspace = true
authors.workspace = true authors.workspace = true

View File

@ -14,7 +14,6 @@ use ghost_helpers::{
merkle_tree::verify_tree_proof, merkle_tree::verify_tree_proof,
SubstrateBlake2Hasher, SubstrateKeccakHasher, UtxoSha2Hasher, SubstrateBlake2Hasher, SubstrateKeccakHasher, UtxoSha2Hasher,
}; };
use ghost_traits::hashing::GhostHasher;
use crate::{ExternalBlockNumber, ThreadId, WeavingSession}; use crate::{ExternalBlockNumber, ThreadId, WeavingSession};
@ -350,8 +349,10 @@ where
{ {
if EVM_MERKLE_DEPTH as usize != self.proof.len() { return None; } if EVM_MERKLE_DEPTH as usize != self.proof.len() { return None; }
let preimage_hash = self.get_preimage_hash(network_id)?;
let proof_valid = verify_tree_proof::<SubstrateKeccakHasher, _>( let proof_valid = verify_tree_proof::<SubstrateKeccakHasher, _>(
&self.get_preimage_slice(network_id).to_fixed_bytes(), &preimage_hash.to_fixed_bytes(),
self.proof.as_ref(), self.proof.as_ref(),
root_hash, root_hash,
self.proof_index, self.proof_index,
@ -362,22 +363,17 @@ where
Some((self.receiver.clone(), self.amount)) Some((self.receiver.clone(), self.amount))
} }
fn get_preimage_slice<NetworkId>(&self, network_id: NetworkId) -> H256 fn get_preimage_hash<NetworkId>(&self, network_id: NetworkId) -> Option<H256>
where where
NetworkId: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u64>, NetworkId: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u64>,
{ {
let slot_index_usize: usize = self.slot_index.unique_saturated_into(); let slot_index_usize: usize = self.slot_index.unique_saturated_into();
let mut slot_values: Vec<H256> = self.slots.to_vec();
match slot_values.get_mut(slot_index_usize) { self.slots.get(slot_index_usize)
Some(slot) => { .filter(|&&provided_hash| {
*slot = self.compute_arguments_hash(network_id); provided_hash == self.compute_arguments_hash(network_id)
cumulative_hash::<SubstrateKeccakHasher, _>(slot_values) })
} .map(|_| cumulative_hash::<SubstrateKeccakHasher, _>(self.slots.iter()))
None => {
SubstrateKeccakHasher::empty()
}
}
} }
pub fn get_unique_key<NetworkId>( pub fn get_unique_key<NetworkId>(