diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr index f983dbf3836..b8312729da1 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr @@ -87,7 +87,6 @@ contract AppSubscription { #[aztec(public)] #[aztec(internal)] - #[aztec(noinitcheck)] fn init( target_address: AztecAddress, subscription_token_address: AztecAddress, diff --git a/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr b/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr index 60cbf894ef1..76028481588 100644 --- a/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr @@ -28,9 +28,8 @@ contract EasyPrivateVoting { // docs:end:constructor // docs:start:initialize #[aztec(public)] // annotation to mark function as public and expose public context - #[aztec(internal)] // internal - can only be called by contract - #[aztec(noinitcheck)] - fn _initialize(admin: AztecAddress) { + #[aztec(internal)] + fn _initialize(admin: AztecAddress) { // internal - can only be called by contract storage.admin.write(admin); storage.voteEnded.write(false); } diff --git a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr index 7207f0ef308..9ab6846b076 100644 --- a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr @@ -24,7 +24,6 @@ contract FPC { #[aztec(public)] #[aztec(internal)] - #[aztec(noinitcheck)] fn _initialize(other_asset: AztecAddress, fee_asset: AztecAddress) { storage.other_asset.initialize(other_asset); storage.fee_asset.initialize(fee_asset); diff --git a/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr b/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr index b026448a1b0..0deda6433a1 100644 --- a/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr @@ -38,7 +38,6 @@ contract InclusionProofs { #[aztec(public)] #[aztec(internal)] - #[aztec(noinitcheck)] fn _initialize(value: Field) { storage.public_value.write(value); } diff --git a/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr index dddb482211e..242e6f7f016 100644 --- a/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr @@ -70,12 +70,12 @@ contract StatefulTest { #[aztec(public)] fn increment_public_value(owner: AztecAddress, value: Field) { + assert_is_initialized(&mut context); let loc = storage.public_values.at(owner); loc.write(loc.read() + value); } #[aztec(public)] - #[aztec(noinitcheck)] fn increment_public_value_no_init_check(owner: AztecAddress, value: Field) { let loc = storage.public_values.at(owner); loc.write(loc.read() + value); diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr index 1e26124a5bb..fe9bec5f4fe 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr @@ -78,7 +78,6 @@ contract TokenBlacklist { /////// #[aztec(public)] #[aztec(internal)] - #[aztec(noinitcheck)] fn _initialize(new_admin: AztecAddress, slow_updates_contract: AztecAddress) { assert(!new_admin.is_zero(), "invalid admin"); storage.admin.write(new_admin); diff --git a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr index 1870537b2b9..e6d37db870e 100644 --- a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr @@ -139,7 +139,6 @@ contract TokenBridge { #[aztec(public)] #[aztec(internal)] - #[aztec(noinitcheck)] fn _initialize(token: AztecAddress) { storage.token.write(token); } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index ed6ff0dfceb..1321ad290f2 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -314,7 +314,6 @@ contract Token { // docs:start:initialize #[aztec(public)] #[aztec(internal)] - #[aztec(noinitcheck)] fn _initialize( new_admin: AztecAddress, name: FieldCompressedString, diff --git a/noir/noir-repo/aztec_macros/src/lib.rs b/noir/noir-repo/aztec_macros/src/lib.rs index 0c84c00820d..9afedd39245 100644 --- a/noir/noir-repo/aztec_macros/src/lib.rs +++ b/noir/noir-repo/aztec_macros/src/lib.rs @@ -451,6 +451,7 @@ fn transform_module( is_internal = true; } else if is_custom_attribute(&secondary_attribute, "aztec(public)") { is_public = true; + insert_init_check = false; } else if is_custom_attribute(&secondary_attribute, "aztec(public-vm)") { is_public_vm = true; } @@ -672,6 +673,15 @@ fn transform_function( // Add initialization check if insert_init_check { + if ty == "Public" { + let error = AztecMacroError::UnsupportedAttributes { + span: func.def.name.span(), + secondary_message: Some( + "public functions do not yet support initialization check".to_owned(), + ), + }; + return Err(error); + } let init_check = create_init_check(); func.def.body.0.insert(0, init_check); } diff --git a/yarn-project/merkle-tree/src/index.ts b/yarn-project/merkle-tree/src/index.ts index ca08070bc8e..45ae1771bbf 100644 --- a/yarn-project/merkle-tree/src/index.ts +++ b/yarn-project/merkle-tree/src/index.ts @@ -5,7 +5,6 @@ export * from './interfaces/update_only_tree.js'; export * from './pedersen.js'; export * from './sparse_tree/sparse_tree.js'; export { StandardIndexedTree } from './standard_indexed_tree/standard_indexed_tree.js'; -export { StandardIndexedTreeWithAppend } from './standard_indexed_tree/test/standard_indexed_tree_with_append.js'; export * from './standard_tree/standard_tree.js'; export { INITIAL_LEAF, getTreeMeta } from './tree_base.js'; export { newTree } from './new_tree.js'; diff --git a/yarn-project/merkle-tree/src/standard_indexed_tree/test/standard_indexed_tree_with_append.ts b/yarn-project/merkle-tree/src/standard_indexed_tree/test/standard_indexed_tree_with_append.ts index a772f1fc5fb..60ff4a9ecca 100644 --- a/yarn-project/merkle-tree/src/standard_indexed_tree/test/standard_indexed_tree_with_append.ts +++ b/yarn-project/merkle-tree/src/standard_indexed_tree/test/standard_indexed_tree_with_append.ts @@ -1,4 +1,4 @@ -import { StandardIndexedTree } from '../standard_indexed_tree.js'; +import { StandardIndexedTree } from '../../index.js'; /** * A testing utility which is here to store the original implementation of StandardIndexedTree.appendLeaves method diff --git a/yarn-project/simulator/src/public/index.test.ts b/yarn-project/simulator/src/public/index.test.ts index 3c8396547c9..810c0745c01 100644 --- a/yarn-project/simulator/src/public/index.test.ts +++ b/yarn-project/simulator/src/public/index.test.ts @@ -1,4 +1,4 @@ -import { L1ToL2Message, NullifierMembershipWitness, SiblingPath } from '@aztec/circuit-types'; +import { L1ToL2Message, SiblingPath } from '@aztec/circuit-types'; import { AppendOnlyTreeSnapshot, CallContext, @@ -7,19 +7,13 @@ import { Header, L1_TO_L2_MSG_TREE_HEIGHT, L2ToL1Message, - NULLIFIER_TREE_HEIGHT, - NullifierLeaf, - NullifierLeafPreimage, } from '@aztec/circuits.js'; -import { siloNullifier } from '@aztec/circuits.js/hash'; import { makeHeader } from '@aztec/circuits.js/testing'; import { FunctionArtifact, FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { pedersenHash } from '@aztec/foundation/crypto'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; -import { openTmpStore } from '@aztec/kv-store/utils'; -import { Pedersen, StandardIndexedTreeWithAppend } from '@aztec/merkle-tree'; import { ChildContractArtifact } from '@aztec/noir-contracts.js/Child'; import { ParentContractArtifact } from '@aztec/noir-contracts.js/Parent'; import { TestContractArtifact } from '@aztec/noir-contracts.js/Test'; @@ -56,46 +50,16 @@ describe('ACIR public execution simulator', () => { executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); }, 10000); - const mockInitializationNullifierCallback = async (contractAddress: AztecAddress) => { - // We create a nullifier tree just to get the membership witness for the token contract - // initialization nullifier, which is checked by all of the Token contract functions. - const nullifierTree = new StandardIndexedTreeWithAppend( - openTmpStore(), - new Pedersen(), - 'nullifier', - NULLIFIER_TREE_HEIGHT, - 0n, - NullifierLeafPreimage, - NullifierLeaf, - ); - await nullifierTree.init(1); - const initializationNullifier = siloNullifier(contractAddress, contractAddress.toField()); - await nullifierTree.appendLeaves([initializationNullifier.toBuffer()]); - header.state.partial.nullifierTree.root = Fr.fromBuffer(nullifierTree.getRoot(true)); - commitmentsDb.getNullifierMembershipWitnessAtLatestBlock.mockImplementation(async nullifier => { - if (nullifier.equals(initializationNullifier)) { - const index = 1n; - const preimage = nullifierTree.getLatestLeafPreimageCopy(index, true); - const siblingPath = await nullifierTree.getSiblingPath(index, true); - return new NullifierMembershipWitness(index, preimage as NullifierLeafPreimage, siblingPath); - } else { - throw new Error(`Unexpected nullifier witness request for ${nullifier}`); - } - }); - }; - describe('Token contract', () => { let recipient: AztecAddress; - let contractAddress: AztecAddress; - beforeEach(async () => { + beforeEach(() => { recipient = AztecAddress.random(); - contractAddress = AztecAddress.random(); - await mockInitializationNullifierCallback(contractAddress); }); describe('mint', () => { it('should run the mint_public function', async () => { + const contractAddress = AztecAddress.random(); const mintArtifact = TokenContractArtifact.functions.find(f => f.name === 'mint_public')!; const functionData = FunctionData.fromAbi(mintArtifact); @@ -162,6 +126,7 @@ describe('ACIR public execution simulator', () => { }); describe('transfer', () => { + let contractAddress: AztecAddress; let transferArtifact: FunctionArtifact; let functionData: FunctionData; let args: Fr[]; @@ -172,6 +137,7 @@ describe('ACIR public execution simulator', () => { let execution: PublicExecution; beforeEach(() => { + contractAddress = AztecAddress.random(); transferArtifact = TokenContractArtifact.functions.find(f => f.name === 'transfer_public')!; functionData = new FunctionData(FunctionSelector.empty(), false, false, false); sender = AztecAddress.random(); @@ -329,9 +295,8 @@ describe('ACIR public execution simulator', () => { let amount: Fr; let params: Fr[]; - beforeEach(async () => { + beforeEach(() => { contractAddress = AztecAddress.random(); - await mockInitializationNullifierCallback(contractAddress); functionData = new FunctionData(FunctionSelector.empty(), false, false, false); amount = new Fr(1); params = [amount, new Fr(1)];