From 3e9d2b9de53476b28edbdf9dc1cf596b292893d1 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 13 Oct 2023 15:24:57 +0200 Subject: [PATCH] nuked private token --- .circleci/config.yml | 14 --- bootstrap_docker.sh | 2 +- .../src/e2e_private_token_contract.test.ts | 99 ----------------- yarn-project/noir-contracts/Nargo.toml | 1 - .../private_token_contract/Nargo.toml | 12 -- .../private_token_contract/src/interface.nr | 67 ----------- .../private_token_contract/src/main.nr | 105 ------------------ 7 files changed, 1 insertion(+), 299 deletions(-) delete mode 100644 yarn-project/end-to-end/src/e2e_private_token_contract.test.ts delete mode 100644 yarn-project/noir-contracts/src/contracts/private_token_contract/Nargo.toml delete mode 100644 yarn-project/noir-contracts/src/contracts/private_token_contract/src/interface.nr delete mode 100644 yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr diff --git a/.circleci/config.yml b/.circleci/config.yml index bc968b697fbe..ce7335fa2b18 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -631,18 +631,6 @@ jobs: command: cond_run_script end-to-end ./scripts/run_tests_local e2e_private_airdrop.test.ts environment: { DEBUG: "aztec:*" } - e2e-private-token-contract: - machine: - image: ubuntu-2204:2023.07.2 - resource_class: large - steps: - - *checkout - - *setup_env - - run: - name: "Test" - command: cond_run_script end-to-end ./scripts/run_tests_local e2e_private_token_contract.test.ts - environment: { DEBUG: "aztec:*" } - e2e-sandbox-example: machine: image: ubuntu-2204:2023.07.2 @@ -1355,7 +1343,6 @@ workflows: - e2e-lending-contract: *e2e_test - e2e-token-contract: *e2e_test - e2e-private-airdrop: *e2e_test - - e2e-private-token-contract: *e2e_test - e2e-sandbox-example: *e2e_test - e2e-multi-transfer-contract: *e2e_test - e2e-block-building: *e2e_test @@ -1394,7 +1381,6 @@ workflows: - e2e-lending-contract - e2e-token-contract - e2e-private-airdrop - - e2e-private-token-contract - e2e-sandbox-example - e2e-multi-transfer-contract - e2e-block-building diff --git a/bootstrap_docker.sh b/bootstrap_docker.sh index 45dbc3fe70d2..bbc081d0b591 100755 --- a/bootstrap_docker.sh +++ b/bootstrap_docker.sh @@ -36,5 +36,5 @@ build_local $PROJECT_NAME if [ -z "$PROJECT_NAME" ]; then echo echo "Success! You could now run e.g.:" - echo " docker run -ti --rm aztecprotocol/end-to-end:latest e2e_private_token_contract.test" + echo " docker run -ti --rm aztecprotocol/end-to-end:latest e2e_token_contract.test" fi diff --git a/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts deleted file mode 100644 index 1cc13f97e783..000000000000 --- a/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { AztecAddress, Wallet } from '@aztec/aztec.js'; -import { DebugLogger } from '@aztec/foundation/log'; -import { PrivateTokenContract } from '@aztec/noir-contracts/types'; -import { AztecNode, CompleteAddress, TxStatus } from '@aztec/types'; - -import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js'; - -describe('e2e_private_token_contract', () => { - let aztecNode: AztecNode | undefined; - let wallet: Wallet; - let logger: DebugLogger; - let owner: AztecAddress; - let receiver: AztecAddress; - let teardown: () => Promise; - let contract: PrivateTokenContract; - - beforeEach(async () => { - let accounts: CompleteAddress[]; - ({ teardown, aztecNode, accounts, wallet, logger } = await setup(2)); - owner = accounts[0].address; - receiver = accounts[1].address; - }, 100_000); - - afterEach(() => teardown()); - - const expectBalance = async (owner: AztecAddress, expectedBalance: bigint) => { - const balance = await contract.methods.getBalance(owner).view({ from: owner }); - logger(`Account ${owner} balance: ${balance}`); - expect(balance).toBe(expectedBalance); - }; - - const deployContract = async (initialBalance: bigint, owner: AztecAddress) => { - logger(`Deploying L2 contract...`); - contract = await PrivateTokenContract.deploy(wallet, initialBalance, owner).send().deployed(); - logger(`L2 contract deployed at ${contract.address}`); - }; - - /** - * Milestone 1.3. - * https://hackmd.io/AG5rb9DyTRu3y7mBptWauA - */ - it('1.3 should deploy private token contract with initial token minted to the account', async () => { - const initialBalance = 987n; - await deployContract(initialBalance, owner); - await expectBalance(owner, initialBalance); - await expectBalance(receiver, 0n); - - await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1); - }, 30_000); - - /** - * Milestone 1.4. - */ - it('1.4 should call mint and increase balance', async () => { - const mintAmount = 65n; - - await deployContract(0n, owner); - await expectBalance(owner, 0n); - - await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 0); - - const tx = contract.methods.mint(mintAmount, owner).send(); - - await tx.isMined({ interval: 0.1 }); - const receipt = await tx.getReceipt(); - - expect(receipt.status).toBe(TxStatus.MINED); - await expectBalance(owner, mintAmount); - - await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1); - }, 60_000); - - /** - * Milestone 1.5. - */ - it('1.5 should call transfer and increase balance of another account', async () => { - const initialBalance = 987n; - const transferAmount = 654n; - - await deployContract(initialBalance, owner); - - await expectBalance(owner, initialBalance); - await expectBalance(receiver, 0n); - - await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1); - - const tx = contract.methods.transfer(transferAmount, receiver).send(); - - await tx.isMined({ interval: 0.1 }); - const receipt = await tx.getReceipt(); - - expect(receipt.status).toBe(TxStatus.MINED); - - await expectBalance(owner, initialBalance - transferAmount); - await expectBalance(receiver, transferAmount); - - await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2); - }, 60_000); -}); diff --git a/yarn-project/noir-contracts/Nargo.toml b/yarn-project/noir-contracts/Nargo.toml index a1df90d29c21..1097b1ae1183 100644 --- a/yarn-project/noir-contracts/Nargo.toml +++ b/yarn-project/noir-contracts/Nargo.toml @@ -15,7 +15,6 @@ members = [ "src/contracts/pokeable_token_contract", "src/contracts/price_feed_contract", "src/contracts/private_token_airdrop_contract", - "src/contracts/private_token_contract", "src/contracts/public_token_contract", "src/contracts/schnorr_account_contract", "src/contracts/schnorr_hardcoded_account_contract", diff --git a/yarn-project/noir-contracts/src/contracts/private_token_contract/Nargo.toml b/yarn-project/noir-contracts/src/contracts/private_token_contract/Nargo.toml deleted file mode 100644 index f3e29ac1bf52..000000000000 --- a/yarn-project/noir-contracts/src/contracts/private_token_contract/Nargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -# docs:start:importing-aztec -[package] -name = "private_token_contract" -authors = [""] -compiler_version = "0.1" -type = "contract" - -[dependencies] -# highlight-next-line:importing-aztec -aztec = { path = "../../../../aztec-nr/aztec" } -value_note = { path = "../../../../aztec-nr/value-note"} -# docs:end:importing-aztec \ No newline at end of file diff --git a/yarn-project/noir-contracts/src/contracts/private_token_contract/src/interface.nr b/yarn-project/noir-contracts/src/contracts/private_token_contract/src/interface.nr deleted file mode 100644 index 19b526671a3c..000000000000 --- a/yarn-project/noir-contracts/src/contracts/private_token_contract/src/interface.nr +++ /dev/null @@ -1,67 +0,0 @@ -/* Autogenerated file, do not edit! */ - -use dep::std; -use dep::aztec::context::{ PrivateContext, PublicContext }; -use dep::aztec::constants_gen::RETURN_VALUES_LENGTH; - - - -// Interface for calling PrivateToken functions from a private context -struct PrivateTokenPrivateContextInterface { - address: Field, -} - -impl PrivateTokenPrivateContextInterface { - pub fn at(address: Field) -> Self { - Self { - address, - } - } - - pub fn mint( - self, - context: &mut PrivateContext, - amount: Field, - owner: Field - ) -> [Field; RETURN_VALUES_LENGTH] { - let mut serialized_args = [0; 2]; - serialized_args[0] = amount; - serialized_args[1] = owner; - - context.call_private_function(self.address, 0x1535439c, serialized_args) - } - - - pub fn transfer( - self, - context: &mut PrivateContext, - amount: Field, - recipient: Field - ) -> [Field; RETURN_VALUES_LENGTH] { - let mut serialized_args = [0; 2]; - serialized_args[0] = amount; - serialized_args[1] = recipient; - - context.call_private_function(self.address, 0xc0888d22, serialized_args) - } - -} - - - - -// Interface for calling PrivateToken functions from a public context -struct PrivateTokenPublicContextInterface { - address: Field, -} - -impl PrivateTokenPublicContextInterface { - pub fn at(address: Field) -> Self { - Self { - address, - } - } - -} - - diff --git a/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr deleted file mode 100644 index c999ee9939e4..000000000000 --- a/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr +++ /dev/null @@ -1,105 +0,0 @@ -// docs:start:all -contract PrivateToken { - use dep::std::option::Option; - use dep::value_note::{ - balance_utils, - utils::{increment, decrement}, - value_note::{VALUE_NOTE_LEN, ValueNote, ValueNoteMethods}, - }; - use dep::aztec::{ - context::{PrivateContext, PublicContext, Context}, - note::{ - note_header::NoteHeader, - utils as note_utils, - }, - state_vars::{map::Map, set::Set}, - }; - - struct Storage { - // maps an aztec address to its balance - balances: Map>, - } - - impl Storage { - fn init(context: Context) -> pub Self { - Storage { - balances: Map::new( - context, - 1, // Storage slot - |context, slot| { - Set::new(context, slot, ValueNoteMethods) - }, - ), - } - } - } - - // Constructs the contract and sets `initial_supply` which is fully owned by `owner`. - #[aztec(private)] - fn constructor( - initial_supply: Field, - owner: Field - ) { - - // Insert new note to a set of user notes and emit the newly created encrypted note preimage via oracle call. - let owner_balance = storage.balances.at(owner); - if (initial_supply != 0) { - increment(owner_balance, initial_supply, owner); - } - } - - // docs:start:mint - // Mints `amount` of tokens to `owner`. - #[aztec(private)] - fn mint( - amount: Field, - owner: Field - ) { - - - // Insert new note to a set of user notes and emit the newly created encrypted note preimage via oracle call. - let owner_balance = storage.balances.at(owner); - increment(owner_balance, amount, owner); - } - // docs:end:mint - - // Transfers `amount` of tokens from msg_sender to a `recipient`. - #[aztec(private)] - fn transfer( - amount: Field, - recipient: Field, - ) { - - let sender = context.msg_sender(); - - // Pick from the set of sender's notes to spend amount. - let sender_balance = storage.balances.at(sender); - decrement(sender_balance, amount, sender); - - // Creates new note for the recipient. - let recipient_balance = storage.balances.at(recipient); - increment(recipient_balance, amount, recipient); - } - - // Helper function to get the balance of a user ("unconstrained" is a Noir alternative of Solidity's "view" function). - unconstrained fn getBalance( - owner: Field, - ) -> Field { - - - // Get the set of notes owned by the user. - let owner_balance = storage.balances.at(owner); - - // Return the sum of all notes in the set. - balance_utils::get_balance(owner_balance) - } - - // Computes note hash and nullifier. - // Note 1: Needs to be defined by every contract producing logs. - // Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes. - unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] { - let note_header = NoteHeader::new(contract_address, nonce, storage_slot); - note_utils::compute_note_hash_and_nullifier(ValueNoteMethods, note_header, preimage) - } -} -// docs:end:all \ No newline at end of file