Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Dec 1, 2023
1 parent 40ade4d commit faa6a92
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 89 deletions.
10 changes: 1 addition & 9 deletions yarn-project/acir-simulator/src/acvm/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,7 @@ export function toACVMContractDeploymentData(contractDeploymentData: ContractDep
* @returns The ACVM fields.
*/
export function toACVMBlockHeader(blockHeader: BlockHeader): ACVMField[] {
return [
toACVMField(blockHeader.noteHashTreeRoot),
toACVMField(blockHeader.nullifierTreeRoot),
toACVMField(blockHeader.contractTreeRoot),
toACVMField(blockHeader.l1ToL2MessagesTreeRoot),
toACVMField(blockHeader.blocksTreeRoot),
toACVMField(blockHeader.publicDataTreeRoot),
toACVMField(blockHeader.globalVariablesHash),
];
return blockHeader.toArray().map(toACVMField);
}

/**
Expand Down
19 changes: 11 additions & 8 deletions yarn-project/aztec-nr/aztec/src/abi.nr
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ impl CallContext {

// docs:start:block-header
struct BlockHeader {
// Tree root of the parent block's blocks tree - we don't have this block's blocks tree root here because
// to update the tree we first need to form this object and compute its hash
parent_block_blocks_tree_root: Field,
// The rest of the values are from the current block
note_hash_tree_root : Field,
nullifier_tree_root : Field,
contract_tree_root : Field,
l1_to_l2_messages_tree_root : Field,
blocks_tree_root: Field,
private_kernel_vk_tree_root : Field,
public_data_tree_root: Field,
global_variables_hash: Field,
Expand All @@ -158,11 +161,11 @@ impl BlockHeader {
// NOTE: this order must match the order in `private_circuit_public_inputs.hpp`
pub fn serialize(self) -> [Field; BLOCK_HEADER_LENGTH] {
[
self.parent_block_blocks_tree_root,
self.note_hash_tree_root,
self.nullifier_tree_root,
self.contract_tree_root,
self.l1_to_l2_messages_tree_root,
self.blocks_tree_root,
self.private_kernel_vk_tree_root,
self.public_data_tree_root,
self.global_variables_hash,
Expand All @@ -171,11 +174,11 @@ impl BlockHeader {

pub fn deserialize(deserialized: [Field; BLOCK_HEADER_LENGTH]) -> Self {
BlockHeader {
note_hash_tree_root: deserialized[0],
nullifier_tree_root: deserialized[1],
contract_tree_root: deserialized[2],
l1_to_l2_messages_tree_root: deserialized[3],
blocks_tree_root: deserialized[4],
parent_block_blocks_tree_root: deserialized[0],
note_hash_tree_root: deserialized[1],
nullifier_tree_root: deserialized[2],
contract_tree_root: deserialized[3],
l1_to_l2_messages_tree_root: deserialized[4],
private_kernel_vk_tree_root: deserialized[5],
public_data_tree_root: deserialized[6],
global_variables_hash: deserialized[7],
Expand All @@ -184,11 +187,11 @@ impl BlockHeader {

pub fn empty() -> Self {
Self {
parent_block_blocks_tree_root: 0,
note_hash_tree_root: 0,
nullifier_tree_root: 0,
contract_tree_root: 0,
l1_to_l2_messages_tree_root: 0,
blocks_tree_root: 0,
private_kernel_vk_tree_root: 0,
public_data_tree_root: 0,
global_variables_hash: 0
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/aztec-nr/aztec/src/context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ impl PrivateContext {
unencrypted_log_preimages_length: fields[144],
block_header: BlockHeader {
// Must match order in `private_circuit_public_inputs.hpp`
note_hash_tree_root : fields[145],
nullifier_tree_root : fields[146],
contract_tree_root : fields[147],
l1_to_l2_messages_tree_root : fields[148],
blocks_tree_root : fields[149],
parent_block_blocks_tree_root : fields[145],
note_hash_tree_root : fields[146],
nullifier_tree_root : fields[147],
contract_tree_root : fields[148],
l1_to_l2_messages_tree_root : fields[149],
private_kernel_vk_tree_root: 0, // TODO(#3441)
public_data_tree_root: fields[150],
global_variables_hash: fields[151],
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-nr/aztec/src/oracle/get_block_header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn get_block_header(block_number: Field, context: PrivateContext) -> BlockHe
let witness: MembershipWitness<BLOCKS_TREE_HEIGHT, BLOCKS_TREE_HEIGHT + 1> = get_membership_witness(block_number, blocks_tree_id, block_hash);

// 4) Check that the block is in the blocks tree (i.e. the witness is valid)
assert(context.block_header.blocks_tree_root == compute_merkle_root(block_hash, witness.index, witness.path), "Proving membership of a block in blocks tree failed");
assert(context.block_header.parent_block_blocks_tree_root == compute_merkle_root(block_hash, witness.index, witness.path), "Proving membership of a block in blocks tree failed");

// 5) Return the block header
block_header
Expand Down
20 changes: 10 additions & 10 deletions yarn-project/aztec.js/src/artifacts/ecdsa_account_contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,31 +371,31 @@
"path": "aztec::abi::BlockHeader",
"fields": [
{
"name": "note_hash_tree_root",
"name": "parent_block_blocks_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "nullifier_tree_root",
"name": "note_hash_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "contract_tree_root",
"name": "nullifier_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "l1_to_l2_messages_tree_root",
"name": "contract_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "blocks_tree_root",
"name": "l1_to_l2_messages_tree_root",
"type": {
"kind": "field"
}
Expand Down Expand Up @@ -644,31 +644,31 @@
"path": "aztec::abi::BlockHeader",
"fields": [
{
"name": "note_hash_tree_root",
"name": "parent_block_blocks_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "nullifier_tree_root",
"name": "note_hash_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "contract_tree_root",
"name": "nullifier_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "l1_to_l2_messages_tree_root",
"name": "contract_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "blocks_tree_root",
"name": "l1_to_l2_messages_tree_root",
"type": {
"kind": "field"
}
Expand Down
20 changes: 10 additions & 10 deletions yarn-project/aztec.js/src/artifacts/schnorr_account_contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,31 +359,31 @@
"path": "aztec::abi::BlockHeader",
"fields": [
{
"name": "note_hash_tree_root",
"name": "parent_block_blocks_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "nullifier_tree_root",
"name": "note_hash_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "contract_tree_root",
"name": "nullifier_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "l1_to_l2_messages_tree_root",
"name": "contract_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "blocks_tree_root",
"name": "l1_to_l2_messages_tree_root",
"type": {
"kind": "field"
}
Expand Down Expand Up @@ -632,31 +632,31 @@
"path": "aztec::abi::BlockHeader",
"fields": [
{
"name": "note_hash_tree_root",
"name": "parent_block_blocks_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "nullifier_tree_root",
"name": "note_hash_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "contract_tree_root",
"name": "nullifier_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "l1_to_l2_messages_tree_root",
"name": "contract_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "blocks_tree_root",
"name": "l1_to_l2_messages_tree_root",
"type": {
"kind": "field"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,31 +294,31 @@
"path": "aztec::abi::BlockHeader",
"fields": [
{
"name": "note_hash_tree_root",
"name": "parent_block_blocks_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "nullifier_tree_root",
"name": "note_hash_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "contract_tree_root",
"name": "nullifier_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "l1_to_l2_messages_tree_root",
"name": "contract_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "blocks_tree_root",
"name": "l1_to_l2_messages_tree_root",
"type": {
"kind": "field"
}
Expand Down Expand Up @@ -567,31 +567,31 @@
"path": "aztec::abi::BlockHeader",
"fields": [
{
"name": "note_hash_tree_root",
"name": "parent_block_blocks_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "nullifier_tree_root",
"name": "note_hash_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "contract_tree_root",
"name": "nullifier_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "l1_to_l2_messages_tree_root",
"name": "contract_tree_root",
"type": {
"kind": "field"
}
},
{
"name": "blocks_tree_root",
"name": "l1_to_l2_messages_tree_root",
"type": {
"kind": "field"
}
Expand Down
11 changes: 3 additions & 8 deletions yarn-project/circuits.js/src/abis/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,12 @@ function computePrivateInputsHash(input: PrivateCircuitPublicInputs) {
...input.unencryptedLogsHash.map(fr => fr.toBuffer()),
input.encryptedLogPreimagesLength.toBuffer(),
input.unencryptedLogPreimagesLength.toBuffer(),
input.blockHeader.parentBlockBlocksTreeRoot.toBuffer(),
input.blockHeader.noteHashTreeRoot.toBuffer(),
input.blockHeader.nullifierTreeRoot.toBuffer(),
input.blockHeader.contractTreeRoot.toBuffer(),
input.blockHeader.l1ToL2MessagesTreeRoot.toBuffer(),
input.blockHeader.blocksTreeRoot.toBuffer(),
input.blockHeader.privateKernelVkTreeRoot.toBuffer(),
input.blockHeader.publicDataTreeRoot.toBuffer(),
input.blockHeader.globalVariablesHash.toBuffer(),
computeContractDeploymentDataHash(input.contractDeploymentData).toBuffer(),
Expand Down Expand Up @@ -517,13 +518,7 @@ function computePublicInputsHash(input: PublicCircuitPublicInputs) {
...input.newL2ToL1Msgs.map(fr => fr.toBuffer()),
...input.unencryptedLogsHash.map(fr => fr.toBuffer()),
input.unencryptedLogPreimagesLength.toBuffer(),
input.blockHeader.noteHashTreeRoot.toBuffer(),
input.blockHeader.nullifierTreeRoot.toBuffer(),
input.blockHeader.contractTreeRoot.toBuffer(),
input.blockHeader.l1ToL2MessagesTreeRoot.toBuffer(),
input.blockHeader.blocksTreeRoot.toBuffer(),
input.blockHeader.publicDataTreeRoot.toBuffer(),
input.blockHeader.globalVariablesHash.toBuffer(),
...input.blockHeader.toArray().map(fr => fr.toBuffer()),
input.proverAddress.toBuffer(),
];
if (toHash.length != PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH) {
Expand Down
Loading

0 comments on commit faa6a92

Please sign in to comment.