Skip to content

Commit

Permalink
chore: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Sep 11, 2023
1 parent 42ab573 commit e0c414a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
4 changes: 2 additions & 2 deletions yarn-project/acir-simulator/src/client/private_execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ export class PrivateFunctionExecution {
return Promise.resolve(ZERO_ACVM_FIELD);
},
enqueuePublicFunctionCall: async ([acvmContractAddress], [acvmFunctionSelector], [acvmArgsHash]) => {
const selector = frToAztecAddress(fromACVMField(acvmContractAddress));
const selector = FunctionSelector.fromField(fromACVMField(acvmFunctionSelector));
const enqueuedRequest = await this.enqueuePublicFunctionCall(
frToAztecAddress(fromACVMField(acvmContractAddress)),
selector,
FunctionSelector.fromField(fromACVMField(acvmFunctionSelector)),
this.context.packedArgsCache.unpack(fromACVMField(acvmArgsHash)),
this.callContext,
);
Expand Down
28 changes: 18 additions & 10 deletions yarn-project/end-to-end/src/e2e_token_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe('e2e_token_contract', () => {
it('as minter', async () => {
const amount = 10000n;
const tx = asset.methods
.mint_pub({ address: accounts[0].address }, amount)
.mint_public({ address: accounts[0].address }, amount)
.send({ origin: accounts[0].address });
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
Expand All @@ -246,28 +246,36 @@ describe('e2e_token_contract', () => {
it('as non-minter', async () => {
const amount = 10000n;
await expect(
asset.methods.mint_pub({ address: accounts[0].address }, amount).simulate({ origin: accounts[1].address }),
asset.methods
.mint_public({ address: accounts[0].address }, amount)
.simulate({ origin: accounts[1].address }),
).rejects.toThrowError('Assertion failed: caller is not minter');
});

it('mint >u120 tokens to overflow', async () => {
const amount = 2n ** 120n; // SafeU120::max() + 1;
await expect(
asset.methods.mint_pub({ address: accounts[0].address }, amount).simulate({ origin: accounts[0].address }),
asset.methods
.mint_public({ address: accounts[0].address }, amount)
.simulate({ origin: accounts[0].address }),
).rejects.toThrowError('Assertion failed: Value too large for SafeU120');
});

it('mint <u120 but recipient balance >u120', async () => {
const amount = 2n ** 120n - tokenSim.balanceOfPublic(accounts[0].address);
await expect(
asset.methods.mint_pub({ address: accounts[0].address }, amount).simulate({ origin: accounts[0].address }),
asset.methods
.mint_public({ address: accounts[0].address }, amount)
.simulate({ origin: accounts[0].address }),
).rejects.toThrowError('Assertion failed: Overflow');
});

it('mint <u120 but such that total supply >u120', async () => {
const amount = 2n ** 120n - tokenSim.balanceOfPublic(accounts[0].address);
await expect(
asset.methods.mint_pub({ address: accounts[1].address }, amount).simulate({ origin: accounts[0].address }),
asset.methods
.mint_public({ address: accounts[1].address }, amount)
.simulate({ origin: accounts[0].address }),
).rejects.toThrowError('Assertion failed: Overflow');
});
});
Expand All @@ -284,7 +292,7 @@ describe('e2e_token_contract', () => {

describe('Mint flow', () => {
it('mint_private as minter', async () => {
const tx = asset.methods.mint_priv(amount, secretHash).send({ origin: accounts[0].address });
const tx = asset.methods.mint_private(amount, secretHash).send({ origin: accounts[0].address });
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
tokenSim.mintPrivate(accounts[0].address, amount);
Expand Down Expand Up @@ -312,28 +320,28 @@ describe('e2e_token_contract', () => {

it('mint_private as non-minter', async () => {
await expect(
asset.methods.mint_priv(amount, secretHash).simulate({ origin: accounts[1].address }),
asset.methods.mint_private(amount, secretHash).simulate({ origin: accounts[1].address }),
).rejects.toThrowError('Assertion failed: caller is not minter');
});

it('mint >u120 tokens to overflow', async () => {
const amount = 2n ** 120n; // SafeU120::max() + 1;
await expect(
asset.methods.mint_priv(amount, secretHash).simulate({ origin: accounts[0].address }),
asset.methods.mint_private(amount, secretHash).simulate({ origin: accounts[0].address }),
).rejects.toThrowError('Assertion failed: Value too large for SafeU120');
});

it('mint <u120 but recipient balance >u120', async () => {
const amount = 2n ** 120n - tokenSim.balanceOfPrivate(accounts[0].address);
await expect(
asset.methods.mint_priv(amount, secretHash).simulate({ origin: accounts[0].address }),
asset.methods.mint_private(amount, secretHash).simulate({ origin: accounts[0].address }),
).rejects.toThrowError('Assertion failed: Overflow');
});

it('mint <u120 but such that total supply >u120', async () => {
const amount = 2n ** 120n - tokenSim.totalSupply;
await expect(
asset.methods.mint_priv(amount, secretHash).simulate({ origin: accounts[0].address }),
asset.methods.mint_private(amount, secretHash).simulate({ origin: accounts[0].address }),
).rejects.toThrowError('Assertion failed: Overflow');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ contract Token {
}

#[aztec(public)]
fn mint_pub(
fn mint_public(
to: AztecAddress,
amount: Field,
) -> Field {
Expand All @@ -138,7 +138,7 @@ contract Token {
}

#[aztec(public)]
fn mint_priv(
fn mint_private(
amount: Field,
secret_hash: Field,
) -> Field {
Expand Down Expand Up @@ -205,6 +205,8 @@ contract Token {

let to_balance = SafeU120::new(storage.public_balances.at(to.address).read()).add(amount);
storage.public_balances.at(to.address).write(to_balance.value as Field);

1
}

#[aztec(public)]
Expand All @@ -229,6 +231,8 @@ contract Token {

let new_supply = SafeU120::new(storage.total_supply.read()).sub(amount);
storage.total_supply.write(new_supply.value as Field);

1
}

#[aztec(private)]
Expand All @@ -244,6 +248,8 @@ contract Token {

pending_shields.assert_contains_and_remove(public_note);
increment(balance, amount, to.address);

1
}

#[aztec(private)]
Expand All @@ -268,6 +274,8 @@ contract Token {

let selector = compute_selector("_increase_public_balance((Field),Field)");
let _void = context.call_public_function(context.this_address(), selector, [to.address, amount]);

1
}

#[aztec(private)]
Expand All @@ -292,6 +300,8 @@ contract Token {

decrement(from_balance, amount, from.address);
increment(to_balance, amount, to.address);

1
}

#[aztec(private)]
Expand All @@ -316,6 +326,8 @@ contract Token {

let selector = compute_selector("_reduce_total_supply(Field)");
let _void = context.call_public_function(context.this_address(), selector, [amount]);

1
}

/// SHOULD BE Internal ///
Expand Down
5 changes: 2 additions & 3 deletions yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createEthereumChain } from '@aztec/ethereum';
import { createDebugLogger } from '@aztec/foundation/log';
import { ContractDeploymentEmitterAbi, RollupAbi } from '@aztec/l1-artifacts';
import { ExtendedContractData } from '@aztec/types';
import { BLOB_SIZE_IN_BYTES, ExtendedContractData } from '@aztec/types';

import {
GetContractReturnType,
Expand Down Expand Up @@ -142,8 +142,7 @@ export class ViemTxSender implements L1PublisherTxSender {
] as const;

const codeSize = extendedContractData.bytecode.length;
const blobSize = 31 * 4096;
this.log(`Bytecode is ${codeSize} bytes and require ${codeSize / blobSize} blobs`);
this.log(`Bytecode is ${codeSize} bytes and require ${codeSize / BLOB_SIZE_IN_BYTES} blobs`);

const gas = await this.contractDeploymentEmitterContract.estimateGas.emitContractDeployment(args, {
account: this.account,
Expand Down
1 change: 1 addition & 0 deletions yarn-project/types/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const INITIAL_L2_BLOCK_NUM = 1;
export const BLOB_SIZE_IN_BYTES = 31 * 4096;

0 comments on commit e0c414a

Please sign in to comment.