-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: optimize public call stack item hashing
- Loading branch information
Showing
19 changed files
with
224 additions
and
77 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
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
75 changes: 75 additions & 0 deletions
75
...rojects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item_compressed.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,75 @@ | ||
use crate::abis::{call_context::CallContext, function_data::FunctionData}; | ||
use crate::address::AztecAddress; | ||
use crate::constants::{GENERATOR_INDEX__CALL_STACK_ITEM, PUBLIC_CALL_STACK_ITEM_COMPRESSED_LENGTH}; | ||
use crate::traits::{Hash, Empty, Serialize, Deserialize}; | ||
use crate::utils::reader::Reader; | ||
|
||
struct PublicCallStackItemCompressed { | ||
contract_address: AztecAddress, | ||
call_context: CallContext, | ||
function_data: FunctionData, | ||
args_hash: Field, | ||
} | ||
|
||
impl Eq for PublicCallStackItemCompressed { | ||
fn eq(self, other: PublicCallStackItemCompressed) -> bool { | ||
(self.contract_address == other.contract_address) | ||
& (self.call_context == other.call_context) | ||
& (self.function_data == other.function_data) | ||
& (self.args_hash == other.args_hash) | ||
} | ||
} | ||
|
||
impl Hash for PublicCallStackItemCompressed { | ||
fn hash(self) -> Field { | ||
let item = self; | ||
std::hash::pedersen_hash_with_separator([ | ||
item.contract_address.to_field(), | ||
item.call_context.hash(), | ||
item.function_data.hash(), | ||
item.args_hash, | ||
], GENERATOR_INDEX__CALL_STACK_ITEM) | ||
} | ||
} | ||
|
||
impl Empty for PublicCallStackItemCompressed { | ||
|
||
fn empty() -> Self { | ||
PublicCallStackItemCompressed { | ||
contract_address: AztecAddress::empty(), | ||
call_context: CallContext::empty(), | ||
function_data: FunctionData::empty(), | ||
args_hash: 0, | ||
} | ||
} | ||
} | ||
|
||
impl Serialize<PUBLIC_CALL_STACK_ITEM_COMPRESSED_LENGTH> for PublicCallStackItemCompressed { | ||
fn serialize(self) -> [Field; PUBLIC_CALL_STACK_ITEM_COMPRESSED_LENGTH] { | ||
let mut fields: BoundedVec<Field, PUBLIC_CALL_STACK_ITEM_COMPRESSED_LENGTH> = BoundedVec::new(); | ||
|
||
fields.push(self.contract_address.to_field()); | ||
fields.extend_from_array(self.call_context.serialize()); | ||
fields.extend_from_array(self.function_data.serialize()); | ||
fields.push(self.args_hash); | ||
|
||
assert_eq(fields.len(), PUBLIC_CALL_STACK_ITEM_COMPRESSED_LENGTH); | ||
|
||
fields.storage | ||
} | ||
} | ||
|
||
impl Deserialize<PUBLIC_CALL_STACK_ITEM_COMPRESSED_LENGTH> for PublicCallStackItemCompressed { | ||
fn deserialize(fields: [Field; PUBLIC_CALL_STACK_ITEM_COMPRESSED_LENGTH]) -> PublicCallStackItemCompressed { | ||
let mut reader = Reader::new(fields); | ||
|
||
let item = PublicCallStackItemCompressed { | ||
contract_address: reader.read_struct(AztecAddress::deserialize), | ||
call_context: reader.read_struct(CallContext::deserialize), | ||
function_data: reader.read_struct(FunctionData::deserialize), | ||
args_hash: reader.read(), | ||
}; | ||
reader.finish(); | ||
item | ||
} | ||
} |
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
8 changes: 4 additions & 4 deletions
8
yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`PublicCallStackItem Computes a callstack item hash 1`] = `"0x23a1d22e7bf37df7d68e8fcbfb7e016c060194b7915e3771e2dcd72cea26e427"`; | ||
exports[`PublicCallStackItem Computes a callstack item hash 1`] = `"0x00ae3637b279ce8be67fd283808915bce72cb2943cb9bdbcb19d35cf8ca8fe9e"`; | ||
|
||
exports[`PublicCallStackItem Computes a callstack item request hash 1`] = `"0x022a2b82af83606ae5a8d4955ef6215e54025193356318aefbde3b5026952953"`; | ||
exports[`PublicCallStackItem Computes a callstack item request hash 1`] = `"0x00ae3637b279ce8be67fd283808915bce72cb2943cb9bdbcb19d35cf8ca8fe9e"`; | ||
|
||
exports[`PublicCallStackItem computes empty item hash 1`] = `Fr<0x211932b705c9a5dbbaf2433d2ee4b0a896ef9fb720a4efbe7c1e783747c36588>`; | ||
exports[`PublicCallStackItem computes empty item hash 1`] = `Fr<0x00ccf05f0449b7f9f0e4b20585334b860596780a70e41b939f67731e6276fba1>`; | ||
|
||
exports[`PublicCallStackItem computes hash 1`] = `Fr<0x2d9862fe4fb3db6fe24996cbc3064346aa4551ccd41246c1ca6b002b8b0201fd>`; | ||
exports[`PublicCallStackItem computes hash 1`] = `Fr<0x153cad9cc1e6d97618fd6f920ebe80a1e1cfc8a1f336aab769397e66729b1b33>`; |
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
Oops, something went wrong.