From c0cd7546a084f988ce81411fda27b9f0de6c2075 Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Fri, 7 Jun 2024 10:27:13 +0000 Subject: [PATCH] chore(avm): enable tag checking and some proving tests --- noir-projects/noir-contracts/Nargo.toml | 2 - .../avm_acvm_interop_test_contract/Nargo.toml | 9 - .../src/main.nr | 77 -------- .../avm_nested_calls_test_contract/Nargo.toml | 8 - .../src/main.nr | 81 -------- .../contracts/avm_test_contract/src/main.nr | 55 +++++- .../bb-prover/src/avm_proving.test.ts | 179 ++++++------------ .../simulator/src/avm/avm_memory_types.ts | 4 +- .../simulator/src/avm/avm_simulator.test.ts | 59 +++--- .../simulator/src/avm/fixtures/index.ts | 11 +- .../src/avm/opcodes/accrued_substate.ts | 3 +- .../src/avm/opcodes/external_calls.ts | 3 +- .../simulator/src/avm/opcodes/hashing.ts | 9 +- 13 files changed, 146 insertions(+), 354 deletions(-) delete mode 100644 noir-projects/noir-contracts/contracts/avm_acvm_interop_test_contract/Nargo.toml delete mode 100644 noir-projects/noir-contracts/contracts/avm_acvm_interop_test_contract/src/main.nr delete mode 100644 noir-projects/noir-contracts/contracts/avm_nested_calls_test_contract/Nargo.toml delete mode 100644 noir-projects/noir-contracts/contracts/avm_nested_calls_test_contract/src/main.nr diff --git a/noir-projects/noir-contracts/Nargo.toml b/noir-projects/noir-contracts/Nargo.toml index 141e5925a00f..e8c4347f8555 100644 --- a/noir-projects/noir-contracts/Nargo.toml +++ b/noir-projects/noir-contracts/Nargo.toml @@ -4,8 +4,6 @@ members = [ "contracts/auth_contract", "contracts/avm_initializer_test_contract", "contracts/avm_test_contract", - "contracts/avm_nested_calls_test_contract", - "contracts/avm_acvm_interop_test_contract", "contracts/fpc_contract", "contracts/benchmarking_contract", "contracts/card_game_contract", diff --git a/noir-projects/noir-contracts/contracts/avm_acvm_interop_test_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/avm_acvm_interop_test_contract/Nargo.toml deleted file mode 100644 index 87e26e0aaa25..000000000000 --- a/noir-projects/noir-contracts/contracts/avm_acvm_interop_test_contract/Nargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "avm_acvm_interop_test_contract" -authors = [""] -compiler_version = ">=0.25.0" -type = "contract" - -[dependencies] -aztec = { path = "../../../aztec-nr/aztec" } -authwit = { path = "../../../aztec-nr/authwit" } diff --git a/noir-projects/noir-contracts/contracts/avm_acvm_interop_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/avm_acvm_interop_test_contract/src/main.nr deleted file mode 100644 index b9e6d4589543..000000000000 --- a/noir-projects/noir-contracts/contracts/avm_acvm_interop_test_contract/src/main.nr +++ /dev/null @@ -1,77 +0,0 @@ -use dep::aztec::protocol_types::traits::{Serialize, Deserialize}; - -contract AvmAcvmInteropTest { - // Libs - use dep::aztec::protocol_types::address::AztecAddress; - use dep::aztec::context::gas::GasOpts; - use dep::aztec::context::public_context::FunctionReturns; - use dep::aztec::protocol_types::abis::function_selector::FunctionSelector; - use dep::authwit::{auth::{assert_current_call_valid_authwit, assert_current_call_valid_authwit_public}}; - - // Use the standard context interface to emit a new nullifier - #[aztec(public)] - fn new_nullifier(nullifier: Field) { - context.push_new_nullifier(nullifier, 0); - } - - /************************************************************************ - * ACVM interoperability - ************************************************************************/ - #[aztec(public)] - fn constant_field_acvm() -> pub Field { - 123456 - } - - #[aztec(public)] - fn constant_field_avm() -> pub Field { - 123456 - } - - #[aztec(public)] - fn new_nullifier_acvm(nullifier: Field) { - context.push_new_nullifier(nullifier, 0); - } - - #[aztec(public)] - fn assert_unsiloed_nullifier_acvm(unsiloed_nullifier: Field) { - assert(context.nullifier_exists(unsiloed_nullifier, context.this_address())); - } - - #[aztec(public)] - fn call_acvm_from_avm() -> pub Field { - context.call_public_function( - context.this_address(), - FunctionSelector::from_signature("constant_field_acvm()"), - [].as_slice(), - GasOpts::default() - ).deserialize_into() - } - - #[aztec(public)] - fn call_avm_from_acvm() -> pub Field { - context.call_public_function( - context.this_address(), - FunctionSelector::from_signature("constant_field_avm()"), - [].as_slice(), - GasOpts::default() - ).deserialize_into() - } - - #[aztec(public)] - fn avm_to_acvm_call(selector: FunctionSelector, args: Field) { - context.call_public_function( - context.this_address(), - selector, - [args].as_slice(), - GasOpts::default() - ).assert_empty(); - } - - /************************************************************************ - * Authwit functions - ************************************************************************/ - #[aztec(public)] - fn test_authwit_send_money(from: AztecAddress, _to: AztecAddress, _amount: Field) { - assert_current_call_valid_authwit_public(&mut context, from); - } -} diff --git a/noir-projects/noir-contracts/contracts/avm_nested_calls_test_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/avm_nested_calls_test_contract/Nargo.toml deleted file mode 100644 index ff0d26a2ce9d..000000000000 --- a/noir-projects/noir-contracts/contracts/avm_nested_calls_test_contract/Nargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "avm_nested_calls_test_contract" -authors = [""] -compiler_version = ">=0.25.0" -type = "contract" - -[dependencies] -aztec = { path = "../../../aztec-nr/aztec" } diff --git a/noir-projects/noir-contracts/contracts/avm_nested_calls_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/avm_nested_calls_test_contract/src/main.nr deleted file mode 100644 index 1b19286079fc..000000000000 --- a/noir-projects/noir-contracts/contracts/avm_nested_calls_test_contract/src/main.nr +++ /dev/null @@ -1,81 +0,0 @@ -use dep::aztec::protocol_types::traits::{Serialize, Deserialize}; - -contract AvmNestedCallsTest { - // Libs - use dep::aztec::state_vars::PublicMutable; - use dep::aztec::protocol_types::address::AztecAddress; - use dep::aztec::context::gas::GasOpts; - use dep::aztec::context::public_context::FunctionReturns; - use dep::aztec::protocol_types::abis::function_selector::FunctionSelector; - - #[aztec(storage)] - struct Storage { - single: PublicMutable, - } - - /************************************************************************ - * Storage - ************************************************************************/ - #[aztec(public)] - fn set_storage_single(a: Field) { - storage.single.write(a); - } - - #[aztec(public)] - fn add_args_return(arg_a: Field, arg_b: Field) -> pub Field { - arg_a + arg_b - } - - #[aztec(public)] - fn assert_same(arg_a: Field, arg_b: Field) -> pub Field { - assert(arg_a == arg_b, "Values are not equal"); - 1 - } - - // Use the standard context interface to emit a new nullifier - #[aztec(public)] - fn new_nullifier(nullifier: Field) { - context.push_new_nullifier(nullifier, 0); - } - - // External call opcode to initiate a nested call to the add function with user-specified gas - #[aztec(public)] - fn nested_call_to_add_with_gas( - arg_a: Field, - arg_b: Field, - l2_gas: Field, - da_gas: Field - ) -> pub Field { - AvmNestedCallsTest::at(context.this_address()).add_args_return(arg_a, arg_b).with_gas(GasOpts::new(l2_gas, da_gas)).call(&mut context) - } - - // Use the `call_public_function` wrapper to initiate a nested call to the add function - #[aztec(public)] - fn nested_call_to_add(arg_a: Field, arg_b: Field) -> pub Field { - AvmNestedCallsTest::at(context.this_address()).add_args_return(arg_a, arg_b).call(&mut context) - } - - // Indirectly call_static the external call opcode to initiate a nested call to the add function - #[aztec(public)] - fn nested_static_call_to_add(arg_a: Field, arg_b: Field) -> pub Field { - AvmNestedCallsTest::at(context.this_address()).add_args_return(arg_a, arg_b).view(&mut context) - } - - // Indirectly call_static `set_storage_single`. Should revert since it's accessing storage. - #[aztec(public)] - fn nested_static_call_to_set_storage() { - AvmNestedCallsTest::at(context.this_address()).set_storage_single(20).view(&mut context); - } - - #[aztec(public)] - fn create_same_nullifier_in_nested_call(nestedAddress: AztecAddress, nullifier: Field) { - context.push_new_nullifier(nullifier, 0); - AvmNestedCallsTest::at(nestedAddress).new_nullifier(nullifier).call(&mut context); - } - - #[aztec(public)] - fn create_different_nullifier_in_nested_call(nestedAddress: AztecAddress, nullifier: Field) { - context.push_new_nullifier(nullifier, 0); - AvmNestedCallsTest::at(nestedAddress).new_nullifier(nullifier + 1).call(&mut context); - } -} diff --git a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr index c3d31d3e5079..9b1f7d757551 100644 --- a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr @@ -30,6 +30,7 @@ contract AvmTest { use dep::aztec::protocol_types::{address::{AztecAddress, EthAddress}, constants::L1_TO_L2_MESSAGE_LENGTH}; use dep::aztec::oracle::get_contract_instance::{get_contract_instance_avm, get_contract_instance_internal_avm}; use dep::aztec::protocol_types::abis::function_selector::FunctionSelector; + use dep::aztec::context::gas::GasOpts; use dep::compressed_string::CompressedString; #[aztec(storage)] @@ -178,6 +179,12 @@ contract AvmTest { dep::aztec::oracle::debug_log::debug_log("tabs and newlines\n\t- first\n\t- second"); } + #[aztec(public)] + fn assert_same(arg_a: Field, arg_b: Field) -> pub Field { + assert(arg_a == arg_b, "Values are not equal"); + 1 + } + /************************************************************************ * Hashing functions ************************************************************************/ @@ -291,11 +298,6 @@ contract AvmTest { context.da_gas_left() } - // #[aztec(public)] - // fn get_contract_call_depth() -> Field { - // context.contract_call_depth() - // } - #[aztec(public)] fn check_selector() { assert( @@ -370,6 +372,49 @@ contract AvmTest { context.message_portal(recipient, content) } + /************************************************************************ + * Nested calls + ************************************************************************/ + #[aztec(public)] + fn nested_call_to_add_with_gas( + arg_a: Field, + arg_b: Field, + l2_gas: Field, + da_gas: Field + ) -> pub Field { + AvmTest::at(context.this_address()).add_args_return(arg_a, arg_b).with_gas(GasOpts::new(l2_gas, da_gas)).call(&mut context) + } + + // Use the `call_public_function` wrapper to initiate a nested call to the add function + #[aztec(public)] + fn nested_call_to_add(arg_a: Field, arg_b: Field) -> pub Field { + AvmTest::at(context.this_address()).add_args_return(arg_a, arg_b).call(&mut context) + } + + // Indirectly call_static the external call opcode to initiate a nested call to the add function + #[aztec(public)] + fn nested_static_call_to_add(arg_a: Field, arg_b: Field) -> pub Field { + AvmTest::at(context.this_address()).add_args_return(arg_a, arg_b).view(&mut context) + } + + // Indirectly call_static `set_storage_single`. Should revert since it's accessing storage. + #[aztec(public)] + fn nested_static_call_to_set_storage() { + AvmTest::at(context.this_address()).set_storage_single(20).view(&mut context); + } + + #[aztec(public)] + fn create_same_nullifier_in_nested_call(nestedAddress: AztecAddress, nullifier: Field) { + context.push_new_nullifier(nullifier, 0); + AvmTest::at(nestedAddress).new_nullifier(nullifier).call(&mut context); + } + + #[aztec(public)] + fn create_different_nullifier_in_nested_call(nestedAddress: AztecAddress, nullifier: Field) { + context.push_new_nullifier(nullifier, 0); + AvmTest::at(nestedAddress).new_nullifier(nullifier + 1).call(&mut context); + } + /** * Enqueue a public call from private */ diff --git a/yarn-project/bb-prover/src/avm_proving.test.ts b/yarn-project/bb-prover/src/avm_proving.test.ts index f48594f354f7..4645f8695ac4 100644 --- a/yarn-project/bb-prover/src/avm_proving.test.ts +++ b/yarn-project/bb-prover/src/avm_proving.test.ts @@ -54,139 +54,78 @@ import { extractVkData } from './verification_key/verification_key_data.js'; const TIMEOUT = 30_000; describe('AVM WitGen, proof generation and verification', () => { - it( - 'Should prove valid execution contract function that performs addition', - async () => { - await proveAndVerifyAvmTestContract('add_args_return', [new Fr(1), new Fr(2)]); - }, - TIMEOUT, - ); - - it( - 'Should prove kernel get environment opcode', - async () => { - await proveAndVerifyAvmTestContract('get_address'); - }, - TIMEOUT, - ); - - it( - 'Should prove with note hash exists with hints', - async () => { - await proveAndVerifyAvmTestContract('note_hash_exists', [new Fr(1), new Fr(2)]); - }, - TIMEOUT, - ); - - it( - 'Should prove get contract instance opcode with hints', - async () => { - await proveAndVerifyAvmTestContract('test_get_contract_instance'); - }, - TIMEOUT, - ); - - it( - 'Should prove new note hash', - async () => { - await proveAndVerifyAvmTestContract('new_note_hash', [new Fr(1)]); - }, - TIMEOUT, - ); - - it( - 'Should prove new note hash', - async () => { - await proveAndVerifyAvmTestContract('new_note_hash', [new Fr(1)]); - }, - TIMEOUT, - ); - - it( - 'Should prove new nullifier', - async () => { - await proveAndVerifyAvmTestContract('new_nullifier', [new Fr(1)]); - }, - TIMEOUT, - ); - - it( - 'Should prove nullifier exists', - async () => { - await proveAndVerifyAvmTestContract('nullifier_exists', [new Fr(1)]); + const avmFunctionsAndCalldata: [string, Fr[]][] = [ + ['add_args_return', [new Fr(1), new Fr(2)]], + ['get_address', []], + ['note_hash_exists', [new Fr(1), new Fr(2)]], + ['test_get_contract_instance', []], + ['new_note_hash', [new Fr(1)]], + ['new_nullifier', [new Fr(1)]], + ['nullifier_exists', [new Fr(1)]], + ['l1_to_l2_msg_exists', [new Fr(1), new Fr(2)]], + ['send_l2_to_l1_msg', [new Fr(1), new Fr(2)]], + ['to_radix_le', [new Fr(10)]], + ]; + + it.each(avmFunctionsAndCalldata)( + 'Should prove %s', + async (name, calldata) => { + await proveAndVerifyAvmTestContract(name, calldata); }, TIMEOUT, ); - it( - 'Should prove l1 to l2 msg exists', + it.skip( + 'Should prove a keccak hash evaluation', async () => { - await proveAndVerifyAvmTestContract('l1_to_l2_msg_exists', [new Fr(1), new Fr(2)]); + await proveAndVerifyAvmTestContract('keccak_hash', [ + new Fr(0), + new Fr(1), + new Fr(2), + new Fr(3), + new Fr(4), + new Fr(5), + new Fr(6), + new Fr(7), + new Fr(8), + new Fr(9), + ]); }, TIMEOUT, ); - it( - 'Should prove send l2 to l1 msg', - async () => { - await proveAndVerifyAvmTestContract('send_l2_to_l1_msg', [new Fr(1), new Fr(2)]); - }, - TIMEOUT, - ); - - // TODO: requires revert - // it("Should prove to radix", - // async () => { - // await proveAndVerifyAvmTestContract('to_radix_le', [new Fr(10)]); - // }, - // TIMEOUT - // ) + /************************************************************************ + * AvmContext functions + ************************************************************************/ + describe('AVM Context functions', () => { + const avmContextFunctions = [ + 'get_address', + 'get_storage_address', + 'get_sender', + 'get_fee_per_l2_gas', + 'get_fee_per_da_gas', + 'get_transaction_fee', + 'get_chain_id', + 'get_version', + 'get_block_number', + 'get_timestamp', + 'get_l2_gas_left', + 'get_da_gas_left', + ]; + + it.each(avmContextFunctions)( + 'Should prove %s', + async contextFunction => { + await proveAndVerifyAvmTestContract(contextFunction); + }, + TIMEOUT, + ); + }); }); -it.skip( - 'Should prove a keccak hash evaluation', - async () => { - await proveAndVerifyAvmTestContract('keccak_hash', [ - new Fr(0), - new Fr(1), - new Fr(2), - new Fr(3), - new Fr(4), - new Fr(5), - new Fr(6), - new Fr(7), - new Fr(8), - new Fr(9), - ]); - }, - TIMEOUT, -); - /************************************************************************ - * AvmContext functions + * Helpers ************************************************************************/ -const avmContextFunctions = [ - 'get_address', - 'get_storage_address', - 'get_sender', - 'get_fee_per_l2_gas', - 'get_fee_per_da_gas', - 'get_transaction_fee', - 'get_chain_id', - 'get_version', - 'get_block_number', - 'get_timestamp', - 'get_l2_gas_left', - 'get_da_gas_left', -]; - -it.each(avmContextFunctions)( - 'Should prove an avm context function %s', - async contextFunction => { - await proveAndVerifyAvmTestContract(contextFunction); - }, - TIMEOUT, -); const proveAndVerifyAvmTestContract = async (functionName: string, calldata: Fr[] = []) => { const startSideEffectCounter = 0; diff --git a/yarn-project/simulator/src/avm/avm_memory_types.ts b/yarn-project/simulator/src/avm/avm_memory_types.ts index 9509b0297bb9..59eb9a985531 100644 --- a/yarn-project/simulator/src/avm/avm_memory_types.ts +++ b/yarn-project/simulator/src/avm/avm_memory_types.ts @@ -298,9 +298,7 @@ export class TaggedMemory implements TaggedMemoryInterface { } public checkIsValidMemoryOffsetTag(offset: number) { - if (this.getTag(offset) > TypeTag.UINT64) { - throw TagCheckError.forOffset(offset, TypeTag[this.getTag(offset)], 'UINT64'); - } + this.checkTag(TypeTag.UINT32, offset); } public static checkIsIntegralTag(tag: TypeTag) { diff --git a/yarn-project/simulator/src/avm/avm_simulator.test.ts b/yarn-project/simulator/src/avm/avm_simulator.test.ts index d9c20f34210a..f1db42498b03 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.test.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.test.ts @@ -14,7 +14,6 @@ import { type MemoryValue, TypeTag, type Uint8 } from './avm_memory_types.js'; import { AvmSimulator } from './avm_simulator.js'; import { adjustCalldataIndex, - getAvmNestedCallsTestContractBytecode, getAvmTestContractBytecode, initContext, initExecutionEnvironment, @@ -126,9 +125,9 @@ describe('AVM simulator: transpiled Noir contracts', () => { const bytecode = getAvmTestContractBytecode('u128_from_integer_overflow'); const results = await new AvmSimulator(initContext()).executeBytecode(bytecode); expect(results.reverted).toBe(true); - expect(results.revertReason?.message).toEqual('Assertion failed.'); - // Note: compiler intrinsic messages (like below) are not known to the AVM - //expect(results.revertReason?.message).toEqual("Assertion failed: call to assert_max_bit_size 'self.__assert_max_bit_size(bit_size)'"); + expect(results.revertReason?.message).toMatch('Assertion failed.'); + // Note: compiler intrinsic messages (like below) are not known to the AVM, they are recovered by the PXE. + // "Assertion failed: call to assert_max_bit_size 'self.__assert_max_bit_size(bit_size)'" }); }); @@ -821,28 +820,30 @@ describe('AVM simulator: transpiled Noir contracts', () => { describe('Nested external calls', () => { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/5625): gas not plumbed through correctly in nested calls. - // it(`Nested call with not enough gas`, async () => { - // const gas = [/*l1=*/ 10000, /*l2=*/ 20, /*da=*/ 10000].map(g => new Fr(g)); - // const calldata: Fr[] = [new Fr(1), new Fr(2), ...gas]; - // const callBytecode = getAvmNestedCallsTestContractBytecode('nested_call_to_add_with_gas'); - // const addBytecode = getAvmNestedCallsTestContractBytecode('add_args_return'); - // const context = initContext({ env: initExecutionEnvironment({ calldata }) }); - // jest - // .spyOn(context.persistableState.hostStorage.contractsDb, 'getBytecode') - // .mockReturnValue(Promise.resolve(addBytecode)); - - // const results = await new AvmSimulator(context).executeBytecode(callBytecode); - - // // Outer frame should not revert, but inner should, so the forwarded return value is 0 - // expect(results.revertReason).toBeUndefined(); - // expect(results.reverted).toBe(false); - // expect(results.output).toEqual([new Fr(0)]); - // }); + it(`Nested call with not enough gas`, async () => { + const gas = [/*l2=*/ 5, /*da=*/ 10000].map(g => new Fr(g)); + const calldata: Fr[] = [new Fr(1), new Fr(2), ...gas]; + const callBytecode = getAvmTestContractBytecode('nested_call_to_add_with_gas'); + const addBytecode = getAvmTestContractBytecode('add_args_return'); + const context = initContext({ env: initExecutionEnvironment({ calldata }) }); + jest + .spyOn(context.persistableState.hostStorage.contractsDb, 'getBytecode') + .mockReturnValue(Promise.resolve(addBytecode)); + + const results = await new AvmSimulator(context).executeBytecode(callBytecode); + + // TODO: change this once we don't force rethrowing of exceptions. + // Outer frame should not revert, but inner should, so the forwarded return value is 0 + // expect(results.revertReason).toBeUndefined(); + // expect(results.reverted).toBe(false); + expect(results.reverted).toBe(true); + expect(results.revertReason?.message).toEqual('Not enough L2GAS gas left'); + }); it(`Nested call`, async () => { const calldata: Fr[] = [new Fr(1), new Fr(2)]; - const callBytecode = getAvmNestedCallsTestContractBytecode('nested_call_to_add'); - const addBytecode = getAvmNestedCallsTestContractBytecode('add_args_return'); + const callBytecode = getAvmTestContractBytecode('nested_call_to_add'); + const addBytecode = getAvmTestContractBytecode('add_args_return'); const context = initContext({ env: initExecutionEnvironment({ calldata }) }); jest .spyOn(context.persistableState.hostStorage.contractsDb, 'getBytecode') @@ -856,8 +857,8 @@ describe('AVM simulator: transpiled Noir contracts', () => { it(`Nested static call`, async () => { const calldata: Fr[] = [new Fr(1), new Fr(2)]; - const callBytecode = getAvmNestedCallsTestContractBytecode('nested_static_call_to_add'); - const addBytecode = getAvmNestedCallsTestContractBytecode('add_args_return'); + const callBytecode = getAvmTestContractBytecode('nested_static_call_to_add'); + const addBytecode = getAvmTestContractBytecode('add_args_return'); const context = initContext({ env: initExecutionEnvironment({ calldata }) }); jest .spyOn(context.persistableState.hostStorage.contractsDb, 'getBytecode') @@ -870,8 +871,8 @@ describe('AVM simulator: transpiled Noir contracts', () => { }); it(`Nested static call which modifies storage`, async () => { - const callBytecode = getAvmNestedCallsTestContractBytecode('nested_static_call_to_set_storage'); - const nestedBytecode = getAvmNestedCallsTestContractBytecode('set_storage_single'); + const callBytecode = getAvmTestContractBytecode('nested_static_call_to_set_storage'); + const nestedBytecode = getAvmTestContractBytecode('set_storage_single'); const context = initContext(); jest .spyOn(context.persistableState.hostStorage.contractsDb, 'getBytecode') @@ -887,9 +888,9 @@ describe('AVM simulator: transpiled Noir contracts', () => { it(`Nested calls rethrow exceptions`, async () => { const calldata: Fr[] = [new Fr(1), new Fr(2)]; - const callBytecode = getAvmNestedCallsTestContractBytecode('nested_call_to_add'); + const callBytecode = getAvmTestContractBytecode('nested_call_to_add'); // We actually don't pass the function ADD, but it's ok because the signature is the same. - const nestedBytecode = getAvmNestedCallsTestContractBytecode('assert_same'); + const nestedBytecode = getAvmTestContractBytecode('assert_same'); const context = initContext({ env: initExecutionEnvironment({ calldata }) }); jest .spyOn(context.persistableState.hostStorage.contractsDb, 'getBytecode') diff --git a/yarn-project/simulator/src/avm/fixtures/index.ts b/yarn-project/simulator/src/avm/fixtures/index.ts index fae76eceb2c3..b96be7f003c3 100644 --- a/yarn-project/simulator/src/avm/fixtures/index.ts +++ b/yarn-project/simulator/src/avm/fixtures/index.ts @@ -3,7 +3,7 @@ import { FunctionSelector } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; -import { AvmNestedCallsTestContractArtifact, AvmTestContractArtifact } from '@aztec/noir-contracts.js'; +import { AvmTestContractArtifact } from '@aztec/noir-contracts.js'; import { SerializableContractInstance } from '@aztec/types/contracts'; import { strict as assert } from 'assert'; @@ -139,15 +139,6 @@ export function getAvmTestContractBytecode(functionName: string): Buffer { return artifact.bytecode; } -export function getAvmNestedCallsTestContractBytecode(functionName: string): Buffer { - const artifact = AvmNestedCallsTestContractArtifact.functions.find(f => f.name === functionName)!; - assert( - !!artifact?.bytecode, - `No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`, - ); - return artifact.bytecode; -} - export function randomTracedContractInstance(): TracedContractInstance { const instance = SerializableContractInstance.random(); const address = AztecAddress.random(); diff --git a/yarn-project/simulator/src/avm/opcodes/accrued_substate.ts b/yarn-project/simulator/src/avm/opcodes/accrued_substate.ts index 76cdbe236a24..c227710208fd 100644 --- a/yarn-project/simulator/src/avm/opcodes/accrued_substate.ts +++ b/yarn-project/simulator/src/avm/opcodes/accrued_substate.ts @@ -242,8 +242,7 @@ export class EmitUnencryptedLog extends Instruction { memory, ); memory.checkTag(TypeTag.FIELD, eventSelectorOffset); - // TODO: enable once Noir generates UINT32 - // memory.checkTag(TypeTag.UINT32, logSize); + memory.checkTag(TypeTag.UINT32, logSizeOffset); const logSize = memory.get(logSizeOffset).toNumber(); memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize); diff --git a/yarn-project/simulator/src/avm/opcodes/external_calls.ts b/yarn-project/simulator/src/avm/opcodes/external_calls.ts index 75c71f61d7bc..9ccc88d362ee 100644 --- a/yarn-project/simulator/src/avm/opcodes/external_calls.ts +++ b/yarn-project/simulator/src/avm/opcodes/external_calls.ts @@ -55,8 +55,7 @@ abstract class ExternalCall extends Instruction { ); memory.checkTags(TypeTag.FIELD, gasOffset, gasOffset + 1); memory.checkTag(TypeTag.FIELD, addrOffset); - // TODO: Enable when Noir uses UINT32 - // memory.checkTag(TypeTag.UINT32, argsSizeOffset); + memory.checkTag(TypeTag.UINT32, argsSizeOffset); memory.checkTag(TypeTag.FIELD, this.functionSelectorOffset); const calldataSize = memory.get(argsSizeOffset).toNumber(); diff --git a/yarn-project/simulator/src/avm/opcodes/hashing.ts b/yarn-project/simulator/src/avm/opcodes/hashing.ts index 2c586d1227bc..d181c48e608e 100644 --- a/yarn-project/simulator/src/avm/opcodes/hashing.ts +++ b/yarn-project/simulator/src/avm/opcodes/hashing.ts @@ -75,8 +75,7 @@ export class Keccak extends Instruction { [this.dstOffset, this.messageOffset, this.messageSizeOffset], memory, ); - // TODO: Enable when Noir uses UINT32 - // memory.checkTag(TypeTag.UINT32, messageSizeOffset); + memory.checkTag(TypeTag.UINT32, messageSizeOffset); const messageSize = memory.get(messageSizeOffset).toNumber(); const memoryOperations = { reads: messageSize + 1, writes: 32, indirect: this.indirect }; context.machineState.consumeGas(this.gasCost(memoryOperations)); @@ -124,8 +123,7 @@ export class Sha256 extends Instruction { [this.dstOffset, this.messageOffset, this.messageSizeOffset], memory, ); - // TODO: Enable when Noir uses UINT32 - // memory.checkTag(TypeTag.UINT32, messageSizeOffset); + memory.checkTag(TypeTag.UINT32, messageSizeOffset); const messageSize = memory.get(messageSizeOffset).toNumber(); const memoryOperations = { reads: messageSize + 1, writes: 32, indirect: this.indirect }; context.machineState.consumeGas(this.gasCost(memoryOperations)); @@ -178,8 +176,7 @@ export class Pedersen extends Instruction { const genIndex = Number(memory.get(genIndexOffset).toBigInt()); memory.checkTag(TypeTag.UINT32, genIndexOffset); const messageSize = Number(memory.get(messageSizeOffset).toBigInt()); - // TODO: Enable when Noir uses UINT32 - // memory.checkTag(TypeTag.UINT32, messageSizeOffset); + memory.checkTag(TypeTag.UINT32, messageSizeOffset); const hashData = memory.getSlice(messageOffset, messageSize); const memoryOperations = { reads: messageSize + 2, writes: 1, indirect: this.indirect };