From 76907195da0241e012d652989674ccba1f190d7d Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Thu, 12 Oct 2023 08:15:35 +0100 Subject: [PATCH] refactor: assert admin is non-zero in token contract --- .../end-to-end/src/cli_docs_sandbox.test.ts | 1 - .../end-to-end/src/e2e_deploy_contract.test.ts | 6 +++--- yarn-project/noir-contracts/Nargo.toml | 7 +++---- .../src/contracts/test_assert_contract/Nargo.toml | 8 -------- .../contracts/test_assert_contract/src/main.nr | 15 --------------- .../src/contracts/token_contract/src/main.nr | 5 +++-- 6 files changed, 9 insertions(+), 33 deletions(-) delete mode 100644 yarn-project/noir-contracts/src/contracts/test_assert_contract/Nargo.toml delete mode 100644 yarn-project/noir-contracts/src/contracts/test_assert_contract/src/main.nr diff --git a/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts b/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts index 8720fc3c568..1b95d120272 100644 --- a/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts +++ b/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts @@ -116,7 +116,6 @@ SchnorrAccountContractArtifact SchnorrHardcodedAccountContractArtifact SchnorrSingleKeyAccountContractArtifact StatefulTestContractArtifact -TestAssertContractArtifact TestContractArtifact TokenBridgeContractArtifact TokenContractArtifact diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts index cb9df33dcde..64878799d9d 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts @@ -1,7 +1,7 @@ import { AztecAddress, Contract, ContractDeployer, EthAddress, Fr, Wallet, isContractDeployed } from '@aztec/aztec.js'; import { CompleteAddress, getContractDeploymentInfo } from '@aztec/circuits.js'; import { DebugLogger } from '@aztec/foundation/log'; -import { TestAssertContractArtifact, TestContractArtifact } from '@aztec/noir-contracts/artifacts'; +import { TestContractArtifact, TokenContractArtifact } from '@aztec/noir-contracts/artifacts'; import { PXE, TxStatus } from '@aztec/types'; import { setup } from './fixtures/utils.js'; @@ -132,8 +132,8 @@ describe('e2e_deploy_contract', () => { it('it should not deploy a contract which failed the public part of the execution', async () => { // This test requires at least another good transaction to go through in the same block as the bad one. // I deployed the same contract again but it could really be any valid transaction here. - const goodDeploy = new ContractDeployer(TestAssertContractArtifact, wallet).deploy(0); - const badDeploy = new ContractDeployer(TestAssertContractArtifact, wallet).deploy(1); + const goodDeploy = new ContractDeployer(TokenContractArtifact, wallet).deploy(AztecAddress.random()); + const badDeploy = new ContractDeployer(TokenContractArtifact, wallet).deploy(AztecAddress.ZERO); await Promise.all([ goodDeploy.simulate({ skipPublicSimulation: true }), diff --git a/yarn-project/noir-contracts/Nargo.toml b/yarn-project/noir-contracts/Nargo.toml index bca8b6340bb..0c9dcf0bbcc 100644 --- a/yarn-project/noir-contracts/Nargo.toml +++ b/yarn-project/noir-contracts/Nargo.toml @@ -1,8 +1,8 @@ [workspace] members = [ - "src/contracts/benchmarking_contract", - "src/contracts/card_game_contract", - "src/contracts/child_contract", + "src/contracts/benchmarking_contract", + "src/contracts/card_game_contract", + "src/contracts/child_contract", "src/contracts/docs_example_contract", "src/contracts/easy_private_token_contract", "src/contracts/ecdsa_account_contract", @@ -23,7 +23,6 @@ members = [ "src/contracts/schnorr_single_key_account_contract", "src/contracts/stateful_test_contract", "src/contracts/test_contract", - "src/contracts/test_assert_contract", "src/contracts/token_contract", "src/contracts/token_bridge_contract", "src/contracts/uniswap_contract", diff --git a/yarn-project/noir-contracts/src/contracts/test_assert_contract/Nargo.toml b/yarn-project/noir-contracts/src/contracts/test_assert_contract/Nargo.toml deleted file mode 100644 index 3ddb06f75ef..00000000000 --- a/yarn-project/noir-contracts/src/contracts/test_assert_contract/Nargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "test_assert_contract" -authors = [""] -compiler_version = "0.1" -type = "contract" - -[dependencies] -aztec = { path = "../../../../aztec-nr/aztec" } diff --git a/yarn-project/noir-contracts/src/contracts/test_assert_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/test_assert_contract/src/main.nr deleted file mode 100644 index 86a665eca50..00000000000 --- a/yarn-project/noir-contracts/src/contracts/test_assert_contract/src/main.nr +++ /dev/null @@ -1,15 +0,0 @@ -// A contract used in end to end tests -contract TestAssert { - use dep::aztec::selector::compute_selector; - - #[aztec(private)] - fn constructor(value: Field) { - let selector = compute_selector("assert_is_zero(Field)"); - context.call_public_function(context.this_address(), selector, [value]); - } - - #[aztec(public)] - fn assert_is_zero(value: Field) { - assert(0 == value); - } -} diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr index 73e0c9f3360..0c5cfe44fe9 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr @@ -36,8 +36,8 @@ contract Token { // docs:start:import_authwit use dep::authwit::{ auth::{ - assert_current_call_valid_authwit, - assert_current_call_valid_authwit_public, + assert_current_call_valid_authwit, + assert_current_call_valid_authwit_public, }, }; // docs:end:import_authwit @@ -359,6 +359,7 @@ contract Token { internal fn _initialize( new_admin: AztecAddress, ) { + assert(new_admin.address != 0, "invalid admin"); storage.admin.write(new_admin); storage.minters.at(new_admin.address).write(true); }