Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 23, 2024
1 parent 7a5881c commit 11ff97f
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ pub fn contract_logic(
private_call.contract_leaf_membership_witness.sibling_path
);

let purported_contract_tree_root = private_call.call_stack_item.public_inputs.block_header.contract_tree_root();
let purported_contract_tree_root = private_call.call_stack_item.public_inputs.block_header.state.partial.contract_tree.root;
assert_eq(
computed_contract_tree_root, purported_contract_tree_root, "computed_contract_tree_root does not match purported_contract_tree_root"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl PrivateKernelInputsInit {
self.validate_this_private_call_against_tx_request();

common::validate_read_requests(
public_inputs.constants.block_header.note_hash_tree_root(),
public_inputs.constants.block_header.state.partial.note_hash_tree.root,
self.private_call.call_stack_item.public_inputs.read_requests,
self.private_call.read_request_membership_witnesses
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl PrivateKernelInputsInner {
}

fn validate_contract_tree_root(self) {
let purported_contract_tree_root = self.private_call.call_stack_item.public_inputs.block_header.contract_tree_root();
let previous_kernel_contract_tree_root = self.previous_kernel.public_inputs.constants.block_header.contract_tree_root();
let purported_contract_tree_root = self.private_call.call_stack_item.public_inputs.block_header.state.partial.contract_tree.root;
let previous_kernel_contract_tree_root = self.previous_kernel.public_inputs.constants.block_header.state.partial.contract_tree.root;

assert(purported_contract_tree_root == previous_kernel_contract_tree_root, "purported_contract_tree_root does not match previous_kernel_contract_tree_root");
}
Expand Down Expand Up @@ -52,7 +52,7 @@ impl PrivateKernelInputsInner {
self.pop_and_validate_this_private_call_hash(&mut public_inputs);

common::validate_read_requests(
public_inputs.constants.block_header.note_hash_tree_root(),
public_inputs.constants.block_header.state.partial.note_hash_tree.root,
self.private_call.call_stack_item.public_inputs.read_requests, // read requests from private call
self.private_call.read_request_membership_witnesses);

Expand Down Expand Up @@ -171,8 +171,8 @@ mod tests {
let mut builder = PrivateKernelInnerInputsBuilder::new();

// Set historical_tree_root to a wrong value (the correct value + 1).
let contract_tree_root = builder.previous_kernel.block_header.contract_tree_root;
builder.previous_kernel.block_header.contract_tree_root = contract_tree_root + 1;
let contract_tree_root = builder.previous_kernel.block_header.state.partial.contract_tree.root;
builder.previous_kernel.block_header.state.partial.contract_tree.root = contract_tree_root + 1;

builder.failed();
}
Expand Down Expand Up @@ -610,8 +610,8 @@ mod tests {
builder.private_call.append_read_requests(1);

// Set the root to be a different root so the above read request is not under this root.
let old_root = builder.previous_kernel.block_header.note_hash_tree_root;
builder.previous_kernel.block_header.note_hash_tree_root = old_root + 1;
let old_root = builder.previous_kernel.block_header.state.partial.note_hash_tree.root;
builder.previous_kernel.block_header.state.partial.note_hash_tree.root = old_root + 1;

builder.failed();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use dep::std::cmp::Eq;
use crate::traits::Empty;

struct AppendOnlyTreeSnapshot {
root : Field,
Expand All @@ -25,3 +26,12 @@ impl Eq for AppendOnlyTreeSnapshot {
(self.root == other.root) & (self.next_available_leaf_index == other.next_available_leaf_index)
}
}

impl Empty for AppendOnlyTreeSnapshot {
fn empty() -> Self {
Self {
root: 0,
next_available_leaf_index: 0
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::{
abis::{
call_context::CallContext,
block_header::BlockHeader,
side_effect::{SideEffect, SideEffectLinkedToNoteHash},
},
contrakt::deployment_data::ContractDeploymentData,
hash::{
pedersen_hash,
},
header::Header,
utils::bounded_vec::BoundedVec,
};
use crate::constants::{
Expand Down Expand Up @@ -48,7 +48,7 @@ struct PrivateCircuitPublicInputs {
encrypted_log_preimages_length: Field,
unencrypted_log_preimages_length: Field,

block_header: BlockHeader,
block_header: Header,

contract_deployment_data: ContractDeploymentData,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ global CONTRACT_DEPLOYMENT_DATA_LENGTH: Field = 6;
// Change this ONLY if you have changed the PrivateCircuitPublicInputs structure.
// In other words, if the structure/size of the public inputs of a function call changes then we
// should change this constant as well as the offsets in private_call_stack_item.nr
global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: Field = 189;
// TODO(benesjan): Didn't find any offsets in call_stack_item.nr is this ^ still relevant
global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: Field = 200;
global CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH: Field = 3;
global CONTRACT_STORAGE_READ_LENGTH: Field = 2;
// Change this ONLY if you have changed the PublicCircuitPublicInputs structure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,46 @@ mod contracts;
mod note_hash_tree;
mod read_requests;

use crate::address::AztecAddress;
use crate::abis::block_header::BlockHeader;
use crate::grumpkin_point::GrumpkinPoint;
use crate::tests::fixtures;
use crate::{
abis::{
append_only_tree_snapshot::AppendOnlyTreeSnapshot,
global_variables::GlobalVariables,
},
address::AztecAddress,
constants::NUM_FIELDS_PER_SHA256,
grumpkin_point::GrumpkinPoint,
header::Header,
partial_state_reference::PartialStateReference,
state_reference::StateReference,
tests::fixtures
};

global MSG_SENDER = AztecAddress { inner: 27 };

global DEPLOYER_PUBLIC_KEY = GrumpkinPoint { x: 123456789, y: 123456789 };

global BLOCK_HEADER = BlockHeader {
note_hash_tree_root: fixtures::note_hash_tree::ROOT,
nullifier_tree_root: 0,
contract_tree_root: fixtures::contract_tree::ROOT,
l1_to_l2_message_tree_root: 0,
archive_root: 0,
public_data_tree_root: 0,
global_variables_hash: 0,
global BLOCK_HEADER = Header {
last_archive: AppendOnlyTreeSnapshot::empty(),
body_hash: [0; NUM_FIELDS_PER_SHA256],
state: StateReference {
l1_to_l2_message_tree: AppendOnlyTreeSnapshot::empty(),
partial: PartialStateReference {
note_hash_tree: AppendOnlyTreeSnapshot {
root: fixtures::note_hash_tree::ROOT,
next_available_leaf_index: 0, // TODO: should this be populated?
},
nullifier_tree: AppendOnlyTreeSnapshot::empty(),
contract_tree: AppendOnlyTreeSnapshot {
root: fixtures::contract_tree::ROOT,
next_available_leaf_index: 0, // TODO: should this be populated?
},
public_data_tree: AppendOnlyTreeSnapshot::empty()
}
},
global_variables: GlobalVariables {
chain_id: 0,
version: 0,
block_number: 0,
timestamp: 0
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use crate::{
call_request::{CallerContext, CallRequest},
combined_constant_data::CombinedConstantData,
combined_accumulated_data::CombinedAccumulatedDataBuilder,
block_header::BlockHeader,
kernel_circuit_public_inputs::KernelCircuitPublicInputs,
previous_kernel_data::PreviousKernelData,
public_data_read::PublicDataRead,
public_data_update_request::PublicDataUpdateRequest,
side_effect::{SideEffect, SideEffectLinkedToNoteHash},
},
address::{AztecAddress, EthAddress},
header::Header,
mocked::{Proof, VerificationKey},
tests::{
fixtures,
Expand All @@ -32,7 +32,7 @@ struct PreviousKernelDataBuilder {
contract_address: AztecAddress,
portal_contract_address: EthAddress,
end: CombinedAccumulatedDataBuilder,
block_header: BlockHeader,
block_header: Header,
tx_context: TxContext,
is_private: bool,
proof: Proof,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use crate::{
abis::{
call_context::CallContext,
complete_address::CompleteAddress,
block_header::BlockHeader,
private_circuit_public_inputs::PrivateCircuitPublicInputs,
side_effect::{SideEffect, SideEffectLinkedToNoteHash},
},
contrakt::deployment_data::ContractDeploymentData,
hash::{compute_constructor_hash, hash_args},
header::Header,
tests::{
fixtures,
testing_harness::build_contract_deployment_data,
Expand Down Expand Up @@ -46,7 +46,7 @@ struct PrivateCircuitPublicInputsBuilder {
encrypted_log_preimages_length: Field,
unencrypted_log_preimages_length: Field,

block_header: BlockHeader,
block_header: Header,

contract_deployment_data: ContractDeploymentData,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
abis::{
call_context::CallContext,
block_header::BlockHeader,
public_circuit_public_inputs::PublicCircuitPublicInputs,
side_effect::{SideEffect, SideEffectLinkedToNoteHash},
},
Expand All @@ -10,6 +9,7 @@ use crate::{
storage_read::StorageRead,
storage_update_request::StorageUpdateRequest,
},
header::Header,
tests::fixtures,
utils::bounded_vec::BoundedVec,
};
Expand All @@ -36,7 +36,7 @@ struct PublicCircuitPublicInputsBuilder {
new_l2_to_l1_msgs: BoundedVec<Field, MAX_NEW_L2_TO_L1_MSGS_PER_CALL>,
unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256],
unencrypted_log_preimages_length: Field,
block_header: BlockHeader,
block_header: Header,
prover_address: AztecAddress,
}

Expand Down

0 comments on commit 11ff97f

Please sign in to comment.