Skip to content

Commit

Permalink
header -> historical_header in contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 30, 2024
1 parent fce94dc commit 2e817f2
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 44 deletions.
2 changes: 1 addition & 1 deletion yarn-project/acir-simulator/src/acvm/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function toACVMPublicInputs(publicInputs: PrivateCircuitPublicInputs): AC
toACVMField(publicInputs.encryptedLogPreimagesLength),
toACVMField(publicInputs.unencryptedLogPreimagesLength),

...toACVMHeader(publicInputs.header),
...toACVMHeader(publicInputs.historicalHeader),

...toACVMContractDeploymentData(publicInputs.contractDeploymentData),

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-nr/aztec/src/abi.nr
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl PublicGlobalVariables {
// docs:start:private-context-inputs
struct PrivateContextInputs {
call_context : CallContext,
header: Header,
historical_header: Header,
contract_deployment_data: ContractDeploymentData,
private_global_variables: PrivateGlobalVariables,
}
Expand All @@ -51,7 +51,7 @@ struct PrivateContextInputs {
// docs:start:public-context-inputs
struct PublicContextInputs {
call_context: CallContext,
header: Header,
historical_header: Header,

public_global_variables: PublicGlobalVariables,
}
Expand Down
20 changes: 10 additions & 10 deletions yarn-project/aztec-nr/aztec/src/context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct PrivateContext {
new_l2_to_l1_msgs : BoundedVec<Field, MAX_NEW_L2_TO_L1_MSGS_PER_CALL>,
// docs:end:private-context

header: Header,
historical_header: Header,

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)
// encrypted_logs_preimages: Vec<Field>,
Expand All @@ -110,7 +110,7 @@ impl PrivateContext {
new_commitments: BoundedVec::new(SideEffect::empty()),
new_nullifiers: BoundedVec::new(SideEffectLinkedToNoteHash::empty()),

header: inputs.header,
historical_header: inputs.historical_header,

private_call_stack_hashes: BoundedVec::new(0),
public_call_stack_hashes: BoundedVec::new(0),
Expand Down Expand Up @@ -175,7 +175,7 @@ impl PrivateContext {
unencrypted_logs_hash: unencrypted_logs_hash,
encrypted_log_preimages_length: encrypted_log_preimages_length,
unencrypted_log_preimages_length: unencrypted_log_preimages_length,
header: self.header,
historical_header: self.historical_header,
contract_deployment_data: self.inputs.contract_deployment_data,
chain_id: self.inputs.private_global_variables.chain_id,
version: self.inputs.private_global_variables.version,
Expand Down Expand Up @@ -248,7 +248,7 @@ impl PrivateContext {
)
// docs:end:context_consume_l1_to_l2_message
{
let nullifier = process_l1_to_l2_message(self.header.state.l1_to_l2_message_tree.root, self.this_address(), self.this_portal_address(), self.chain_id(), self.version(), msg_key, content, secret);
let nullifier = process_l1_to_l2_message(self.historical_header.state.l1_to_l2_message_tree.root, self.this_address(), self.this_portal_address(), self.chain_id(), self.version(), msg_key, content, secret);

// Push nullifier (and the "commitment" corresponding to this can be "empty")
self.push_new_nullifier(nullifier, 0)
Expand Down Expand Up @@ -333,7 +333,7 @@ impl PrivateContext {
unencrypted_logs_hash: reader.read_array([0; NUM_FIELDS_PER_SHA256]),
encrypted_log_preimages_length: reader.read(),
unencrypted_log_preimages_length: reader.read(),
header: Header{
historical_header: Header{
// Must match order in `private_circuit_public_inputs.nr`
last_archive: reader.read_struct(AppendOnlyTreeSnapshot::deserialize),
body_hash: reader.read_array([0; NUM_FIELDS_PER_SHA256]),
Expand Down Expand Up @@ -446,7 +446,7 @@ impl PrivateContext {
new_l2_to_l1_msgs:[0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL],
unencrypted_logs_hash:[0; NUM_FIELDS_PER_SHA256],
unencrypted_log_preimages_length: 0,
header: Header::empty(),
historical_header: Header::empty(),
prover_address: AztecAddress::zero(),
},
is_execution_request: true,
Expand Down Expand Up @@ -495,7 +495,7 @@ struct PublicContext {
unencrypted_logs_hash: BoundedVec<Field, NUM_FIELDS_PER_SHA256>,
unencrypted_logs_preimages_length: Field,

header: Header,
historical_header: Header,
prover_address: AztecAddress,
}

Expand Down Expand Up @@ -523,7 +523,7 @@ impl PublicContext {
unencrypted_logs_hash: BoundedVec::new(0),
unencrypted_logs_preimages_length: 0,

header: inputs.header,
historical_header: inputs.historical_header,
prover_address: AztecAddress::zero(),

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)
Expand Down Expand Up @@ -583,7 +583,7 @@ impl PublicContext {
new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage,
unencrypted_logs_hash: unencrypted_logs_hash,
unencrypted_log_preimages_length: unencrypted_log_preimages_length,
header: self.inputs.header,
historical_header: self.inputs.historical_header,
prover_address: self.prover_address,
};
pub_circuit_pub_inputs
Expand Down Expand Up @@ -616,7 +616,7 @@ impl PublicContext {
// Note this returns self to get around an issue where mutable structs do not maintain mutations unless reassigned
pub fn consume_l1_to_l2_message(&mut self, msg_key: Field, content: Field, secret: Field) {
let this = (*self).this_address();
let nullifier = process_l1_to_l2_message(self.header.state.l1_to_l2_message_tree.root, this, self.this_portal_address(), self.chain_id(), self.version(), msg_key, content, secret);
let nullifier = process_l1_to_l2_message(self.historical_header.state.l1_to_l2_message_tree.root, this, self.this_portal_address(), self.chain_id(), self.version(), msg_key, content, secret);

// Push nullifier (and the "commitment" corresponding to this can be "empty")
self.push_new_nullifier(nullifier, 0)
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/aztec-nr/aztec/src/oracle/get_header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ unconstrained pub fn get_header_internal(block_number: u32) -> Header {
pub fn get_header(block_number: u32, context: PrivateContext) -> Header {
// 1) Get block number corresponding to the last_archive root in the header
// Note: We subtract 1 because the last_archive root is the root of the archive after applying the previous block
let last_archive_block_number = (context.header.global_variables.block_number - 1) as u32;
let last_archive_block_number = (context.historical_header.global_variables.block_number - 1) as u32;

// 2) Check that the last archive block number is more than or equal to the block number we want to prove against
// We could not perform the proof otherwise because the last archive root from the header would not "contain"
Expand All @@ -40,7 +40,8 @@ pub fn get_header(block_number: u32, context: PrivateContext) -> Header {

// 6) Check that the block is in the archive (i.e. the witness is valid)
assert(
context.header.last_archive.root == compute_merkle_root(block_hash, witness.index, witness.path), "Proving membership of a block in archive failed"
context.historical_header.last_archive.root
== compute_merkle_root(block_hash, witness.index, witness.path), "Proving membership of a block in archive failed"
);

// 7) Return the block header
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/abis/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ function computePrivateInputsHash(input: PrivateCircuitPublicInputs) {
...input.unencryptedLogsHash.map(fr => fr.toBuffer()),
input.encryptedLogPreimagesLength.toBuffer(),
input.unencryptedLogPreimagesLength.toBuffer(),
...(input.header.toFieldArray().map(fr => fr.toBuffer()) as Buffer[]),
...(input.historicalHeader.toFieldArray().map(fr => fr.toBuffer()) as Buffer[]),
computeContractDeploymentDataHash(input.contractDeploymentData).toBuffer(),
input.chainId.toBuffer(),
input.version.toBuffer(),
Expand Down Expand Up @@ -601,7 +601,7 @@ export function computePublicInputsHash(input: PublicCircuitPublicInputs) {
...input.newL2ToL1Msgs.map(fr => fr.toBuffer()),
...input.unencryptedLogsHash.map(fr => fr.toBuffer()),
input.unencryptedLogPreimagesLength.toBuffer(),
...input.header.toFieldArray().map(fr => fr.toBuffer()),
...input.historicalHeader.toFieldArray().map(fr => fr.toBuffer()),
input.proverAddress.toBuffer(),
];
if (toHash.length != PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class PrivateCircuitPublicInputs {
/**
* L2 block header.
*/
public header: Header,
public historicalHeader: Header,
/**
* Deployment data of contracts being deployed in this kernel iteration.
*/
Expand Down Expand Up @@ -199,7 +199,7 @@ export class PrivateCircuitPublicInputs {
isZeroArray(this.unencryptedLogsHash) &&
this.encryptedLogPreimagesLength.isZero() &&
this.unencryptedLogPreimagesLength.isZero() &&
this.header.isEmpty() &&
this.historicalHeader.isEmpty() &&
this.contractDeploymentData.isEmpty() &&
this.chainId.isZero() &&
this.version.isZero()
Expand Down Expand Up @@ -228,7 +228,7 @@ export class PrivateCircuitPublicInputs {
fields.unencryptedLogsHash,
fields.encryptedLogPreimagesLength,
fields.unencryptedLogPreimagesLength,
fields.header,
fields.historicalHeader,
fields.contractDeploymentData,
fields.chainId,
fields.version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class PublicCircuitPublicInputs {
/**
* L2 block header of the block preceding the block in which this tx is included.
*/
public header: Header,
public historicalHeader: Header,
/**
* Address of the prover.
*/
Expand Down Expand Up @@ -255,7 +255,7 @@ export class PublicCircuitPublicInputs {
isFrArrayEmpty(this.newL2ToL1Msgs) &&
isFrArrayEmpty(this.unencryptedLogsHash) &&
this.unencryptedLogPreimagesLength.isZero() &&
this.header.isEmpty() &&
this.historicalHeader.isEmpty() &&
this.proverAddress.isZero()
);
}
Expand All @@ -278,7 +278,7 @@ export class PublicCircuitPublicInputs {
fields.newL2ToL1Msgs,
fields.unencryptedLogsHash,
fields.unencryptedLogPreimagesLength,
fields.header,
fields.historicalHeader,
fields.proverAddress,
] as const;
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/tests/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ export function makePrivateCircuitPublicInputs(seed = 0): PrivateCircuitPublicIn
unencryptedLogsHash: makeTuple(NUM_FIELDS_PER_SHA256, fr, seed + 0xa00),
encryptedLogPreimagesLength: fr(seed + 0xb00),
unencryptedLogPreimagesLength: fr(seed + 0xc00),
header: makeHeader(seed + 0xd00, undefined),
historicalHeader: makeHeader(seed + 0xd00, undefined),
contractDeploymentData: makeContractDeploymentData(seed + 0xe00),
chainId: fr(seed + 0x1400),
version: fr(seed + 0x1500),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,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.header.state.partial.contract_tree.root;
let purported_contract_tree_root = private_call.call_stack_item.public_inputs.historical_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 @@ -21,7 +21,7 @@ struct PrivateKernelInputsInit {
impl PrivateKernelInputsInit {
fn initialize_end_values(self, public_inputs: &mut KernelCircuitPublicInputsBuilder) {
public_inputs.constants = CombinedConstantData {
header: self.private_call.call_stack_item.public_inputs.header,
header: self.private_call.call_stack_item.public_inputs.historical_header,
tx_context: self.tx_request.tx_context,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl PrivateKernelInputsInner {
}

fn validate_contract_tree_root(self) {
let purported_contract_tree_root = self.private_call.call_stack_item.public_inputs.header.state.partial.contract_tree.root;
let purported_contract_tree_root = self.private_call.call_stack_item.public_inputs.historical_header.state.partial.contract_tree.root;
let previous_kernel_contract_tree_root = self.previous_kernel.public_inputs.constants.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
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ struct PrivateCircuitPublicInputs {
encrypted_log_preimages_length: Field,
unencrypted_log_preimages_length: Field,

header: Header,
// Header of the block the transaction is executing against (not the block the transaction is included in).
historical_header: Header,

contract_deployment_data: ContractDeploymentData,

Expand Down Expand Up @@ -85,7 +86,7 @@ impl Hash for PrivateCircuitPublicInputs {
fields.push_array(self.unencrypted_logs_hash);
fields.push(self.encrypted_log_preimages_length);
fields.push(self.unencrypted_log_preimages_length);
fields.push_array(self.header.serialize());
fields.push_array(self.historical_header.serialize());
fields.push(self.contract_deployment_data.hash());
fields.push(self.chain_id);
fields.push(self.version);
Expand Down Expand Up @@ -120,7 +121,7 @@ impl PrivateCircuitPublicInputs {
fields.push_array(self.unencrypted_logs_hash);
fields.push(self.encrypted_log_preimages_length);
fields.push(self.unencrypted_log_preimages_length);
fields.push_array(self.header.serialize());
fields.push_array(self.historical_header.serialize());
fields.push_array(self.contract_deployment_data.serialize());
fields.push(self.chain_id);
fields.push(self.version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct PublicCircuitPublicInputs{
// variable-length data.
unencrypted_log_preimages_length: Field,

header: Header,
historical_header: Header,

prover_address: AztecAddress,
}
Expand Down Expand Up @@ -75,7 +75,7 @@ impl PublicCircuitPublicInputs{
inputs.push_array(self.new_l2_to_l1_msgs);
inputs.push_array(self.unencrypted_logs_hash);
inputs.push(self.unencrypted_log_preimages_length);
inputs.push_array(self.header.serialize());
inputs.push_array(self.historical_header.serialize());
inputs.push(self.prover_address.to_field());

assert_eq(inputs.len(), PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH, "Incorrect number of input fields when hashing PublicCircuitPublicInputs");
Expand Down Expand Up @@ -105,7 +105,7 @@ impl PublicCircuitPublicInputs{
fields.push_array(self.new_l2_to_l1_msgs);
fields.push_array(self.unencrypted_logs_hash);
fields.push(self.unencrypted_log_preimages_length);
fields.push_array(self.header.serialize());
fields.push_array(self.historical_header.serialize());
fields.push(self.prover_address.to_field());
fields.storage
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn empty_append_only_tree() -> AppendOnlyTreeSnapshot {
AppendOnlyTreeSnapshot::empty()
}

global BLOCK_HEADER = Header {
global HEADER = Header {
last_archive: empty_append_only_tree(),
body_hash: [0; NUM_FIELDS_PER_SHA256],
state: StateReference {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl PreviousKernelDataBuilder {
contract_address: fixtures::contracts::parent_contract.address,
portal_contract_address: fixtures::contracts::parent_contract.portal_contract_address,
end,
header: fixtures::BLOCK_HEADER,
header: fixtures::HEADER,
tx_context,
is_private: true,
proof: Proof {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct PrivateCircuitPublicInputsBuilder {
encrypted_log_preimages_length: Field,
unencrypted_log_preimages_length: Field,

header: Header,
historical_header: Header,

contract_deployment_data: ContractDeploymentData,

Expand Down Expand Up @@ -101,7 +101,7 @@ impl PrivateCircuitPublicInputsBuilder {
public_inputs.call_context = call_context;
public_inputs.args_hash = args_hash;
public_inputs.contract_deployment_data = contract_deployment_data;
public_inputs.header = fixtures::BLOCK_HEADER;
public_inputs.historical_header = fixtures::HEADER;
public_inputs.chain_id = 0;
public_inputs.version = 1;

Expand Down Expand Up @@ -131,7 +131,7 @@ impl PrivateCircuitPublicInputsBuilder {
encrypted_log_preimages_length: self.encrypted_log_preimages_length,
unencrypted_log_preimages_length: self.unencrypted_log_preimages_length,

header: self.header,
historical_header: self.historical_header,

contract_deployment_data: self.contract_deployment_data,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ 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,
header: Header,
historical_header: Header,
prover_address: AztecAddress,
}

impl PublicCircuitPublicInputsBuilder {
pub fn new() -> Self {
let mut public_inputs: PublicCircuitPublicInputsBuilder = dep::std::unsafe::zeroed();
public_inputs.call_context.msg_sender = fixtures::MSG_SENDER;
public_inputs.header = fixtures::BLOCK_HEADER;
public_inputs.historical_header = fixtures::HEADER;
public_inputs
}

Expand All @@ -61,7 +61,7 @@ impl PublicCircuitPublicInputsBuilder {
new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage,
unencrypted_logs_hash: self.unencrypted_logs_hash,
unencrypted_log_preimages_length: self.unencrypted_log_preimages_length,
header: self.header,
historical_header: self.historical_header,
prover_address: self.prover_address,
}
}
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/noir-protocol-circuits/src/type_conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ export function mapPrivateCircuitPublicInputsToNoir(
unencrypted_logs_hash: mapTuple(privateCircuitPublicInputs.unencryptedLogsHash, mapFieldToNoir),
encrypted_log_preimages_length: mapFieldToNoir(privateCircuitPublicInputs.encryptedLogPreimagesLength),
unencrypted_log_preimages_length: mapFieldToNoir(privateCircuitPublicInputs.unencryptedLogPreimagesLength),
header: mapHeaderToNoir(privateCircuitPublicInputs.header),
historical_header: mapHeaderToNoir(privateCircuitPublicInputs.historicalHeader),
contract_deployment_data: mapContractDeploymentDataToNoir(privateCircuitPublicInputs.contractDeploymentData),
chain_id: mapFieldToNoir(privateCircuitPublicInputs.chainId),
version: mapFieldToNoir(privateCircuitPublicInputs.version),
Expand Down Expand Up @@ -1211,7 +1211,7 @@ export function mapPublicCircuitPublicInputsToNoir(
new_l2_to_l1_msgs: mapTuple(publicInputs.newL2ToL1Msgs, mapFieldToNoir),
unencrypted_logs_hash: mapTuple(publicInputs.unencryptedLogsHash, mapFieldToNoir),
unencrypted_log_preimages_length: mapFieldToNoir(publicInputs.unencryptedLogPreimagesLength),
header: mapHeaderToNoir(publicInputs.header),
historical_header: mapHeaderToNoir(publicInputs.historicalHeader),

prover_address: mapAztecAddressToNoir(publicInputs.proverAddress),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export class PublicProcessor {
publicCallStackHashes,
unencryptedLogsHash,
unencryptedLogPreimagesLength,
header: this.header,
historicalHeader: this.header,
});
}

Expand Down

0 comments on commit 2e817f2

Please sign in to comment.