Skip to content

Commit 4feebce

Browse files
m0arsmrz2001
andauthored
fix: compare hashes instead of CIDs for anchor proof validation (#754)
The blockchain only stores the 32-byte hash, not the CID codec. When validating single-event anchors where the original event uses dag-jose codec, reconstruction assumed dag-cbor, causing validation failure. Since the security property we care about is that the hash matches, compare hashes directly rather than full CIDs. Co-authored-by: Mohsin Zaidi <2236875+smrz2001@users.noreply.github.com>
1 parent 89b1c0c commit 4feebce

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

  • event-svc/src/event/validator

event-svc/src/event/validator/time.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ impl TimeEventValidator {
8787

8888
let chain_proof = provider.get_chain_inclusion_proof(event.proof()).await?;
8989

90-
// Compare the root CID in the TimeEvent's AnchorProof to the root CID that was actually
91-
// included in the transaction onchain.
92-
if chain_proof.root_cid != event.proof().root() {
90+
// Compare the root hash in the TimeEvent's AnchorProof to the root hash that was actually
91+
// included in the transaction onchain. We compare hashes (not full CIDs) because the
92+
// blockchain only stores the hash - the codec is not preserved on-chain.
93+
if chain_proof.root_cid.hash() != event.proof().root().hash() {
9394
return Err(eth_rpc::Error::InvalidProof(format!(
94-
"the root CID is not in the transaction (anchor proof root={}, blockchain transaction root={})",
95+
"the root hash is not in the transaction (anchor proof root={}, blockchain transaction root={})",
9596
event.proof().root(),
9697
chain_proof.root_cid,
9798
)));
@@ -303,7 +304,7 @@ mod test {
303304
}
304305
Err(e) => match e {
305306
eth_rpc::Error::InvalidProof(e) => assert!(
306-
e.contains("the root CID is not in the transaction"),
307+
e.contains("the root hash is not in the transaction"),
307308
"{:#}",
308309
e
309310
),
@@ -338,7 +339,7 @@ mod test {
338339
}
339340
Err(e) => match e {
340341
eth_rpc::Error::InvalidProof(e) => assert!(
341-
e.contains("the root CID is not in the transaction"),
342+
e.contains("the root hash is not in the transaction"),
342343
"{:#}",
343344
e
344345
),

0 commit comments

Comments
 (0)