Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpverify: don't panic when verification fails #1230

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions processor/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ pub enum ExecutionError {
value: Felt,
},
MemoryAddressOutOfBounds(u64),
MerklePathVerificationFailed {
value: Word,
index: Felt,
root: Digest,
},
MerkleStoreMergeFailed(MerkleError),
MerkleStoreLookupFailed(MerkleError),
MerkleStoreUpdateFailed(MerkleError),
Expand Down Expand Up @@ -146,6 +151,11 @@ impl Display for ExecutionError {
MemoryAddressOutOfBounds(addr) => {
write!(f, "Memory address cannot exceed 2^32 but was {addr}")
}
MerklePathVerificationFailed { value, index, root } => {
let value = to_hex(Felt::elements_as_bytes(value))?;
let root = to_hex(&root.as_bytes())?;
write!(f, "Merkle path verification failed for value {value} at index {index}, in the Merkle tree with root {root}")
}
MerkleStoreLookupFailed(reason) => {
write!(f, "Advice provider Merkle store backend lookup failed: {reason}")
}
Expand Down
7 changes: 7 additions & 0 deletions processor/src/operations/crypto_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ where
// Asserting the computed root of the Merkle path from the advice provider is consistent with
// the input root.
assert_eq!(root, computed_root, "inconsistent Merkle tree root");
if root == computed_root {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably remove assert_eq from here and the the condition for the if statement should be root != computed_root - right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the comment should be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops - and it should have been !=. Fixed

return Err(ExecutionError::MerklePathVerificationFailed {
value: node,
index,
root: root.into(),
});
}

// The same state is copied over to the next clock cycle with no changes.
self.stack.copy_state(0);
Expand Down
Loading