-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: indexed protocol contracts tree (#11897)
Closes #11843 This PR converts the protocol contract address tree to an indexed tree. This is so: - If a user is calling a protocol contract address, its calculated address must be in the tree - If a user is NOT calling a protocol contract address, its calculated address must NOT be in the tree This required more changes than expected because the old code had this statement: ```rust let computed_protocol_contract_tree_root = if (MAX_PROTOCOL_CONTRACTS as Field).lt( protocol_contract_index, ) { 0 } else { root_from_sibling_path( computed_address.to_field(), protocol_contract_index, private_call_data.protocol_contract_sibling_path, ) }; assert( computed_address.eq(contract_address) | computed_protocol_contract_tree_root.eq(protocol_contract_tree_root), "computed contract address does not match expected one", ); ``` For many tests in and out of nr, we input `protocol_contract_tree_root = 0`. That meant that even if we weren't calling a protocol contract address, an incorrect `contract_address` would pass the assert statement. The current code does not allow this, so I had to update some old fixtures and provide a real root for all calls (not just protocol contract ones).
- Loading branch information
1 parent
921d2cd
commit 96e84d4
Showing
32 changed files
with
1,306 additions
and
578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
215 changes: 111 additions & 104 deletions
215
noir-projects/noir-protocol-circuits/crates/private-kernel-init/Prover.toml
Large diffs are not rendered by default.
Oops, something went wrong.
581 changes: 294 additions & 287 deletions
581
noir-projects/noir-protocol-circuits/crates/private-kernel-inner/Prover.toml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...-projects/noir-protocol-circuits/crates/types/src/abis/protocol_contract_leaf_preimage.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use crate::{ | ||
hash::poseidon2_hash, | ||
merkle_tree::leaf_preimage::{IndexedTreeLeafPreimage, LeafPreimage}, | ||
traits::Empty, | ||
}; | ||
|
||
/** | ||
Exists to show: | ||
- Membership of a computed protocol contract address in the tree, or | ||
- Non-membership of a computed non-protocol contract address in the tree | ||
in private_call_data_validator/validate_contract_address.nr. | ||
The tree is created never updated within the kernels, so we don't need the functions which update leaves. | ||
*/ | ||
|
||
pub struct ProtocolContractLeafPreimage { | ||
pub address: Field, | ||
pub next_address: Field, | ||
} | ||
|
||
impl Empty for ProtocolContractLeafPreimage { | ||
fn empty() -> Self { | ||
Self { address: 0, next_address: 0 } | ||
} | ||
} | ||
|
||
impl LeafPreimage for ProtocolContractLeafPreimage { | ||
fn get_key(self) -> Field { | ||
self.address | ||
} | ||
|
||
fn as_leaf(self) -> Field { | ||
poseidon2_hash([self.address, self.next_address]) | ||
} | ||
} | ||
|
||
impl IndexedTreeLeafPreimage<Field> for ProtocolContractLeafPreimage { | ||
fn get_next_key(self) -> Field { | ||
self.next_address | ||
} | ||
|
||
fn points_to_infinity(self) -> bool { | ||
// Unimplemented, not required | ||
false | ||
} | ||
|
||
fn update_pointers(self, _next_key: Field, _next_index: u32) -> Self { | ||
assert(false, "Tried to update a static protocol contract index"); | ||
Self::empty() | ||
} | ||
|
||
fn update_value(self, _value: Field) -> Self { | ||
assert(false, "Tried to update a static protocol contract address"); | ||
Self::empty() | ||
} | ||
|
||
fn build_insertion_leaf(_value: Field, _low_leaf: Self) -> Self { | ||
assert(false, "Tried to update a static protocol contract address"); | ||
Self::empty() | ||
} | ||
} | ||
|
||
impl Eq for ProtocolContractLeafPreimage { | ||
fn eq(self, other: Self) -> bool { | ||
(self.address == other.address) & (self.next_address == other.next_address) | ||
} | ||
} |
Oops, something went wrong.