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

fix: Add checks for arg-type #638

Merged
merged 4 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 11 additions & 1 deletion yarn-project/acir-simulator/src/abi_coder/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ class ArgumentEncoder {
private encodeArgument(abiType: ABIType, arg: any) {
switch (abiType.kind) {
case 'field':
this.flattened.push(new Fr(arg));
if (typeof arg === 'number') {
this.flattened.push(new Fr(BigInt(arg)));
} else if (typeof arg === 'bigint') {
this.flattened.push(new Fr(arg));
} else if (typeof arg === 'object') {
if (typeof arg.toField === 'function') {
this.flattened.push(arg.toField());
} else {
this.flattened.push(arg);
}
}
break;
case 'boolean':
this.flattened.push(new Fr(arg ? 1n : 0n));
Expand Down
11 changes: 3 additions & 8 deletions yarn-project/acir-simulator/src/client/private_execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ describe('Private Execution test suite', () => {
AztecAddress.random(),
AztecAddress.ZERO,
new FunctionData(Buffer.alloc(4), true, false),
encodeArguments(parentAbi, [Fr.fromBuffer(childAddress.toBuffer()).value, Fr.fromBuffer(childSelector).value]),
encodeArguments(parentAbi, [Fr.fromBuffer(childAddress.toBuffer()), Fr.fromBuffer(childSelector)]),
Fr.random(),
txContext,
Fr.ZERO,
Expand Down Expand Up @@ -427,8 +427,7 @@ describe('Private Execution test suite', () => {
AztecAddress.random(),
contractAddress,
new FunctionData(Buffer.alloc(4), true, true),
// BUG: placing a fr in args will result in a fr wrapped in an fr: https://github.com/AztecProtocol/aztec-packages/issues/611
encodeArguments(abi, [bridgedAmount, recipient, messageKey.value, secret.value]),
encodeArguments(abi, [bridgedAmount, recipient, messageKey, secret]),
Fr.random(),
txContext,
Fr.ZERO,
Expand Down Expand Up @@ -459,11 +458,7 @@ describe('Private Execution test suite', () => {
AztecAddress.random(),
parentAddress,
new FunctionData(Buffer.alloc(4), true, false),
encodeArguments(parentAbi, [
Fr.fromBuffer(childAddress.toBuffer()).value,
Fr.fromBuffer(childSelector).value,
42n,
]),
encodeArguments(parentAbi, [Fr.fromBuffer(childAddress.toBuffer()), Fr.fromBuffer(childSelector), 42n]),
Fr.random(),
txContext,
Fr.ZERO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,7 @@ describe('e2e_rollup_native_asset_contract', () => {
const ethOutAddress = EthAddress.fromString('0x000000000000000000000000000000000000dead');

const tx = contract.methods
.withdraw(
withdrawAmount,
pointToPublicKey(await aztecRpcServer.getAccountPublicKey(owner)),
ethOutAddress.toField().value,
)
.withdraw(withdrawAmount, pointToPublicKey(await aztecRpcServer.getAccountPublicKey(owner)), ethOutAddress)
.send({ from: accounts[0] });

await tx.isMined(0, 0.1);
Expand Down