Skip to content

Commit 51325d9

Browse files
committed
Merge branch 'arv/simulate_public' of github.com:AztecProtocol/aztec-packages into arv/simulate_public
2 parents eecf77f + ff46ce9 commit 51325d9

16 files changed

+383
-43
lines changed

circuits/cpp/barretenberg/.gitrepo

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[subrepo]
77
remote = https://github.com/AztecProtocol/barretenberg
88
branch = master
9-
commit = 8f8b9f46028a08342a3337db633782e5313e2763
10-
parent = be9718505c7e387bb46183299c9db855e6d7f91c
9+
commit = 53d91a0b85b1087d4a44e32ac5ff64d4f1f06bf2
10+
parent = 1e312f03c455e88dcea035822159ed695912c4e8
1111
method = merge
1212
cmdver = 0.4.6
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{".":"0.4.4","ts":"0.4.4"}
1+
{".":"0.4.5","ts":"0.4.5"}

circuits/cpp/barretenberg/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [0.4.5](https://github.com/AztecProtocol/barretenberg/compare/barretenberg-v0.4.4...barretenberg-v0.4.5) (2023-08-28)
4+
5+
6+
### Bug Fixes
7+
8+
* Conditionally compile base64 command for bb binary ([#1851](https://github.com/AztecProtocol/barretenberg/issues/1851)) ([8f8b9f4](https://github.com/AztecProtocol/barretenberg/commit/8f8b9f46028a08342a3337db633782e5313e2763))
9+
310
## [0.4.4](https://github.com/AztecProtocol/barretenberg/compare/barretenberg-v0.4.3...barretenberg-v0.4.4) (2023-08-28)
411

512

circuits/cpp/barretenberg/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.4.4 x-release-please-version
1+
v0.4.5 x-release-please-version

circuits/cpp/barretenberg/barretenberg-wasm.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ in
66
stdenv.mkDerivation
77
{
88
pname = "barretenberg.wasm";
9-
version = "0.4.4"; # x-release-please-version
9+
version = "0.4.5"; # x-release-please-version
1010

1111
src = ./cpp;
1212

circuits/cpp/barretenberg/barretenberg.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ in
1414
buildEnv.mkDerivation
1515
{
1616
pname = "libbarretenberg";
17-
version = "0.4.4"; # x-release-please-version
17+
version = "0.4.5"; # x-release-please-version
1818

1919
src = ./cpp;
2020

circuits/cpp/barretenberg/cpp/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.24)
66
project(
77
Barretenberg
88
DESCRIPTION "BN254 elliptic curve library, and PLONK SNARK prover"
9-
VERSION 0.4.4 # x-release-please-version
9+
VERSION 0.4.5 # x-release-please-version
1010
LANGUAGES CXX C
1111
)
1212

circuits/cpp/barretenberg/ts/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [0.4.5](https://github.com/AztecProtocol/barretenberg/compare/barretenberg.js-v0.4.4...barretenberg.js-v0.4.5) (2023-08-28)
4+
5+
6+
### Miscellaneous Chores
7+
8+
* **barretenberg.js:** Synchronize barretenberg versions
9+
310
## [0.4.4](https://github.com/AztecProtocol/barretenberg/compare/barretenberg.js-v0.4.3...barretenberg.js-v0.4.4) (2023-08-28)
411

512

circuits/cpp/barretenberg/ts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aztec/bb.js",
3-
"version": "0.4.4",
3+
"version": "0.4.5",
44
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/circuits/cpp/barretenberg/ts",
55
"license": "MIT",
66
"type": "module",

yarn-project/aztec-cli/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ Options:
324324
- `-c, --contract-abi <fileLocation>`: The compiled contract's ABI in JSON format. You can also use one of Aztec's example contracts found in (@aztec/noir-contracts)[https://www.npmjs.com/package/@aztec/noir-contracts], e.g. PrivateTokenContractAbi.
325325
- `-ca, --contract-address <address>`: Address of the contract.
326326
- `-k, --private-key <string>`: The sender's private key.
327-
- `-u, --rpcUrl <string>`: URL of the Aztec RPC. Default: `http://localhost:8080`.
327+
- `-u, --rpc-url <string>`: URL of the Aztec RPC. Default: `http://localhost:8080`.
328328

329329
This command calls a function on an Aztec contract. It requires the contract's ABI, address, function name, and optionally, function arguments. The command executes the function call and displays the transaction details.
330330

@@ -352,7 +352,7 @@ Options:
352352
- `-c, --contract-abi <fileLocation>`: The compiled contract's ABI in JSON format. You can also use one of Aztec's example contracts found in (@aztec/noir-contracts)[https://www.npmjs.com/package/@aztec/noir-contracts], e.g. PrivateTokenContractAbi.
353353
- `-ca, --contract-address <address>`: Address of the contract.
354354
- `-f, --from <string>`: Public key of the transaction viewer. If empty, it will try to find an account in the RPC.
355-
- `-u, --rpcUrl <string>`: URL of the Aztec RPC. Default: `http://localhost:8080`.
355+
- `-u, --rpc-url <string>`: URL of the Aztec RPC. Default: `http://localhost:8080`.
356356

357357
This command simulates the execution of a view function on a deployed contract without modifying the state. It requires the contract's ABI, address, function name, and optionally, function arguments. The command displays the result of the view function.
358358

yarn-project/aztec-cli/src/encoding.ts

+34-15
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,37 @@ export function parseStructString(str: string, abiType: StructType) {
2929
* @param abiType - The type as described by the contract's ABI.
3030
* @returns The encoded argument.
3131
*/
32-
function encodeArg(arg: string, abiType: ABIType): any {
32+
function encodeArg(arg: string, abiType: ABIType, name: string): any {
3333
const { kind } = abiType;
3434
if (kind === 'field' || kind === 'integer') {
35-
return BigInt(arg);
35+
let res: bigint;
36+
try {
37+
res = BigInt(arg);
38+
} catch (err) {
39+
throw new Error(
40+
`Invalid value passed for ${name}. Could not parse ${arg} as a${kind === 'integer' ? 'n' : ''} ${kind}.`,
41+
);
42+
}
43+
return res;
3644
} else if (kind === 'boolean') {
3745
if (arg === 'true') return true;
3846
if (arg === 'false') return false;
47+
else throw Error(`Invalid boolean value passed for ${name}: ${arg}.`);
3948
} else if (kind === 'array') {
4049
let arr;
50+
const res = [];
4151
try {
4252
arr = JSON.parse(arg);
43-
if (!Array.isArray(arr)) throw Error();
44-
for (let i = 0; i < abiType.length; i += 1) {
45-
return encodeArg(arg[i], abiType.type);
46-
}
4753
} catch {
48-
throw new Error(`Unable to parse arg ${arg} as array`);
54+
throw new Error(`Unable to parse arg ${arg} as array for ${name} parameter`);
55+
}
56+
if (!Array.isArray(arr)) throw Error(`Invalid argument ${arg} passed for array parameter ${name}.`);
57+
if (arr.length !== abiType.length)
58+
throw Error(`Invalid array length passed for ${name}. Expected ${abiType.length}, received ${arr.length}.`);
59+
for (let i = 0; i < abiType.length; i += 1) {
60+
res.push(encodeArg(arr[i], abiType.type, name));
4961
}
62+
return res;
5063
} else if (kind === 'struct') {
5164
// check if input is encoded long string
5265
if (arg.startsWith('0x')) {
@@ -55,15 +68,18 @@ function encodeArg(arg: string, abiType: ABIType): any {
5568
let obj;
5669
try {
5770
obj = JSON.parse(arg);
58-
if (Array.isArray(obj)) throw Error();
59-
const res = [];
60-
for (const field of abiType.fields) {
61-
res.push(encodeArg(obj[field.name], field.type));
62-
}
63-
return res;
6471
} catch {
6572
throw new Error(`Unable to parse arg ${arg} as struct`);
6673
}
74+
if (Array.isArray(obj)) throw Error(`Array passed for arg ${name}. Expected a struct.`);
75+
const res = [];
76+
for (const field of abiType.fields) {
77+
// Remove field name from list as it's present
78+
const arg = obj[field.name];
79+
if (!arg) throw Error(`Expected field ${field.name} not found in struct ${name}.`);
80+
res.push(encodeArg(obj[field.name], field.type, field.name));
81+
}
82+
return res;
6783
}
6884
}
6985

@@ -73,10 +89,13 @@ function encodeArg(arg: string, abiType: ABIType): any {
7389
* @returns The encoded array.
7490
*/
7591
export function encodeArgs(args: any[], params: ABIParameter[]) {
92+
if (args.length !== params.length) {
93+
throw new Error(`Invalid number of args provided. Expected: ${params.length}, received: ${args.length}`);
94+
}
7695
return args
7796
.map((arg: any, index) => {
78-
const paramType = params[index].type;
79-
return encodeArg(arg, paramType);
97+
const { type, name } = params[index];
98+
return encodeArg(arg, type, name);
8099
})
81100
.flat();
82101
}

yarn-project/aztec-cli/src/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
129129
.action(async options => {
130130
const client = await createCompatibleClient(options.rpcUrl, debugLogger);
131131
const privateKey = options.privateKey
132-
? new PrivateKey(Buffer.from(stripLeadingHex(options.privateKey), 'hex'))
132+
? PrivateKey.fromString(stripLeadingHex(options.privateKey))
133133
: PrivateKey.random();
134134

135135
const account = getSchnorrAccount(client, privateKey, privateKey, accountCreationSalt);
@@ -198,8 +198,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
198198

199199
program
200200
.command('get-tx-receipt')
201-
.argument('<txHash>', 'A transaction hash to get the receipt for.')
202201
.description('Gets the receipt for the specified transaction hash.')
202+
.argument('<txHash>', 'A transaction hash to get the receipt for.')
203203
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
204204
.action(async (_txHash, options) => {
205205
const client = await createCompatibleClient(options.rpcUrl, debugLogger);
@@ -361,7 +361,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
361361
)
362362
.requiredOption('-ca, --contract-address <address>', 'Aztec address of the contract.')
363363
.option('-k, --private-key <string>', "The sender's private key.", PRIVATE_KEY)
364-
.option('-u, --rpcUrl <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
364+
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
365365

366366
.action(async (functionName, options) => {
367367
const { contractAddress, functionArgs, contractAbi } = await prepTx(
@@ -379,7 +379,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
379379
);
380380
}
381381

382-
const privateKey = new PrivateKey(Buffer.from(stripLeadingHex(options.privateKey), 'hex'));
382+
const privateKey = PrivateKey.fromString(stripLeadingHex(options.privateKey));
383383

384384
const client = await createCompatibleClient(options.rpcUrl, debugLogger);
385385
const wallet = await getAccountWallets(
@@ -391,7 +391,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
391391
);
392392
const contract = await Contract.at(contractAddress, contractAbi, wallet);
393393
const tx = contract.methods[functionName](...functionArgs).send();
394-
await tx.isMined();
394+
await tx.wait();
395395
log('\nTransaction has been mined');
396396
const receipt = await tx.getReceipt();
397397
log(`Transaction hash: ${(await tx.getTxHash()).toString()}`);
@@ -413,7 +413,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
413413
)
414414
.requiredOption('-ca, --contract-address <address>', 'Aztec address of the contract.')
415415
.option('-f, --from <string>', 'Public key of the TX viewer. If empty, will try to find account in RPC.')
416-
.option('-u, --rpcUrl <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
416+
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
417417
.action(async (functionName, options) => {
418418
const { contractAddress, functionArgs, contractAbi } = await prepTx(
419419
options.contractAbi,
@@ -431,7 +431,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
431431
const client = await createCompatibleClient(options.rpcUrl, debugLogger);
432432
const from = await getTxSender(client, options.from);
433433
const result = await client.viewTx(functionName, functionArgs, contractAddress, from);
434-
log('\nView result: ', JsonStringify(result, true), '\n');
434+
log('\nView result: ', result, '\n');
435435
});
436436

437437
// Helper for users to decode hex strings into structs if needed
@@ -461,7 +461,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
461461
program
462462
.command('block-number')
463463
.description('Gets the current Aztec L2 block number.')
464-
.option('-u, --rpcUrl <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
464+
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
465465
.action(async (options: any) => {
466466
const client = await createCompatibleClient(options.rpcUrl, debugLogger);
467467
const num = await client.getBlockNumber();
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { ABIParameterVisibility, ContractAbi, FunctionType } from '@aztec/foundation/abi';
2+
3+
export const mockContractAbi: ContractAbi = {
4+
name: 'MockContract',
5+
functions: [
6+
{
7+
name: 'constructor',
8+
functionType: FunctionType.SECRET,
9+
isInternal: false,
10+
parameters: [
11+
{
12+
name: 'constructorParam1',
13+
type: {
14+
kind: 'field',
15+
},
16+
visibility: ABIParameterVisibility.SECRET,
17+
},
18+
],
19+
returnTypes: [],
20+
bytecode: 'constructorBytecode',
21+
},
22+
{
23+
name: 'mockFunction',
24+
functionType: FunctionType.SECRET,
25+
isInternal: false,
26+
parameters: [
27+
{
28+
name: 'fieldParam',
29+
type: { kind: 'field' },
30+
visibility: ABIParameterVisibility.SECRET,
31+
},
32+
{
33+
name: 'boolParam',
34+
type: { kind: 'boolean' },
35+
visibility: ABIParameterVisibility.SECRET,
36+
},
37+
{
38+
name: 'integerParam',
39+
type: { kind: 'integer', sign: 'signed', width: 32 },
40+
visibility: ABIParameterVisibility.SECRET,
41+
},
42+
{
43+
name: 'arrayParam',
44+
type: { kind: 'array', length: 3, type: { kind: 'field' } },
45+
visibility: ABIParameterVisibility.SECRET,
46+
},
47+
{
48+
name: 'structParam',
49+
type: {
50+
kind: 'struct',
51+
fields: [
52+
{ name: 'subField1', type: { kind: 'field' } },
53+
{ name: 'subField2', type: { kind: 'boolean' } },
54+
],
55+
},
56+
visibility: ABIParameterVisibility.SECRET,
57+
},
58+
],
59+
returnTypes: [{ kind: 'boolean' }],
60+
bytecode: 'mockBytecode',
61+
},
62+
],
63+
};

0 commit comments

Comments
 (0)