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

Bumped circuits #198

Merged
merged 11 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion circuits
Submodule circuits updated 33 files
+1 −1 cpp/barretenberg
+3 −1 cpp/cmake/barretenberg.cmake
+1 −0 cpp/dockerfiles/Dockerfile.wasm-linux-clang
+13 −11 cpp/src/aztec3/circuits/abis/c_bind.cpp
+23 −10 cpp/src/aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp
+0 −59 cpp/src/aztec3/circuits/abis/rollup/base/previous_rollup_data.hpp
+0 −104 cpp/src/aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp
+6 −6 cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp
+1 −1 cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp
+1 −1 cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp
+1 −1 cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp
+1 −1 cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp
+1 −1 cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp
+1 −1 cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp
+50 −20 cpp/src/aztec3/circuits/kernel/private/.test.cpp
+18 −8 cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp
+12 −7 cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp
+0 −3 cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp
+35 −40 cpp/src/aztec3/circuits/rollup/base/.test.cpp
+8 −24 cpp/src/aztec3/circuits/rollup/base/c_bind.cpp
+2 −3 cpp/src/aztec3/circuits/rollup/base/init.hpp
+7 −5 cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp
+2 −2 cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp
+1 −23 cpp/src/aztec3/circuits/rollup/base/utils.cpp
+0 −2 cpp/src/aztec3/circuits/rollup/base/utils.hpp
+170 −0 cpp/src/aztec3/circuits/rollup/merge/.test.cpp
+3 −2 cpp/src/aztec3/circuits/rollup/merge/init.hpp
+130 −11 cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp
+1 −1 cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp
+72 −0 cpp/src/aztec3/circuits/rollup/merge/utils.cpp
+17 −0 cpp/src/aztec3/circuits/rollup/merge/utils.hpp
+18 −17 cpp/src/aztec3/circuits/rollup/root/.test.cpp
+23 −4 cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp
38 changes: 2 additions & 36 deletions yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -122,42 +122,8 @@ Object {
`;

exports[`abis wasm bindings computes contract leaf 1`] = `
Object {
"data": Array [
37,
164,
27,
46,
63,
9,
182,
227,
172,
238,
84,
38,
169,
47,
59,
48,
111,
49,
185,
159,
58,
31,
73,
162,
28,
126,
118,
148,
55,
26,
100,
78,
],
"type": "Buffer",
Fr {
"value": 13761632275218847273520262751574664149269181891159611676226614084913136324343n,
}
`;

Expand Down
9 changes: 5 additions & 4 deletions yarn-project/circuits.js/src/abis/abis.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Fr, FunctionData, NullifierLeafPreimage } from '../index.js';
import { fr, makeAztecAddress, makeBytes, makeTxRequest, makeVerificationKey } from '../tests/factories.js';
import { Fr, FunctionData, NewContractData } from '../index.js';
import { makeEthAddress } from '../tests/factories.js';
import { makeAztecAddress, makeBytes, makeTxRequest, makeVerificationKey } from '../tests/factories.js';
import { CircuitsWasm } from '../wasm/circuits_wasm.js';
import {
computeContractAddress,
Expand Down Expand Up @@ -72,8 +73,8 @@ describe('abis wasm bindings', () => {
});

it('computes contract leaf', async () => {
const leafPreImage = new NullifierLeafPreimage(fr(2), fr(2 + 0x100), 2 + 0x200);
const res = await computeContractLeaf(wasm, leafPreImage);
const cd = new NewContractData(makeAztecAddress(), makeEthAddress(), new Fr(3n));
const res = await computeContractLeaf(wasm, cd);
expect(res).toMatchSnapshot();
});
});
17 changes: 11 additions & 6 deletions yarn-project/circuits.js/src/abis/abis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Buffer } from 'buffer';
import { AztecAddress, Fr, serializeBufferArrayToVector } from '@aztec/foundation';
import { CircuitsWasm } from '../wasm/index.js';
import { FunctionData, FUNCTION_SELECTOR_NUM_BYTES, NullifierLeafPreimage, TxRequest } from '../index.js';
import { FunctionData, FUNCTION_SELECTOR_NUM_BYTES, TxRequest, NewContractData } from '../index.js';
import { serializeToBuffer } from '../utils/serialize.js';

export async function hashTxRequest(wasm: CircuitsWasm, txRequest: TxRequest) {
Expand Down Expand Up @@ -83,10 +83,15 @@ export async function computeContractAddress(
return AztecAddress.fromBuffer(resultBuf);
}

export async function computeContractLeaf(wasm: CircuitsWasm, leafPreimage: NullifierLeafPreimage) {
const data = leafPreimage.toBuffer();
export async function computeContractLeaf(wasm: CircuitsWasm, cd: NewContractData) {
wasm.call('pedersen__init');
wasm.writeMemory(0, leafPreimage.toBuffer());
await wasm.asyncCall('abis__compute_contract_leaf', 0, data.length);
return Buffer.from(wasm.getMemorySlice(data.length, data.length + 32));
const data = cd.toBuffer();
const outputBuf = wasm.call('bbmalloc', 32);
const inputBuf = wasm.call('bbmalloc', data.length);
wasm.writeMemory(inputBuf, data);
await wasm.asyncCall('abis__compute_contract_leaf', inputBuf, outputBuf);
const buf = Buffer.from(wasm.getMemorySlice(outputBuf, outputBuf + 32));
wasm.call('bbfree', outputBuf);
wasm.call('bbfree', inputBuf);
return Fr.fromBuffer(buf);
}
6 changes: 3 additions & 3 deletions yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BaseRollupInputs, BaseRollupPublicInputs, RootRollupInputs, RootRollupPublicInputs } from '../index.js';
import { BaseRollupInputs, BaseOrMergeRollupPublicInputs, RootRollupInputs, RootRollupPublicInputs } from '../index.js';
import { uint8ArrayToNum } from '../utils/serialize.js';
import { CircuitsWasm } from '../wasm/circuits_wasm.js';

export class RollupWasmWrapper {
constructor(private wasm: CircuitsWasm) {}

public simulateBaseRollup(baseRollupInputs: BaseRollupInputs): Promise<BaseRollupPublicInputs> {
return this.callWasm('base_rollup__sim', baseRollupInputs, BaseRollupPublicInputs);
public simulateBaseRollup(baseRollupInputs: BaseRollupInputs): Promise<BaseOrMergeRollupPublicInputs> {
return this.callWasm('base_rollup__sim', baseRollupInputs, BaseOrMergeRollupPublicInputs);
}

public simulateRootRollup(rootRollupInputs: RootRollupInputs): Promise<RootRollupPublicInputs> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ merge_rollup_vk_hash: 0x404
`;

exports[`structs/base_rollup serializes and prints BaseRollupPublicInputs 1`] = `
"end_aggregation_object:
"rollup_type:
0
rollup_subtree_height:
0x0
end_aggregation_object:
P0: { 0x100, 0x101 }
P1: { 0x200, 0x201 }
public_inputs: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`structs/root_rollup serializes a RootRollupInput and prints it 1`] = `
"previous_rollup_data: [ merge_rollup_public_inputs: end_aggregation_object:
"previous_rollup_data: [ base_or_merge_rollup_public_inputs: rollup_type:
0
rollup_subtree_height:
0x0
end_aggregation_object:
P0: { 0x100, 0x101 }
P1: { 0x200, 0x201 }
public_inputs: [
Expand Down Expand Up @@ -58,20 +62,16 @@ next_available_leaf_index: 800
calldata_hash: [ 0x901 0x902 ]
proof: [ 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 ]
vk: key.composer_type: 0
key.circuit_size: 65
key.num_public_inputs: 66
key.commitments: [
A: { 0x200, 0x300 }
]
key.contains_recursive_proof: 1
key.recursive_proof_public_input_indices: [ 190 191 192 193 194 ]
vk: 0x12b300
vk_index: 110
vk_sibling_path: leaf_index: 120
sibling_path: [ 0x120 0x121 0x122 0x123 0x124 0x125 0x126 0x127 ]
merge_rollup_public_inputs: end_aggregation_object:
base_or_merge_rollup_public_inputs: rollup_type:
0
rollup_subtree_height:
0x0
end_aggregation_object:
P0: { 0x1100, 0x1101 }
P1: { 0x1200, 0x1201 }
public_inputs: [
Expand Down Expand Up @@ -128,15 +128,7 @@ next_available_leaf_index: 1800
calldata_hash: [ 0x1901 0x1902 ]
proof: [ 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 ]
vk: key.composer_type: 0
key.circuit_size: 65
key.num_public_inputs: 66
key.commitments: [
A: { 0x200, 0x300 }
]
key.contains_recursive_proof: 1
key.recursive_proof_public_input_indices: [ 190 191 192 193 194 ]
vk: 0x133e40
vk_index: 1110
vk_sibling_path: leaf_index: 1120
sibling_path: [ 0x1120 0x1121 0x1122 0x1123 0x1124 0x1125 0x1126 0x1127 ]
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/circuits.js/src/structs/base_rollup.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectReserializeToMatchObject, expectSerializeToMatchSnapshot } from '../tests/expectSerialize.js';
import { makeBaseRollupInputs, makeBaseRollupPublicInputs } from '../tests/factories.js';
import { BaseRollupPublicInputs } from './base_rollup.js';
import { BaseOrMergeRollupPublicInputs } from './base_rollup.js';

describe('structs/base_rollup', () => {
it(`serializes and prints BaseRollupInputs`, async () => {
Expand All @@ -16,7 +16,7 @@ describe('structs/base_rollup', () => {

await expectSerializeToMatchSnapshot(
baseRollupPublicInputs.toBuffer(),
'abis__test_roundtrip_serialize_base_rollup_public_inputs',
'abis__test_roundtrip_serialize_base_or_merge_rollup_public_inputs',
);
});

Expand All @@ -25,8 +25,8 @@ describe('structs/base_rollup', () => {

await expectReserializeToMatchObject(
baseRollupPublicInputs,
'abis__test_roundtrip_reserialize_base_rollup_public_inputs',
BaseRollupPublicInputs.fromBuffer,
'abis__test_roundtrip_reserialize_base_or_merge_rollup_public_inputs',
BaseOrMergeRollupPublicInputs.fromBuffer,
);
});
});
14 changes: 10 additions & 4 deletions yarn-project/circuits.js/src/structs/base_rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT,
} from './constants.js';
import { PreviousKernelData } from './kernel.js';
import { AggregationObject, MembershipWitness, UInt32 } from './shared.js';
import { AggregationObject, MembershipWitness, RollupTypes, UInt32 } from './shared.js';

export class NullifierLeafPreimage {
constructor(public leafValue: Fr, public nextValue: Fr, public nextIndex: UInt32) {}
Expand Down Expand Up @@ -168,8 +168,10 @@ export class BaseRollupInputs {
/**
* Output of the base rollup circuit
*/
export class BaseRollupPublicInputs {
export class BaseOrMergeRollupPublicInputs {
constructor(
public rollupType: RollupTypes,
public rollupSubTreeHeight: Fr,
public endAggregationObject: AggregationObject,
public constants: ConstantBaseRollupData,

Expand All @@ -190,9 +192,11 @@ export class BaseRollupPublicInputs {
* Deserializes from a buffer or reader, corresponding to a write in cpp.
* @param bufferReader - Buffer to read from.
*/
static fromBuffer(buffer: Buffer | BufferReader): BaseRollupPublicInputs {
static fromBuffer(buffer: Buffer | BufferReader): BaseOrMergeRollupPublicInputs {
const reader = BufferReader.asReader(buffer);
return new BaseRollupPublicInputs(
return new BaseOrMergeRollupPublicInputs(
reader.readNumber(),
reader.readFr(),
reader.readObject(AggregationObject),
reader.readObject(ConstantBaseRollupData),
reader.readObject(AppendOnlyTreeSnapshot),
Expand All @@ -211,6 +215,8 @@ export class BaseRollupPublicInputs {
*/
toBuffer() {
return serializeToBuffer(
this.rollupType,
this.rollupSubTreeHeight,
this.endAggregationObject,
this.constants,

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/structs/merge_rollup.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Fr } from '@aztec/foundation';
import { FieldsOf } from '../utils/jsUtils.js';
import { serializeToBuffer } from '../utils/serialize.js';
import { AppendOnlyTreeSnapshot, BaseRollupPublicInputs, ConstantBaseRollupData } from './base_rollup.js';
import { AppendOnlyTreeSnapshot, BaseOrMergeRollupPublicInputs, ConstantBaseRollupData } from './base_rollup.js';
import { ROLLUP_VK_TREE_HEIGHT } from './constants.js';
import { AggregationObject, MembershipWitness, RollupTypes, UInt32, UInt8Vector } from './shared.js';
import { VerificationKey } from './verification_key.js';

export class PreviousRollupData {
constructor(
public publicInputs: BaseRollupPublicInputs | MergeRollupPublicInputs,
public publicInputs: BaseOrMergeRollupPublicInputs | MergeRollupPublicInputs,
public proof: UInt8Vector,
public vk: VerificationKey,
/**
Expand Down
7 changes: 5 additions & 2 deletions yarn-project/circuits.js/src/tests/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import {
AppendOnlyTreeSnapshot,
BaseRollupInputs,
BaseRollupPublicInputs,
BaseOrMergeRollupPublicInputs,
ConstantBaseRollupData,
NullifierLeafPreimage,
} from '../structs/base_rollup.js';
Expand Down Expand Up @@ -57,6 +57,7 @@ import {
ComposerType,
EcdsaSignature,
MembershipWitness,
RollupTypes,
UInt8Vector,
} from '../structs/shared.js';
import { ContractDeploymentData, SignedTxRequest, TxContext, TxRequest } from '../structs/tx.js';
Expand Down Expand Up @@ -264,7 +265,9 @@ export function makeEcdsaSignature(seed = 1): EcdsaSignature {
}

export function makeBaseRollupPublicInputs(seed = 0) {
return new BaseRollupPublicInputs(
return new BaseOrMergeRollupPublicInputs(
RollupTypes.Base,
new Fr(0n),
makeAggregationObject(seed + 0x100),
makeConstantBaseRollupData(seed + 0x200),
makeAppendOnlyTreeSnapshot(seed + 0x300),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
AppendOnlyTreeSnapshot,
BaseRollupInputs,
BaseRollupPublicInputs,
BaseOrMergeRollupPublicInputs,
CircuitsWasm,
Fr,
RootRollupPublicInputs,
Expand All @@ -19,13 +19,14 @@ import { MockProxy, mock } from 'jest-mock-extended';
import { default as levelup } from 'levelup';
import flatMap from 'lodash.flatmap';
import { default as memdown } from 'memdown';
import { hashNewContractData, makeEmptyTx, makeEmptyUnverifiedData } from '../deps/tx.js';
import { makeEmptyTx, makeEmptyUnverifiedData } from '../deps/tx.js';
import { VerificationKeys, getVerificationKeys } from '../deps/verification_keys.js';
import { EmptyProver } from '../prover/empty.js';
import { Prover } from '../prover/index.js';
import { Simulator } from '../simulator/index.js';
import { WasmCircuitSimulator } from '../simulator/wasm.js';
import { CircuitPoweredBlockBuilder } from './circuit_powered_block_builder.js';
import { computeContractLeaf } from '@aztec/circuits.js/abis';

/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
Expand All @@ -41,8 +42,8 @@ describe('sequencer/circuit_block_builder', () => {
let prover: MockProxy<Prover>;

let blockNumber: number;
let baseRollupOutputLeft: BaseRollupPublicInputs;
let baseRollupOutputRight: BaseRollupPublicInputs;
let baseRollupOutputLeft: BaseOrMergeRollupPublicInputs;
let baseRollupOutputRight: BaseOrMergeRollupPublicInputs;
let rootRollupOutput: RootRollupPublicInputs;

let wasm: CircuitsWasm;
Expand Down Expand Up @@ -93,9 +94,12 @@ describe('sequencer/circuit_block_builder', () => {

// Updates the expectedDb trees based on the new commitments, contracts, and nullifiers from these txs
const updateExpectedTreesFromTxs = async (txs: Tx[]) => {
const newContracts = await Promise.all(
flatMap(txs, tx => tx.data.end.newContracts.map(async n => await computeContractLeaf(wasm, n))),
);
for (const [tree, leaves] of [
[MerkleTreeId.DATA_TREE, flatMap(txs, tx => tx.data.end.newCommitments.map(l => l.toBuffer()))],
[MerkleTreeId.CONTRACT_TREE, flatMap(txs, tx => tx.data.end.newContracts.map(n => hashNewContractData(wasm, n)))],
[MerkleTreeId.CONTRACT_TREE, newContracts.map(x => x.toBuffer())],
[MerkleTreeId.NULLIFIER_TREE, flatMap(txs, tx => tx.data.end.newNullifiers.map(l => l.toBuffer()))],
] as const) {
await expectsDb.appendLeaves(tree, leaves);
Expand Down
Loading