diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts b/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts index 2f8c353c8242..91629f6eb9d2 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts @@ -9,17 +9,22 @@ import { TxContext } from '../tx_context.js'; export class CombinedConstantData { constructor( /** - * Roots of the trees relevant for both kernel circuits. + * Header of a block whose state is used during execution (not the block the transaction is included in). */ - public header: Header, + public historicalHeader: Header, /** * Context of the transaction. + * + * Note: `chainId` and `version` in txContext are not redundant to the values in + * self.historical_header.global_variables because they can be different in case of a protocol upgrade. In such + * a situation we could be using header from a block before the upgrade took place but be using the updated + * protocol to execute and prove the transaction. */ public txContext: TxContext, ) {} toBuffer() { - return serializeToBuffer(this.header, this.txContext); + return serializeToBuffer(this.historicalHeader, this.txContext); } /** diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts index a4971a329b84..9ddd2fbcdde4 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts @@ -103,6 +103,10 @@ export class PrivateCircuitPublicInputs { public contractDeploymentData: ContractDeploymentData, /** * Chain Id of the instance. + * + * Note: The following 2 values are not redundant to the values in self.historical_header.global_variables because + * they can be different in case of a protocol upgrade. In such a situation we could be using header from a block + * before the upgrade took place but be using the updated protocol to execute and prove the transaction. */ public chainId: Fr, /** diff --git a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts index 1812355b76c3..4b6c4da2429e 100644 --- a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts @@ -163,7 +163,7 @@ describe('L1Publisher integration', () => { const kernelOutput = KernelCircuitPublicInputs.empty(); kernelOutput.constants.txContext.chainId = fr(chainId); kernelOutput.constants.txContext.version = fr(config.version); - kernelOutput.constants.header = prevHeader; + kernelOutput.constants.historicalHeader = prevHeader; kernelOutput.end.publicDataUpdateRequests = makeTuple( MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, i => new PublicDataUpdateRequest(fr(i), fr(0), fr(i + 10)), diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr index 44749f9f5ec8..bc95de381b0f 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr @@ -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.historical_header, + historical_header: self.private_call.call_stack_item.public_inputs.historical_header, tx_context: self.tx_request.tx_context, }; } @@ -91,7 +91,7 @@ impl PrivateKernelInputsInit { self.validate_this_private_call_against_tx_request(); common::validate_read_requests( - public_inputs.constants.header.state.partial.note_hash_tree.root, + public_inputs.constants.historical_header.state.partial.note_hash_tree.root, self.private_call.call_stack_item.public_inputs.read_requests, self.private_call.read_request_membership_witnesses ); diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr index bbc1961542d6..eb8f91b00d0c 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -23,7 +23,7 @@ impl PrivateKernelInputsInner { fn validate_contract_tree_root(self) { 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; + let previous_kernel_contract_tree_root = self.previous_kernel.public_inputs.constants.historical_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"); } @@ -52,7 +52,7 @@ impl PrivateKernelInputsInner { self.pop_and_validate_this_private_call_hash(&mut public_inputs); common::validate_read_requests( - public_inputs.constants.header.state.partial.note_hash_tree.root, + public_inputs.constants.historical_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); @@ -170,9 +170,9 @@ mod tests { fn private_function_incorrect_contract_tree_root_fails() { let mut builder = PrivateKernelInnerInputsBuilder::new(); - // Set historical_tree_root to a wrong value (the correct value + 1). - let contract_tree_root = builder.previous_kernel.header.state.partial.contract_tree.root; - builder.previous_kernel.header.state.partial.contract_tree.root = contract_tree_root + 1; + // Set historical contract tree root to a wrong value (the correct value + 1). + let contract_tree_root = builder.previous_kernel.historical_header.state.partial.contract_tree.root; + builder.previous_kernel.historical_header.state.partial.contract_tree.root = contract_tree_root + 1; builder.failed(); } @@ -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.header.state.partial.note_hash_tree.root; - builder.previous_kernel.header.state.partial.note_hash_tree.root = old_root + 1; + let old_root = builder.previous_kernel.historical_header.state.partial.note_hash_tree.root; + builder.previous_kernel.historical_header.state.partial.note_hash_tree.root = old_root + 1; builder.failed(); } diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr index 66a61abf878a..ec6999e06491 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -338,7 +338,7 @@ impl BaseRollupInputs { let archive_root = self.constants.last_archive.root; // Rebuild the block hash - let header = self.kernel_data.public_inputs.constants.header; + let header = self.kernel_data.public_inputs.constants.historical_header; let previous_block_hash = header.block_hash(); let previous_block_hash_witness = self.archive_root_membership_witness; @@ -738,7 +738,7 @@ mod tests { let _nullifier = builder.end.new_nullifiers.pop(); inputs.kernel_data = builder.is_public(); - inputs.pre_existing_blocks[0] = inputs.kernel_data.header.block_hash(); + inputs.pre_existing_blocks[0] = inputs.kernel_data.historical_header.block_hash(); inputs } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/combined_constant_data.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/combined_constant_data.nr index 796a4976fa97..2ccf9e7e51bc 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/combined_constant_data.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/combined_constant_data.nr @@ -2,6 +2,10 @@ use crate::transaction::context::TxContext; use crate::header::Header; struct CombinedConstantData { - header: Header, + historical_header: Header, + // Note: `chainId` and `version` in txContext are not redundant to the values in + // self.historical_header.global_variables because they can be different in case of a protocol upgrade. In such + // a situation we could be using header from a block before the upgrade took place but be using the updated + // protocol to execute and prove the transaction. tx_context: TxContext, } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr index 40248daa202b..a3b07213146e 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr @@ -56,6 +56,9 @@ struct PrivateCircuitPublicInputs { contract_deployment_data: ContractDeploymentData, + // Note: The following 2 values are not redundant to the values in self.historical_header.global_variables because + // they can be different in case of a protocol upgrade. In such a situation we could be using header from a block + // before the upgrade took place but be using the updated protocol to execute and prove the transaction. chain_id: Field, version: Field, } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/previous_kernel_data_builder.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/previous_kernel_data_builder.nr index ec329d912ed6..65dc56d4d93b 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/previous_kernel_data_builder.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/previous_kernel_data_builder.nr @@ -32,7 +32,7 @@ struct PreviousKernelDataBuilder { contract_address: AztecAddress, portal_contract_address: EthAddress, end: CombinedAccumulatedDataBuilder, - header: Header, + historical_header: Header, tx_context: TxContext, is_private: bool, proof: Proof, @@ -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::HEADER, + historical_header: fixtures::HEADER, tx_context, is_private: true, proof: Proof {}, @@ -197,7 +197,7 @@ impl PreviousKernelDataBuilder { let public_inputs = KernelCircuitPublicInputs { end: self.end.finish(), constants: CombinedConstantData { - header: self.header, + historical_header: self.historical_header, tx_context: self.tx_context, }, is_private: self.is_private, diff --git a/yarn-project/noir-protocol-circuits/src/type_conversion.ts b/yarn-project/noir-protocol-circuits/src/type_conversion.ts index 4a493ff4d753..1815befd1713 100644 --- a/yarn-project/noir-protocol-circuits/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits/src/type_conversion.ts @@ -994,7 +994,7 @@ export function mapCombinedAccumulatedDataToNoir( */ export function mapCombinedConstantDataFromNoir(combinedConstantData: CombinedConstantDataNoir): CombinedConstantData { return new CombinedConstantData( - mapHeaderFromNoir(combinedConstantData.header), + mapHeaderFromNoir(combinedConstantData.historical_header), mapTxContextFromNoir(combinedConstantData.tx_context), ); } @@ -1006,7 +1006,7 @@ export function mapCombinedConstantDataFromNoir(combinedConstantData: CombinedCo */ export function mapCombinedConstantDataToNoir(combinedConstantData: CombinedConstantData): CombinedConstantDataNoir { return { - header: mapHeaderToNoir(combinedConstantData.header), + historical_header: mapHeaderToNoir(combinedConstantData.historicalHeader), tx_context: mapTxContextToNoir(combinedConstantData.txContext), }; } diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts index 27f6e78a20b9..8afe5f4197a3 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.test.ts @@ -191,7 +191,7 @@ describe('sequencer/solo_block_builder', () => { const buildMockSimulatorInputs = async () => { const kernelOutput = makePrivateKernelPublicInputsFinal(); - kernelOutput.constants.header = await buildInitialHeader(expectsDb); + kernelOutput.constants.historicalHeader = await buildInitialHeader(expectsDb); const tx = await makeProcessedTx( new Tx( @@ -297,7 +297,7 @@ describe('sequencer/solo_block_builder', () => { const makeBloatedProcessedTx = async (seed = 0x1) => { const tx = mockTx(seed); const kernelOutput = KernelCircuitPublicInputs.empty(); - kernelOutput.constants.header = await buildInitialHeader(builderDb); + kernelOutput.constants.historicalHeader = await buildInitialHeader(builderDb); kernelOutput.end.publicDataUpdateRequests = makeTuple( MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, i => new PublicDataUpdateRequest(fr(i), fr(0), fr(i + 10)), diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts index 97c7396b78b9..49318dcaa672 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts @@ -157,7 +157,7 @@ export class SoloBlockBuilder implements BlockBuilder { protected validateTxs(txs: ProcessedTx[]) { for (const tx of txs) { - const txHeader = tx.data.constants.header; + const txHeader = tx.data.constants.historicalHeader; if (txHeader.state.l1ToL2MessageTree.isEmpty()) { throw new Error(`Empty L1 to L2 messages tree in tx: ${toFriendlyJSON(tx)}`); } @@ -492,7 +492,7 @@ export class SoloBlockBuilder implements BlockBuilder { } protected getHistoricalTreesMembershipWitnessFor(tx: ProcessedTx) { - const header = tx.data.constants.header; + const header = tx.data.constants.historicalHeader; // TODO(#3941) const blockHash = computeBlockHash( computeGlobalsHash(header.globalVariables), diff --git a/yarn-project/sequencer-client/src/sequencer/processed_tx.ts b/yarn-project/sequencer-client/src/sequencer/processed_tx.ts index 73a2b41e4788..cecd49aa844a 100644 --- a/yarn-project/sequencer-client/src/sequencer/processed_tx.ts +++ b/yarn-project/sequencer-client/src/sequencer/processed_tx.ts @@ -89,7 +89,7 @@ export async function makeProcessedTx( */ export function makeEmptyProcessedTx(header: Header, chainId: Fr, version: Fr): Promise { const emptyKernelOutput = PublicKernelPublicInputs.empty(); - emptyKernelOutput.constants.header = header; + emptyKernelOutput.constants.historicalHeader = header; emptyKernelOutput.constants.txContext.chainId = chainId; emptyKernelOutput.constants.txContext.version = version; const emptyProof = makeEmptyProof();