-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separating combined accumulated data
- Loading branch information
Showing
16 changed files
with
687 additions
and
544 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
noir-projects/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.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
2 changes: 1 addition & 1 deletion
2
noir-projects/noir-protocol-circuits/src/crates/public-kernel-lib/src/common.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
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
19 changes: 19 additions & 0 deletions
19
noir-projects/noir-protocol-circuits/src/crates/types/src/abis/accumulated_data.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,19 @@ | ||
mod accumulated_non_revertible_data_builder; | ||
mod accumulated_revertible_data_builder; | ||
mod combined_accumulated_data; | ||
mod combined_accumulated_data_builder; | ||
mod private_accumulated_non_revertible_data; | ||
mod private_accumulated_revertible_data; | ||
mod public_accumulated_non_revertible_data; | ||
mod public_accumulated_revertible_data; | ||
|
||
use crate::abis::accumulated_data::{ | ||
combined_accumulated_data::CombinedAccumulatedData, | ||
private_accumulated_revertible_data::PrivateAccumulatedRevertibleData, | ||
private_accumulated_non_revertible_data::PrivateAccumulatedNonRevertibleData, | ||
combined_accumulated_data_builder::CombinedAccumulatedDataBuilder, | ||
public_accumulated_non_revertible_data::PublicAccumulatedNonRevertibleData, | ||
public_accumulated_revertible_data::PublicAccumulatedRevertibleData, | ||
accumulated_non_revertible_data_builder::AccumulatedNonRevertibleDataBuilder, | ||
accumulated_revertible_data_builder::AccumulatedRevertibleDataBuilder | ||
}; |
43 changes: 43 additions & 0 deletions
43
...its/src/crates/types/src/abis/accumulated_data/accumulated_non_revertible_data_builder.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,43 @@ | ||
use crate::{ | ||
abis::{ | ||
accumulated_data::{ | ||
private_accumulated_non_revertible_data::PrivateAccumulatedNonRevertibleData, | ||
public_accumulated_non_revertible_data::PublicAccumulatedNonRevertibleData | ||
}, | ||
call_request::CallRequest, public_data_read::PublicDataRead, | ||
public_data_update_request::PublicDataUpdateRequest, | ||
side_effect::{SideEffect, SideEffectLinkedToNoteHash} | ||
} | ||
}; | ||
use crate::constants::{ | ||
MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, | ||
MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NON_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, | ||
MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX | ||
}; | ||
|
||
struct AccumulatedNonRevertibleDataBuilder { | ||
new_commitments: BoundedVec<SideEffect, MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX>, | ||
new_nullifiers: BoundedVec<SideEffectLinkedToNoteHash, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX>, | ||
public_call_stack: BoundedVec<CallRequest, MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX>, | ||
public_data_update_requests: BoundedVec<PublicDataUpdateRequest, MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>, | ||
public_data_reads: BoundedVec<PublicDataRead, MAX_NON_REVERTIBLE_PUBLIC_DATA_READS_PER_TX>, | ||
} | ||
|
||
impl AccumulatedNonRevertibleDataBuilder { | ||
pub fn to_private(self) -> PrivateAccumulatedNonRevertibleData { | ||
PrivateAccumulatedNonRevertibleData { | ||
new_commitments: self.new_commitments.storage, | ||
new_nullifiers: self.new_nullifiers.storage, | ||
public_call_stack: self.public_call_stack.storage | ||
} | ||
} | ||
pub fn to_public(self) -> PublicAccumulatedNonRevertibleData { | ||
PublicAccumulatedNonRevertibleData { | ||
new_commitments: self.new_commitments.storage, | ||
new_nullifiers: self.new_nullifiers.storage, | ||
public_call_stack: self.public_call_stack.storage, | ||
public_data_update_requests: self.public_data_update_requests.storage, | ||
public_data_reads: self.public_data_reads.storage | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...ircuits/src/crates/types/src/abis/accumulated_data/accumulated_revertible_data_builder.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,80 @@ | ||
use crate::{ | ||
abis::{ | ||
accumulated_data::{ | ||
private_accumulated_revertible_data::PrivateAccumulatedRevertibleData, | ||
public_accumulated_revertible_data::PublicAccumulatedRevertibleData | ||
}, | ||
call_request::CallRequest, new_contract_data::NewContractData, | ||
nullifier_key_validation_request::NullifierKeyValidationRequestContext, | ||
public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, | ||
side_effect::{SideEffect, SideEffectLinkedToNoteHash} | ||
} | ||
}; | ||
use crate::constants::{ | ||
MAX_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, | ||
MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_CONTRACTS_PER_TX, | ||
NUM_FIELDS_PER_SHA256, MAX_REVERTIBLE_COMMITMENTS_PER_TX, MAX_REVERTIBLE_NULLIFIERS_PER_TX, | ||
MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, | ||
MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX | ||
}; | ||
|
||
struct AccumulatedRevertibleDataBuilder { | ||
read_requests: BoundedVec<SideEffect, MAX_READ_REQUESTS_PER_TX>, | ||
nullifier_key_validation_requests: BoundedVec<NullifierKeyValidationRequestContext, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX>, | ||
|
||
new_commitments: BoundedVec<SideEffect, MAX_REVERTIBLE_COMMITMENTS_PER_TX>, | ||
new_nullifiers: BoundedVec<SideEffectLinkedToNoteHash, MAX_REVERTIBLE_NULLIFIERS_PER_TX>, | ||
|
||
private_call_stack: BoundedVec<CallRequest, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX>, | ||
public_call_stack: BoundedVec<CallRequest, MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX>, | ||
new_l2_to_l1_msgs: BoundedVec<Field, MAX_NEW_L2_TO_L1_MSGS_PER_TX>, | ||
|
||
encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], | ||
unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], | ||
|
||
// Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the | ||
// variable-length data. | ||
encrypted_log_preimages_length: Field, | ||
unencrypted_log_preimages_length: Field, | ||
|
||
new_contracts: BoundedVec<NewContractData, MAX_NEW_CONTRACTS_PER_TX>, | ||
|
||
public_data_update_requests: BoundedVec<PublicDataUpdateRequest, MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>, | ||
public_data_reads: BoundedVec<PublicDataRead, MAX_REVERTIBLE_PUBLIC_DATA_READS_PER_TX>, | ||
} | ||
|
||
impl AccumulatedRevertibleDataBuilder { | ||
pub fn to_private(self) -> PrivateAccumulatedRevertibleData { | ||
PrivateAccumulatedRevertibleData { | ||
new_commitments: self.new_commitments.storage, | ||
new_nullifiers: self.new_nullifiers.storage, | ||
private_call_stack: self.private_call_stack.storage, | ||
public_call_stack: self.public_call_stack.storage, | ||
new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, | ||
encrypted_logs_hash: self.encrypted_logs_hash, | ||
unencrypted_logs_hash: self.unencrypted_logs_hash, | ||
encrypted_log_preimages_length: self.encrypted_log_preimages_length, | ||
unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, | ||
new_contracts: self.new_contracts.storage | ||
} | ||
} | ||
|
||
pub fn to_public(self) -> PublicAccumulatedRevertibleData { | ||
PublicAccumulatedRevertibleData { | ||
read_requests: self.read_requests.storage, | ||
new_commitments: self.new_commitments.storage, | ||
nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage, | ||
new_nullifiers: self.new_nullifiers.storage, | ||
private_call_stack: self.private_call_stack.storage, | ||
public_call_stack: self.public_call_stack.storage, | ||
new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage, | ||
encrypted_logs_hash: self.encrypted_logs_hash, | ||
unencrypted_logs_hash: self.unencrypted_logs_hash, | ||
encrypted_log_preimages_length: self.encrypted_log_preimages_length, | ||
unencrypted_log_preimages_length: self.unencrypted_log_preimages_length, | ||
new_contracts: self.new_contracts.storage, | ||
public_data_update_requests: self.public_data_update_requests.storage, | ||
public_data_reads: self.public_data_reads.storage | ||
} | ||
} | ||
} |
176 changes: 176 additions & 0 deletions
176
...protocol-circuits/src/crates/types/src/abis/accumulated_data/combined_accumulated_data.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,176 @@ | ||
use crate::{ | ||
abis::{ | ||
accumulated_data::{ | ||
public_accumulated_non_revertible_data::PublicAccumulatedNonRevertibleData, | ||
public_accumulated_revertible_data::PublicAccumulatedRevertibleData | ||
}, | ||
call_request::CallRequest, new_contract_data::NewContractData, | ||
nullifier_key_validation_request::NullifierKeyValidationRequestContext, | ||
public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, | ||
side_effect::{SideEffect, SideEffectLinkedToNoteHash} | ||
} | ||
}; | ||
use crate::constants::{ | ||
MAX_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NEW_COMMITMENTS_PER_TX, | ||
MAX_NEW_NULLIFIERS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, | ||
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_CONTRACTS_PER_TX, | ||
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, NUM_FIELDS_PER_SHA256, | ||
MAX_NON_REVERTIBLE_COMMITMENTS_PER_TX, MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX, | ||
MAX_NON_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_REVERTIBLE_COMMITMENTS_PER_TX, | ||
MAX_REVERTIBLE_NULLIFIERS_PER_TX, MAX_REVERTIBLE_PUBLIC_CALL_STACK_LENGTH_PER_TX, | ||
MAX_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, | ||
MAX_NON_REVERTIBLE_PUBLIC_DATA_READS_PER_TX, MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX | ||
}; | ||
|
||
use dep::std::unsafe; | ||
use crate::traits::is_empty; | ||
|
||
use crate::utils::arrays::{array_cp, array_concat, array_to_bounded_vec}; | ||
|
||
struct CombinedAccumulatedData { | ||
read_requests: [SideEffect; MAX_READ_REQUESTS_PER_TX], | ||
nullifier_key_validation_requests: [NullifierKeyValidationRequestContext; MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], | ||
|
||
new_commitments: [SideEffect; MAX_NEW_COMMITMENTS_PER_TX], | ||
new_nullifiers: [SideEffectLinkedToNoteHash; MAX_NEW_NULLIFIERS_PER_TX], | ||
|
||
private_call_stack: [CallRequest; MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], | ||
public_call_stack: [CallRequest; MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], | ||
new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_TX], | ||
|
||
encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], | ||
unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], | ||
|
||
// Here so that the gas cost of this request can be measured by circuits, without actually needing to feed in the | ||
// variable-length data. | ||
encrypted_log_preimages_length: Field, | ||
unencrypted_log_preimages_length: Field, | ||
|
||
new_contracts: [NewContractData; MAX_NEW_CONTRACTS_PER_TX], | ||
|
||
public_data_update_requests: [PublicDataUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], | ||
|
||
public_data_reads: [PublicDataRead; MAX_PUBLIC_DATA_READS_PER_TX], | ||
} | ||
|
||
impl CombinedAccumulatedData { | ||
pub fn needs_app_logic(self) -> bool { | ||
// if we have any enqueued revertible public calls, we need to run the public app logic circuit. | ||
!self.public_call_stack[0].is_empty() | ||
} | ||
|
||
pub fn recombine( | ||
non_revertible: PublicAccumulatedNonRevertibleData, | ||
revertible: PublicAccumulatedRevertibleData | ||
) -> CombinedAccumulatedData { | ||
CombinedAccumulatedData { | ||
read_requests: revertible.read_requests, | ||
nullifier_key_validation_requests: revertible.nullifier_key_validation_requests, | ||
new_commitments: array_concat(non_revertible.new_commitments, revertible.new_commitments), | ||
new_nullifiers: array_concat(non_revertible.new_nullifiers, revertible.new_nullifiers), | ||
private_call_stack: revertible.private_call_stack, | ||
public_call_stack: array_concat( | ||
non_revertible.public_call_stack, | ||
revertible.public_call_stack | ||
), | ||
new_l2_to_l1_msgs: revertible.new_l2_to_l1_msgs, | ||
encrypted_logs_hash: revertible.encrypted_logs_hash, | ||
unencrypted_logs_hash: revertible.unencrypted_logs_hash, | ||
encrypted_log_preimages_length: revertible.encrypted_log_preimages_length, | ||
unencrypted_log_preimages_length: revertible.unencrypted_log_preimages_length, | ||
new_contracts: revertible.new_contracts, | ||
public_data_update_requests: array_concat( | ||
non_revertible.public_data_update_requests, | ||
revertible.public_data_update_requests | ||
), | ||
public_data_reads: array_concat( | ||
non_revertible.public_data_reads, | ||
revertible.public_data_reads | ||
) | ||
} | ||
} | ||
} | ||
|
||
mod tests { | ||
use crate::abis::{ | ||
accumulated_data::combined_accumulated_data_builder::CombinedAccumulatedDataBuilder, | ||
call_request::{CallRequest, CallerContext}, new_contract_data::NewContractData, | ||
nullifier_key_validation_request::NullifierKeyValidationRequestContext, | ||
public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, | ||
side_effect::{SideEffect, SideEffectLinkedToNoteHash} | ||
}; | ||
use crate::address::AztecAddress; | ||
use crate::utils::arrays::array_eq; | ||
use dep::std::unsafe; | ||
|
||
#[test] | ||
unconstrained fn splits_revertible_and_non_revertible() { | ||
let mut builder: CombinedAccumulatedDataBuilder = unsafe::zeroed(); | ||
|
||
let non_revertible_commitments = [ | ||
SideEffect { value: 1, counter: 1 }, | ||
SideEffect { value: 2, counter: 3 } | ||
]; | ||
|
||
let non_revertible_nullifiers = [ | ||
SideEffectLinkedToNoteHash { value: 10, note_hash: 1, counter: 2 }, | ||
SideEffectLinkedToNoteHash { value: 20, note_hash: 2, counter: 4 } | ||
]; | ||
|
||
let non_revertible_public_stack = [ | ||
CallRequest { | ||
hash: 1, | ||
caller_contract_address: AztecAddress::from_field(1), | ||
caller_context: CallerContext::empty(), | ||
start_side_effect_counter: 5, | ||
end_side_effect_counter: 0 | ||
}, | ||
CallRequest { | ||
hash: 2, | ||
caller_contract_address: AztecAddress::from_field(1), | ||
caller_context: CallerContext::empty(), | ||
start_side_effect_counter: 6, | ||
end_side_effect_counter: 0 | ||
} | ||
]; | ||
|
||
let revertible_commitments = [ | ||
SideEffect { value: 3, counter: 7 }, | ||
SideEffect { value: 4, counter: 10 } | ||
]; | ||
|
||
let revertible_nullifiers = [ | ||
SideEffectLinkedToNoteHash { value: 30, note_hash: 3, counter: 8 }, | ||
SideEffectLinkedToNoteHash { value: 40, note_hash: 4, counter: 11 } | ||
]; | ||
|
||
let revertible_public_call_stack = [ | ||
CallRequest { | ||
hash: 3, | ||
caller_contract_address: AztecAddress::from_field(3), | ||
caller_context: CallerContext::empty(), | ||
start_side_effect_counter: 9, | ||
end_side_effect_counter: 0 | ||
} | ||
]; | ||
|
||
builder.new_commitments.extend_from_array(non_revertible_commitments); | ||
builder.new_commitments.extend_from_array(revertible_commitments); | ||
|
||
builder.new_nullifiers.extend_from_array(non_revertible_nullifiers); | ||
builder.new_nullifiers.extend_from_array(revertible_nullifiers); | ||
|
||
builder.public_call_stack.extend_from_array(non_revertible_public_stack); | ||
builder.public_call_stack.extend_from_array(revertible_public_call_stack); | ||
|
||
let (non_revertible, revertible) = builder.split(7); | ||
|
||
assert(array_eq(non_revertible.new_commitments, non_revertible_commitments)); | ||
assert(array_eq(non_revertible.new_nullifiers, non_revertible_nullifiers)); | ||
assert(array_eq(non_revertible.public_call_stack, non_revertible_public_stack)); | ||
|
||
assert(array_eq(revertible.new_commitments, revertible_commitments)); | ||
assert(array_eq(revertible.new_nullifiers, revertible_nullifiers)); | ||
assert(array_eq(revertible.public_call_stack, revertible_public_call_stack)); | ||
} | ||
} |
Oops, something went wrong.