Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test-contracts): prepare e2e_token_contract+ error msgs for AVM migration #6307

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion noir-projects/aztec-nr/aztec/src/context/avm_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use dep::protocol_types::{
address::{AztecAddress, EthAddress},
constants::{L1_TO_L2_MESSAGE_LENGTH, NESTED_CALL_L2_GAS_BUFFER}, header::Header
};
use dep::protocol_types::traits::Serialize;
use dep::protocol_types::traits::{Deserialize, Serialize, Empty};
use dep::protocol_types::abis::function_selector::FunctionSelector;
use dep::protocol_types::abis::public_circuit_public_inputs::PublicCircuitPublicInputs;
use crate::context::inputs::avm_context_inputs::AvmContextInputs;
Expand Down Expand Up @@ -191,6 +191,12 @@ impl ContextInterface for AvmContext {
}
}

impl Empty for AvmContext {
fn empty() -> Self {
AvmContext::new(AvmContextInputs::empty())
}
}

// Helper functions
fn gas_for_call(user_gas: GasOpts) -> [Field; 2] {
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
use dep::protocol_types::traits::Empty;

struct AvmContextInputs {
selector: Field,
args_hash: Field,
}

impl Empty for AvmContextInputs {
fn empty() -> Self {
AvmContextInputs {
selector: 0,
args_hash: 0,
}
}
}
9 changes: 5 additions & 4 deletions yarn-project/end-to-end/src/e2e_authwit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SchnorrAccountContract } from '@aztec/noir-contracts.js';

import { jest } from '@jest/globals';

import { DUPLICATE_NULLIFIER_ERROR } from './fixtures/fixtures.js';
import { publicDeployAccounts, setup } from './fixtures/utils.js';

const TIMEOUT = 90_000;
Expand Down Expand Up @@ -86,7 +87,7 @@ describe('e2e_authwit_tests', () => {
});

// The transaction should be dropped because of a cancelled authwit (duplicate nullifier)
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

