From d25bfbc8828240155afb9db797ef6bfc947084aa Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 5 Feb 2024 16:22:29 +0000 Subject: [PATCH] WIP --- .../src/core/libraries/ConstantsGen.sol | 8 +- .../acir-simulator/src/public/index.test.ts | 18 ++- .../aztec-node/src/aztec-node/server.ts | 11 +- .../src/abis/__snapshots__/abis.test.ts.snap | 66 +++++----- yarn-project/circuits.js/src/constants.gen.ts | 8 +- .../structs/__snapshots__/header.test.ts.snap | 62 ++++----- .../private_call_stack_item.test.ts.snap | 120 ++++++++--------- ...private_circuit_public_inputs.test.ts.snap | 124 +++++++++--------- .../public_call_stack_item.test.ts.snap | 62 ++++----- .../public_circuit_public_inputs.test.ts.snap | 64 ++++----- .../src/integration_l1_publisher.test.ts | 13 ++ .../crates/types/src/abis/global_variables.nr | 10 +- .../types/src/abis/private_call_stack_item.nr | 2 +- .../src/abis/private_circuit_public_inputs.nr | 2 +- .../src/crates/types/src/constants.nr | 8 +- .../src/crates/types/src/interop_testing.nr | 4 +- .../src/crates/types/src/tests/fixtures.nr | 11 +- .../src/type_conversion.ts | 4 + .../block_builder/solo_block_builder.test.ts | 6 +- .../global_variable_builder/global_builder.ts | 18 ++- .../src/sequencer/sequencer.test.ts | 28 ++-- .../src/sequencer/sequencer.ts | 11 +- 22 files changed, 368 insertions(+), 292 deletions(-) diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 381d13aaf7c6..9e238ec67b64 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -75,14 +75,14 @@ library Constants { uint256 internal constant GLOBAL_VARIABLES_LENGTH = 6; uint256 internal constant PARTIAL_STATE_REFERENCE_LENGTH = 8; uint256 internal constant STATE_REFERENCE_LENGTH = 10; - uint256 internal constant HEADER_LENGTH = 18; + uint256 internal constant HEADER_LENGTH = 20; uint256 internal constant FUNCTION_DATA_LENGTH = 4; uint256 internal constant CONTRACT_DEPLOYMENT_DATA_LENGTH = 6; - uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 204; - uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 209; + uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 206; + uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 211; uint256 internal constant CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 3; uint256 internal constant CONTRACT_STORAGE_READ_LENGTH = 2; - uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 201; + uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 203; uint256 internal constant GET_NOTES_ORACLE_RETURN_LENGTH = 674; uint256 internal constant COMMITMENTS_NUM_BYTES_PER_BASE_ROLLUP = 2048; uint256 internal constant NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 2048; diff --git a/yarn-project/acir-simulator/src/public/index.test.ts b/yarn-project/acir-simulator/src/public/index.test.ts index e96cd2ecaa91..a0c1f9e04b2c 100644 --- a/yarn-project/acir-simulator/src/public/index.test.ts +++ b/yarn-project/acir-simulator/src/public/index.test.ts @@ -264,7 +264,14 @@ describe('ACIR public execution simulator', () => { }); const execution: PublicExecution = { contractAddress: parentContractAddress, functionData, args, callContext }; - const globalVariables = new GlobalVariables(new Fr(69), new Fr(420), new Fr(1), new Fr(7)); + const globalVariables = new GlobalVariables( + new Fr(69), + new Fr(420), + new Fr(1), + new Fr(7), + EthAddress.fromField(new Fr(8)), + AztecAddress.fromField(new Fr(9)), + ); if (isInternal === undefined) { await expect(executor.simulate(execution, globalVariables)).rejects.toThrowError(/Method not found -/); @@ -449,7 +456,14 @@ describe('ACIR public execution simulator', () => { }); const computeGlobalVariables = () => - new GlobalVariables(new Fr(preimage.sender.chainId), new Fr(preimage.recipient.version), Fr.ZERO, Fr.ZERO); + new GlobalVariables( + new Fr(preimage.sender.chainId), + new Fr(preimage.recipient.version), + Fr.ZERO, + Fr.ZERO, + EthAddress.ZERO, + AztecAddress.ZERO, + ); const mockOracles = () => { publicContracts.getBytecode.mockResolvedValue(Buffer.from(mintPublicArtifact.bytecode, 'base64')); diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index a6a5fb16b418..2940f8d55d3d 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -26,6 +26,7 @@ import { import { ARCHIVE_HEIGHT, CONTRACT_TREE_HEIGHT, + EthAddress, Fr, Header, L1_TO_L2_MSG_TREE_HEIGHT, @@ -550,7 +551,15 @@ export class AztecNodeService implements AztecNode { public async simulatePublicCalls(tx: Tx) { this.log.info(`Simulating tx ${await tx.getTxHash()}`); const blockNumber = (await this.blockSource.getBlockNumber()) + 1; - const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(new Fr(blockNumber)); + + // TODO(benesjan): populate these values from config. + const coinbase = EthAddress.ZERO; + const feeRecipient = AztecAddress.ZERO; + const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables( + new Fr(blockNumber), + coinbase, + feeRecipient, + ); const prevHeader = (await this.blockSource.getBlock(-1))?.header; // Instantiate merkle trees so uncommitted updates by this simulation are local to it. diff --git a/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap b/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap index 864ddea2d127..b169f23ce2b8 100644 --- a/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap +++ b/yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap @@ -1,8 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`abis Computes a callstack item hash 1`] = `"0x037cb5ba672a7c461e23cf22ae618757ab4f1a912f3fdc93b2b2800cfe57bb91"`; +exports[`abis Computes a callstack item hash 1`] = `"0x17095bbb9e3e104dc520b6eec9338e9b6ce1fdc0f3a66b06d5ca90b15909ad0e"`; -exports[`abis Computes a callstack item request hash 1`] = `"0x2c36008a759d932a3a1986429aa295e2c2d4e62c33197a7d259750d29347bf30"`; +exports[`abis Computes a callstack item request hash 1`] = `"0x28cb4c264eb11e13c77a5e60b251a6b3edfb4cfed786c4f1ec5e1749fede9b78"`; exports[`abis Computes an empty nullifier hash 1`] = `"0x066e6cdc4a6ba5e4781deda650b0be6c12f975f064fc38df72c1060716759b17"`; @@ -10,41 +10,41 @@ exports[`abis Computes an empty sideeffect hash 1`] = `"0x27b1d0839a5b23baf12a8 exports[`abis compute public call stack item hash 1`] = ` Fr { - "asBigInt": 4942803204430729321299247114280769628204291639882373728884145897482860239103n, + "asBigInt": 6902726350534637945034037933577508446422215007904358955522461123516426791152n, "asBuffer": { "data": [ - 10, - 237, - 135, - 8, - 121, - 161, - 111, - 170, - 23, - 173, - 20, - 73, - 240, - 78, - 59, - 30, - 113, - 136, - 151, + 15, + 66, + 205, + 254, + 91, + 241, + 101, 117, - 250, - 42, - 35, - 186, - 162, - 159, - 250, - 242, - 152, - 210, + 214, + 154, + 136, + 128, + 223, + 11, + 120, + 249, + 245, + 174, + 102, + 132, + 69, + 153, + 88, + 179, + 36, + 144, + 98, + 110, 24, - 255, + 250, + 168, + 240, ], "type": "Buffer", }, diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 57491e91c4bf..a65ae217c2b7 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -61,14 +61,14 @@ export const CALL_CONTEXT_LENGTH = 8; export const GLOBAL_VARIABLES_LENGTH = 6; export const PARTIAL_STATE_REFERENCE_LENGTH = 8; export const STATE_REFERENCE_LENGTH = 10; -export const HEADER_LENGTH = 18; +export const HEADER_LENGTH = 20; export const FUNCTION_DATA_LENGTH = 4; export const CONTRACT_DEPLOYMENT_DATA_LENGTH = 6; -export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 204; -export const PRIVATE_CALL_STACK_ITEM_LENGTH = 209; +export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 206; +export const PRIVATE_CALL_STACK_ITEM_LENGTH = 211; export const CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 3; export const CONTRACT_STORAGE_READ_LENGTH = 2; -export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 201; +export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 203; export const GET_NOTES_ORACLE_RETURN_LENGTH = 674; export const COMMITMENTS_NUM_BYTES_PER_BASE_ROLLUP = 2048; export const NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 2048; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap index 8a15a59ee847..035cc0c2eb61 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/header.test.ts.snap @@ -2,41 +2,41 @@ exports[`Header computes hash 1`] = ` Fr { - "asBigInt": 17991638921121681345555824161757346486368776085978982802127357651656088857262n, + "asBigInt": 17535834694933389587922737272908689289752880632518238306089028120587248314683n, "asBuffer": { "data": [ - 39, - 198, - 232, - 33, - 120, - 194, - 121, - 42, - 23, - 66, - 111, - 251, - 166, - 131, - 251, - 128, - 16, - 46, - 122, - 209, - 193, - 24, - 177, + 38, + 196, + 238, 67, - 172, - 91, - 198, - 153, - 236, - 93, + 20, + 47, + 99, + 167, + 32, + 178, + 243, + 109, + 29, + 247, 170, - 174, + 104, + 85, + 155, + 139, + 190, + 13, + 63, + 35, + 158, + 188, + 79, + 120, + 214, + 216, + 211, + 169, + 59, ], "type": "Buffer", }, diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap index d1cf2f9076a6..16782ee0b9f1 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap @@ -2,41 +2,41 @@ exports[`PrivateCallStackItem computes empty item hash 1`] = ` Fr { - "asBigInt": 21230813221792739829032218511346459661622392006403997687170807299887246304465n, + "asBigInt": 11439500418935448938812546834954776447064444607864398684460320872436560621982n, "asBuffer": { "data": [ + 25, + 74, + 135, + 29, + 37, + 166, 46, - 240, - 54, + 249, + 105, 229, - 221, - 27, - 22, - 205, - 116, - 188, - 205, - 128, - 113, - 43, - 99, - 253, - 225, - 42, - 162, - 230, - 75, - 8, - 243, - 160, - 150, - 65, - 149, - 200, - 179, - 79, - 100, - 209, + 215, + 206, + 201, + 62, + 133, + 18, + 199, + 148, + 18, + 180, + 37, + 240, + 5, + 122, + 38, + 213, + 39, + 140, + 152, + 152, + 241, + 158, ], "type": "Buffer", }, @@ -45,41 +45,41 @@ Fr { exports[`PrivateCallStackItem computes hash 1`] = ` Fr { - "asBigInt": 14723811775539034985226914197401344473208275906441619992416957589322673569693n, + "asBigInt": 17854733235616142992562943781448885630816268824088546745305752514531058544044n, "asBuffer": { "data": [ - 32, - 141, - 97, - 211, - 254, - 114, - 95, - 205, - 151, - 179, - 64, - 109, + 39, 121, + 107, + 191, + 93, + 67, + 27, + 97, + 134, + 246, + 58, + 60, 32, - 239, + 10, + 45, + 51, 244, - 117, - 162, - 13, - 12, - 74, - 168, - 124, + 233, + 127, + 77, + 252, + 30, 126, - 12, - 59, - 146, - 221, - 124, - 42, - 63, - 157, + 179, + 89, + 72, + 47, + 17, + 15, + 212, + 109, + 172, ], "type": "Buffer", }, diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap index 7db6aeed31ec..ba89d4a95a62 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap @@ -2,41 +2,41 @@ exports[`PrivateCircuitPublicInputs computes empty inputs hash 1`] = ` Fr { - "asBigInt": 12301192320887385040004337322010330544799239165678935149737125610986921421742n, + "asBigInt": 15009669417594571011971928726665820728708862021844424267205193289691767079587n, "asBuffer": { "data": [ - 27, - 50, + 33, + 47, + 43, + 253, + 60, 58, - 102, - 44, - 155, - 59, - 78, - 57, + 112, + 8, + 217, + 145, + 43, + 195, + 206, + 127, + 79, + 166, + 145, + 160, + 229, + 226, + 205, + 54, + 202, + 69, + 215, + 211, + 85, + 178, + 92, 121, - 12, - 232, + 130, 163, - 173, - 44, - 126, - 204, - 147, - 1, - 69, - 103, - 187, - 156, - 228, - 194, - 51, - 60, - 93, - 32, - 90, - 107, - 174, ], "type": "Buffer", }, @@ -45,41 +45,41 @@ Fr { exports[`PrivateCircuitPublicInputs hash matches snapshot 1`] = ` Fr { - "asBigInt": 7655509707748365385586683354008259293573299722789964529445054772581519738939n, + "asBigInt": 11005984743792704675785249129978181985212791670182471125510583326224241613766n, "asBuffer": { "data": [ - 16, - 236, - 221, - 108, - 242, - 63, - 20, - 45, - 47, - 147, - 239, - 244, - 141, - 4, - 72, - 218, - 247, - 23, - 13, + 24, + 85, + 42, + 167, + 15, + 123, + 128, + 118, + 1, + 175, + 92, + 134, + 53, + 77, + 250, + 41, + 181, + 48, + 198, + 213, + 150, + 231, + 235, + 120, 105, - 121, - 159, - 29, - 162, - 114, - 51, - 52, - 186, - 54, - 94, - 72, - 59, + 243, + 98, + 219, + 20, + 111, + 91, + 198, ], "type": "Buffer", }, diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap index 75ceefadf6bd..24fe6a5e3f8b 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap @@ -2,41 +2,41 @@ exports[`PublicCallStackItem computes hash 1`] = ` Fr { - "asBigInt": 21083506383287217425295039971423278330073026042631744223709570040299661814284n, + "asBigInt": 19395696808724235586564354338261030411639537309350164360825567543448743585810n, "asBuffer": { "data": [ - 46, - 156, - 215, - 123, - 140, - 169, - 181, - 209, - 208, - 197, - 70, + 42, + 225, + 147, 74, - 61, - 112, - 87, - 194, - 89, - 68, - 53, - 181, - 239, - 169, - 58, - 168, - 66, + 255, + 117, + 70, + 214, + 242, + 250, 92, - 84, - 75, - 166, - 83, - 234, - 12, + 118, + 98, + 92, + 21, + 18, + 34, + 226, + 246, + 182, + 119, + 107, + 40, + 145, + 163, + 218, + 248, + 163, + 143, + 58, + 40, + 18, ], "type": "Buffer", }, diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap index 574d36a80416..3c27ef029318 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap @@ -2,41 +2,41 @@ exports[`PublicCircuitPublicInputs hash matches snapshot 1`] = ` Fr { - "asBigInt": 10987106036606499987406426170447920941391129891158672246363150499235953526428n, + "asBigInt": 18998488698478370909936348553101901315705060100426498604017308046889259543837n, "asBuffer": { "data": [ - 24, - 74, - 123, - 76, - 228, - 113, - 134, - 151, - 63, - 27, - 17, - 70, - 189, - 227, - 135, - 146, - 250, - 51, - 192, - 79, - 251, - 233, - 86, - 238, + 42, 0, - 176, - 100, - 200, - 210, - 134, - 70, - 156, + 195, + 119, + 87, + 116, + 9, + 251, + 84, + 111, + 49, + 221, + 110, + 21, + 211, + 9, + 191, + 82, + 247, + 169, + 39, + 25, + 140, + 78, + 50, + 138, + 231, + 209, + 33, + 158, + 173, + 29, ], "type": "Buffer", }, 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 f147fccfd4b2..b7e7372d4715 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 @@ -10,6 +10,7 @@ import { to2Fields, } from '@aztec/aztec.js'; import { + EthAddress, Header, KernelCircuitPublicInputs, MAX_NEW_COMMITMENTS_PER_TX, @@ -358,11 +359,17 @@ describe('L1Publisher integration', () => { await makeBloatedProcessedTx(totalNullifiersPerBlock * i + 3 * MAX_NEW_NULLIFIERS_PER_TX), await makeBloatedProcessedTx(totalNullifiersPerBlock * i + 4 * MAX_NEW_NULLIFIERS_PER_TX), ]; + + // TODO(benesjan): populate these values from config. + const coinbase = EthAddress.ZERO; + const feeRecipient = AztecAddress.ZERO; const globalVariables = new GlobalVariables( new Fr(chainId), new Fr(config.version), new Fr(1 + i), new Fr(await rollup.read.lastBlockTs()), + coinbase, + feeRecipient, ); const [block] = await builder.buildL2Block(globalVariables, txs, l1ToL2Messages); prevHeader = block.header; @@ -440,11 +447,17 @@ describe('L1Publisher integration', () => { await makeEmptyProcessedTx(), await makeEmptyProcessedTx(), ]; + + // TODO(benesjan): populate these values from config. + const coinbase = EthAddress.ZERO; + const feeRecipient = AztecAddress.ZERO; const globalVariables = new GlobalVariables( new Fr(chainId), new Fr(config.version), new Fr(1 + i), new Fr(await rollup.read.lastBlockTs()), + coinbase, + feeRecipient, ); const [block] = await builder.buildL2Block(globalVariables, txs, l1ToL2Messages); prevHeader = block.header; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/global_variables.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/global_variables.nr index f4c988e76897..c7d9ef97d10f 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/global_variables.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/global_variables.nr @@ -22,7 +22,7 @@ struct GlobalVariables { block_number : Field, timestamp : Field, coinbase : EthAddress, - feeRecipient : AztecAddress, + fee_recipient : AztecAddress, } impl Serialize for GlobalVariables { @@ -33,7 +33,7 @@ impl Serialize for GlobalVariables { self.block_number, self.timestamp, self.coinbase.to_field(), - self.feeRecipient.to_field(), + self.fee_recipient.to_field(), ] } } @@ -46,7 +46,7 @@ impl Deserialize for GlobalVariables { block_number: serialized[2], timestamp: serialized[3], coinbase: EthAddress::from_field(serialized[4]), - feeRecipient: AztecAddress::from_field(serialized[5]), + fee_recipient: AztecAddress::from_field(serialized[5]), } } } @@ -58,7 +58,7 @@ impl Eq for GlobalVariables { (self.block_number == other.block_number) & (self.timestamp == other.timestamp) & (self.coinbase == other.coinbase) & - (self.feeRecipient == other.feeRecipient) + (self.fee_recipient == other.fee_recipient) } } @@ -70,7 +70,7 @@ impl Empty for GlobalVariables { block_number: 0, timestamp: 0, coinbase: EthAddress::empty(), - feeRecipient: AztecAddress::empty(), + fee_recipient: AztecAddress::empty(), } } } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_call_stack_item.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_call_stack_item.nr index 5b907ed61c4a..bee5de00438a 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_call_stack_item.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_call_stack_item.nr @@ -87,5 +87,5 @@ fn empty_hash() { let hash = item.hash(); // Value from private_call_stack_item.test.ts "computes empty item hash" test - assert_eq(hash, 0x2ef036e5dd1b16cd74bccd80712b63fde12aa2e64b08f3a0964195c8b34f64d1); + assert_eq(hash, 0x194a871d25a62ef969e5d7cec93e8512c79412b425f0057a26d5278c9898f19e); } 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 45eb76d7c413..dd2eb5fab57c 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 @@ -180,5 +180,5 @@ fn empty_hash() { let hash = inputs.hash(); // Value from private_circuit_public_inputs.test.ts "computes empty item hash" test - assert_eq(hash, 0x1b323a662c9b3b4e39790ce8a3ad2c7ecc93014567bb9ce4c2333c5d205a6bae); + assert_eq(hash, 0x212f2bfd3c3a7008d9912bc3ce7f4fa691a0e5e2cd36ca45d7d355b25c7982a3); } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/constants.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/constants.nr index f81987b7eff6..f4ffc85f76cc 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/constants.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/constants.nr @@ -110,18 +110,18 @@ global CALL_CONTEXT_LENGTH: Field = 8; global GLOBAL_VARIABLES_LENGTH: Field = 6; global PARTIAL_STATE_REFERENCE_LENGTH: Field = 8; global STATE_REFERENCE_LENGTH: Field = 10; // 2 for snap + 8 for partial -global HEADER_LENGTH: Field = 18; // 2 for last_archive, 2 for body hash, 10 for state reference, 4 for global vars +global HEADER_LENGTH: Field = 20; // 2 for last_archive, 2 for body hash, 10 for state reference, 6 for global vars global FUNCTION_DATA_LENGTH: Field = 4; 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 PRIVATE_CALL_STACK_ITEM_LENGTH -global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: Field = 204; -global PRIVATE_CALL_STACK_ITEM_LENGTH: Field = 209; +global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: Field = 206; +global PRIVATE_CALL_STACK_ITEM_LENGTH: Field = 211; 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. -global PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH: Field = 201; +global PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH: Field = 203; global GET_NOTES_ORACLE_RETURN_LENGTH: Field = 674; global COMMITMENTS_NUM_BYTES_PER_BASE_ROLLUP: Field = 2048; global NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP: Field = 2048; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/interop_testing.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/interop_testing.nr index 205e8bf2403b..02d54fa075d0 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/interop_testing.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/interop_testing.nr @@ -129,7 +129,7 @@ fn compute_call_stack_item_request_hash() { let call_stack_item = PublicCallStackItem { contract_address, public_inputs, is_execution_request: true, function_data }; // Value from abis.test.ts "Computes a callstack item request hash" test - assert_eq(call_stack_item.hash(), 0x2c36008a759d932a3a1986429aa295e2c2d4e62c33197a7d259750d29347bf30); + assert_eq(call_stack_item.hash(), 0x28cb4c264eb11e13c77a5e60b251a6b3edfb4cfed786c4f1ec5e1749fede9b78); } #[test] @@ -146,5 +146,5 @@ fn compute_call_stack_item_hash() { let call_stack_item = PublicCallStackItem { contract_address, public_inputs, is_execution_request: false, function_data }; // Value from abis.test.ts "Computes a callstack item hash" test - assert_eq(call_stack_item.hash(), 0x037cb5ba672a7c461e23cf22ae618757ab4f1a912f3fdc93b2b2800cfe57bb91); + assert_eq(call_stack_item.hash(), 0x17095bbb9e3e104dc520b6eec9338e9b6ce1fdc0f3a66b06d5ca90b15909ad0e); } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr index 0ad476874e5f..05a90de5618b 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr @@ -53,7 +53,14 @@ global HEADER = Header { version: 0, block_number: 0, timestamp: 0, - coinbase: EthAddress::empty(), - feeRecipient: AztecAddress::empty() + coinbase: EthAddress { + inner: 0 + }, + fee_recipient: AztecAddress { + inner: 0 + }, + // TODO(benesjan): figure out why this doesn't work + // coinbase: EthAddress::empty(), + // fee_recipient: AztecAddress::empty(), } }; diff --git a/yarn-project/noir-protocol-circuits/src/type_conversion.ts b/yarn-project/noir-protocol-circuits/src/type_conversion.ts index db92f66ca70b..d010946a4cb5 100644 --- a/yarn-project/noir-protocol-circuits/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits/src/type_conversion.ts @@ -1149,6 +1149,8 @@ export function mapGlobalVariablesToNoir(globalVariables: GlobalVariables): Glob version: mapFieldToNoir(globalVariables.version), block_number: mapFieldToNoir(globalVariables.blockNumber), timestamp: mapFieldToNoir(globalVariables.timestamp), + coinbase: mapEthAddressToNoir(globalVariables.coinbase), + fee_recipient: mapAztecAddressToNoir(globalVariables.feeRecipient), }; } @@ -1174,6 +1176,8 @@ export function mapGlobalVariablesFromNoir(globalVariables: GlobalVariablesNoir) mapFieldFromNoir(globalVariables.version), mapFieldFromNoir(globalVariables.block_number), mapFieldFromNoir(globalVariables.timestamp), + mapEthAddressFromNoir(globalVariables.coinbase), + mapAztecAddressFromNoir(globalVariables.fee_recipient), ); } 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 470ce36f9cc3..9ff0678357f0 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 @@ -12,7 +12,9 @@ import { } from '@aztec/circuit-types'; import { AppendOnlyTreeSnapshot, + AztecAddress, BaseOrMergeRollupPublicInputs, + EthAddress, Fr, GlobalVariables, Header, @@ -91,10 +93,12 @@ describe('sequencer/solo_block_builder', () => { const chainId = Fr.ZERO; const version = Fr.ZERO; + const coinbase = EthAddress.ZERO; + const feeRecipient = AztecAddress.ZERO; beforeEach(async () => { blockNumber = 3; - globalVariables = new GlobalVariables(chainId, version, new Fr(blockNumber), Fr.ZERO); + globalVariables = new GlobalVariables(chainId, version, new Fr(blockNumber), Fr.ZERO, coinbase, feeRecipient); builderDb = await MerkleTrees.new(await AztecLmdbStore.openTmp()).then(t => t.asLatest()); expectsDb = await MerkleTrees.new(await AztecLmdbStore.openTmp()).then(t => t.asLatest()); diff --git a/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts b/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts index d50a8b8f83b4..2b6212b71daa 100644 --- a/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts +++ b/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts @@ -1,4 +1,4 @@ -import { GlobalVariables } from '@aztec/circuits.js'; +import { AztecAddress, EthAddress, GlobalVariables } from '@aztec/circuits.js'; import { Fr } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; @@ -42,9 +42,11 @@ export interface GlobalVariableBuilder { /** * Builds global variables. * @param blockNumber - The block number to build global variables for. + * @param coinbase - The address to receive block reward. + * @param feeRecipient - The address to receive fees. * @returns The global variables for the given block number. */ - buildGlobalVariables(blockNumber: Fr): Promise; + buildGlobalVariables(blockNumber: Fr, coinbase: EthAddress, feeRecipient: AztecAddress): Promise; } /** @@ -58,9 +60,15 @@ export class SimpleTestGlobalVariableBuilder implements GlobalVariableBuilder { /** * Simple builder of global variables that use the minimum time possible. * @param blockNumber - The block number to build global variables for. + * @param coinbase - The address to receive block reward. + * @param feeRecipient - The address to receive fees. * @returns The global variables for the given block number. */ - public async buildGlobalVariables(blockNumber: Fr): Promise { + public async buildGlobalVariables( + blockNumber: Fr, + coinbase: EthAddress, + feeRecipient: AztecAddress, + ): Promise { let lastTimestamp = new Fr(await this.reader.getLastTimestamp()); const version = new Fr(await this.reader.getVersion()); const chainId = new Fr(await this.reader.getChainId()); @@ -79,9 +87,9 @@ export class SimpleTestGlobalVariableBuilder implements GlobalVariableBuilder { } this.log( - `Built global variables for block ${blockNumber}: (${chainId}, ${version}, ${blockNumber}, ${lastTimestamp})`, + `Built global variables for block ${blockNumber}: (${chainId}, ${version}, ${blockNumber}, ${lastTimestamp}, ${coinbase}, ${feeRecipient})`, ); - return new GlobalVariables(chainId, version, blockNumber, lastTimestamp); + return new GlobalVariables(chainId, version, blockNumber, lastTimestamp, coinbase, feeRecipient); } } diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts index f3d94763f0ef..dc433041bb51 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.test.ts @@ -8,7 +8,15 @@ import { TxHash, mockTx, } from '@aztec/circuit-types'; -import { Fr, GlobalVariables, Header, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, makeEmptyProof } from '@aztec/circuits.js'; +import { + AztecAddress, + EthAddress, + Fr, + GlobalVariables, + Header, + NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, + makeEmptyProof, +} from '@aztec/circuits.js'; import { times } from '@aztec/foundation/collection'; import { P2P, P2PClientState } from '@aztec/p2p'; import { MerkleTreeOperations, WorldStateRunningState, WorldStateSynchronizer } from '@aztec/world-state'; @@ -40,6 +48,8 @@ describe('sequencer', () => { const chainId = new Fr(12345); const version = Fr.ZERO; + const coinbase = EthAddress.random(); + const feeRecipient = AztecAddress.random(); beforeEach(() => { lastBlockNumber = 0; @@ -98,7 +108,7 @@ describe('sequencer', () => { blockBuilder.buildL2Block.mockResolvedValueOnce([block, proof]); publisher.processL2Block.mockResolvedValueOnce(true); globalVariableBuilder.buildGlobalVariables.mockResolvedValueOnce( - new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO), + new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO, coinbase, feeRecipient), ); await sequencer.initialSync(); @@ -107,7 +117,7 @@ describe('sequencer', () => { const expectedTxHashes = [...(await Tx.getHashes([tx])), ...times(1, () => TxHash.ZERO)]; expect(blockBuilder.buildL2Block).toHaveBeenCalledWith( - new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO), + new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO, coinbase, feeRecipient), expectedTxHashes.map(hash => expect.objectContaining({ hash })), Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(new Fr(0n)), ); @@ -127,7 +137,7 @@ describe('sequencer', () => { blockBuilder.buildL2Block.mockResolvedValueOnce([block, proof]); publisher.processL2Block.mockResolvedValueOnce(true); globalVariableBuilder.buildGlobalVariables.mockResolvedValueOnce( - new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO), + new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO, coinbase, feeRecipient), ); // We make a nullifier from tx1 a part of the nullifier tree, so it gets rejected as double spend @@ -144,7 +154,7 @@ describe('sequencer', () => { const expectedTxHashes = await Tx.getHashes([txs[0], txs[2]]); expect(blockBuilder.buildL2Block).toHaveBeenCalledWith( - new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO), + new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO, coinbase, feeRecipient), expectedTxHashes.map(hash => expect.objectContaining({ hash })), Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(new Fr(0n)), ); @@ -165,7 +175,7 @@ describe('sequencer', () => { blockBuilder.buildL2Block.mockResolvedValueOnce([block, proof]); publisher.processL2Block.mockResolvedValueOnce(true); globalVariableBuilder.buildGlobalVariables.mockResolvedValueOnce( - new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO), + new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO, coinbase, feeRecipient), ); // We make the chain id on the invalid tx not equal to the configured chain id @@ -177,7 +187,7 @@ describe('sequencer', () => { const expectedTxHashes = await Tx.getHashes([txs[0], txs[2]]); expect(blockBuilder.buildL2Block).toHaveBeenCalledWith( - new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO), + new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO, coinbase, feeRecipient), expectedTxHashes.map(hash => expect.objectContaining({ hash })), Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(new Fr(0n)), ); @@ -195,7 +205,7 @@ describe('sequencer', () => { blockBuilder.buildL2Block.mockResolvedValueOnce([block, proof]); publisher.processL2Block.mockResolvedValueOnce(true); globalVariableBuilder.buildGlobalVariables.mockResolvedValueOnce( - new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO), + new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO, coinbase, feeRecipient), ); await sequencer.initialSync(); @@ -230,7 +240,7 @@ describe('sequencer', () => { publisher.processL2Block.mockResolvedValueOnce(true); publisher.processNewContractData.mockResolvedValueOnce(true); globalVariableBuilder.buildGlobalVariables.mockResolvedValueOnce( - new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO), + new GlobalVariables(chainId, version, new Fr(lastBlockNumber + 1), Fr.ZERO, coinbase, feeRecipient), ); await sequencer.initialSync(); diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index ca31b58d3b59..e81515b50392 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -1,6 +1,6 @@ import { L1ToL2MessageSource, L2Block, L2BlockSource, MerkleTreeId, Tx } from '@aztec/circuit-types'; import { L2BlockBuiltStats } from '@aztec/circuit-types/stats'; -import { GlobalVariables } from '@aztec/circuits.js'; +import { AztecAddress, EthAddress, GlobalVariables } from '@aztec/circuits.js'; import { times } from '@aztec/foundation/collection'; import { Fr } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; @@ -155,7 +155,14 @@ export class Sequencer { } }; - const newGlobalVariables = await this.globalsBuilder.buildGlobalVariables(new Fr(newBlockNumber)); + // TODO(benesjan): populate these values from config. + const coinbase = EthAddress.ZERO; + const feeRecipient = AztecAddress.ZERO; + const newGlobalVariables = await this.globalsBuilder.buildGlobalVariables( + new Fr(newBlockNumber), + coinbase, + feeRecipient, + ); // Filter out invalid txs // TODO: It should be responsibility of the P2P layer to validate txs before passing them on here