Skip to content

Commit

Permalink
docs + naming
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 30, 2024
1 parent e7bc0c5 commit 354425c
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
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.historical_header,
historical_header: self.private_call.call_stack_item.public_inputs.historical_header,
tx_context: self.tx_request.tx_context,
};
}
Expand Down Expand Up @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
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.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);

Expand Down Expand Up @@ -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();
}
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.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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {},
Expand Down Expand Up @@ -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,
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 @@ -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),
);
}
Expand All @@ -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),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function makeProcessedTx(
*/
export function makeEmptyProcessedTx(header: Header, chainId: Fr, version: Fr): Promise<ProcessedTx> {
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();
Expand Down

0 comments on commit 354425c

Please sign in to comment.