it('invalid chain id', async () => {
Expand Down Expand Up @@ -130,7 +131,7 @@ describe('e2e_authwit_tests', () => {
});

// The transaction should be dropped because of the invalid chain id
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

it('invalid version', async () => {
Expand Down Expand Up @@ -174,7 +175,7 @@ describe('e2e_authwit_tests', () => {
});

// The transaction should be dropped because of the invalid version
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});
});
});
Expand Down Expand Up @@ -234,7 +235,7 @@ describe('e2e_authwit_tests', () => {
const c = await SchnorrAccountContract.at(wallets[0].getAddress(), wallets[0]);
const txCancelledAuthwit = c.withWallet(wallets[1]).methods.spend_public_authwit(innerHash).send();
// The transaction should be dropped because of a cancelled authwit (duplicate nullifier)
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js';

describe('e2e_blacklist_token_contract burn', () => {
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('e2e_blacklist_token_contract burn', () => {

// Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer.
const txReplay = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('e2e_blacklist_token_contract burn', () => {

// Perform the transfer again, should fail
const txReplay = asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce).send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr, computeSecretHash } from '@aztec/aztec.js';

import { U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js';

describe('e2e_blacklist_token_contract shield + redeem_shield', () => {
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('e2e_blacklist_token_contract shield + redeem_shield', () => {
.withWallet(wallets[1])
.methods.shield(wallets[0].getAddress(), amount, secretHash, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);

// Redeem it
await t.addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { DUPLICATE_NULLIFIER_ERROR } from '../fixtures/fixtures.js';
import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js';

describe('e2e_blacklist_token_contract transfer private', () => {
Expand Down Expand Up @@ -67,7 +68,7 @@ describe('e2e_blacklist_token_contract transfer private', () => {
.withWallet(wallets[1])
.methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr } from '@aztec/aztec.js';

import { U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js';

describe('e2e_blacklist_token_contract transfer public', () => {
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('e2e_blacklist_token_contract transfer public', () => {
.withWallet(wallets[1])
.methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { DUPLICATE_NULLIFIER_ERROR } from '../fixtures/fixtures.js';
import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js';

describe('e2e_blacklist_token_contract unshielding', () => {
Expand Down Expand Up @@ -57,7 +58,7 @@ describe('e2e_blacklist_token_contract unshielding', () => {
.withWallet(wallets[1])
.methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
// @todo @LHerskind This error is weird?
});

Expand Down
6 changes: 3 additions & 3 deletions yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { TokenContractTest } from './token_contract_test.js';

describe('e2e_token_contract burn', () => {
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('e2e_token_contract burn', () => {

// Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer.
const txReplay = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce).send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('e2e_token_contract burn', () => {

// Perform the transfer again, should fail
const txReplay = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce).send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr, computeSecretHash } from '@aztec/aztec.js';

import { U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js';
import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js';
import { TokenContractTest } from './token_contract_test.js';

describe('e2e_token_contract shield + redeem shield', () => {
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('e2e_token_contract shield + redeem shield', () => {

// Check that replaying the shield should fail!
const txReplay = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce).send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);

// Redeem it
await t.addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { DUPLICATE_NULLIFIER_ERROR } from '../fixtures/fixtures.js';
import { TokenContractTest } from './token_contract_test.js';

describe('e2e_token_contract transfer private', () => {
Expand Down Expand Up @@ -66,7 +67,7 @@ describe('e2e_token_contract transfer private', () => {
.withWallet(wallets[1])
.methods.transfer(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down Expand Up @@ -188,7 +189,7 @@ describe('e2e_token_contract transfer private', () => {
.withWallet(wallets[1])
.methods.transfer(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txCancelledAuthwit.wait()).rejects.toThrowError('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrowError(DUPLICATE_NULLIFIER_ERROR);
});

it('transfer on behalf of other, cancelled authwit, flow 2', async () => {
Expand All @@ -212,7 +213,7 @@ describe('e2e_token_contract transfer private', () => {
.withWallet(wallets[1])
.methods.transfer(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

it('transfer on behalf of other, invalid spend_private_authwit on "from"', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js';
import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js';
import { TokenContractTest } from './token_contract_test.js';

describe('e2e_token_contract transfer public', () => {
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('e2e_token_contract transfer public', () => {
.withWallet(wallets[1])
.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('e2e_token_contract transfer public', () => {
.withWallet(wallets[1])
.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txCancelledAuthwit.wait()).rejects.toThrowError('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrowError(DUPLICATE_NULLIFIER_ERROR);
});

it('transfer on behalf of other, cancelled authwit, flow 2', async () => {
Expand All @@ -216,7 +216,7 @@ describe('e2e_token_contract transfer public', () => {
.withWallet(wallets[1])
.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txCancelledAuthwit.wait()).rejects.toThrowError('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrowError(DUPLICATE_NULLIFIER_ERROR);
});

it('transfer on behalf of other, cancelled authwit, flow 3', async () => {
Expand Down Expand Up @@ -244,7 +244,7 @@ describe('e2e_token_contract transfer public', () => {
.withWallet(wallets[1])
.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

it('transfer on behalf of other, invalid spend_public_authwit on "from"', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { DUPLICATE_NULLIFIER_ERROR } from '../fixtures/fixtures.js';
import { TokenContractTest } from './token_contract_test.js';

describe('e2e_token_contract unshielding', () => {
Expand Down Expand Up @@ -56,7 +57,7 @@ describe('e2e_token_contract unshielding', () => {
.withWallet(wallets[1])
.methods.unshield(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/end-to-end/src/fixtures/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const U128_UNDERFLOW_ERROR = "Assertion failed: attempt to subtract with
export const U128_OVERFLOW_ERROR = "Assertion failed: attempt to add with overflow 'hi == high'";
export const BITSIZE_TOO_BIG_ERROR =
"Assertion failed: call to assert_max_bit_size 'self.__assert_max_bit_size(bit_size)'";
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/5818): Make this a fixed error after transition.
export const DUPLICATE_NULLIFIER_ERROR = /Transaction .*|.*duplicate nullifier.*/;
Loading