Skip to content

Commit

Permalink
2096 - activate new cbind wrappers in the simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmon committed Sep 14, 2023
1 parent 3c0ae9b commit d33de03
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 35 deletions.
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/rollup/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './rollup_wasm_wrapper.js';
export { baseRollupSim, mergeRollupSim, rootRollupSim } from '../cbind/circuits.gen.js';
21 changes: 13 additions & 8 deletions yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import {
AggregationObject,
BaseOrMergeRollupPublicInputs,
CircuitError,
MergeRollupInputs,
RootRollupInputs,
RootRollupPublicInputs,
VerificationKey,
baseRollupSim,
mergeRollupSim,
rootRollupSim,
} from '../index.js';
import { makeBaseRollupInputs, makeMergeRollupInputs, makeRootRollupInputs } from '../tests/factories.js';
import { CircuitsWasm } from '../wasm/circuits_wasm.js';
import { RollupWasmWrapper, mergeRollupSim, rootRollupSim } from './rollup_wasm_wrapper.js';

describe('rollup/rollup_wasm_wrapper', () => {
let wasm: CircuitsWasm;
let rollupWasm: RollupWasmWrapper;

beforeAll(async () => {
wasm = await CircuitsWasm.get();
rollupWasm = new RollupWasmWrapper(wasm);
});

const makeBaseRollupInputsForCircuit = () => {
Expand Down Expand Up @@ -54,11 +55,13 @@ describe('rollup/rollup_wasm_wrapper', () => {
// Task to repair this test: https://github.com/AztecProtocol/aztec-packages/issues/1586
it.skip('calls base_rollup__sim', () => {
const input = makeBaseRollupInputsForCircuit();
const output = baseRollupSim(wasm, input);
expect(output instanceof BaseOrMergeRollupPublicInputs).toBeTruthy();

const output = rollupWasm.simulateBaseRollup(input);
expect(output.startContractTreeSnapshot).toEqual(input.startContractTreeSnapshot);
expect(output.startNullifierTreeSnapshot).toEqual(input.startNullifierTreeSnapshot);
expect(output.startPrivateDataTreeSnapshot).toEqual(input.startPrivateDataTreeSnapshot);
const publicInputs = output as BaseOrMergeRollupPublicInputs;
expect(publicInputs.startContractTreeSnapshot).toEqual(input.startContractTreeSnapshot);
expect(publicInputs.startNullifierTreeSnapshot).toEqual(input.startNullifierTreeSnapshot);
expect(publicInputs.startPrivateDataTreeSnapshot).toEqual(input.startPrivateDataTreeSnapshot);
});

it('calls merge_rollup__sim', () => {
Expand Down Expand Up @@ -104,7 +107,9 @@ describe('rollup/rollup_wasm_wrapper', () => {
for (const rd of input.previousRollupData) {
rd.vk = VerificationKey.makeFake();
rd.baseOrMergeRollupPublicInputs.endAggregationObject = AggregationObject.makeFake();
rd.baseOrMergeRollupPublicInputs = rollupWasm.simulateBaseRollup(makeBaseRollupInputsForCircuit());
const output = baseRollupSim(wasm, makeBaseRollupInputsForCircuit());
expect(output instanceof BaseOrMergeRollupPublicInputs).toBeTruthy();
rd.baseOrMergeRollupPublicInputs = output as BaseOrMergeRollupPublicInputs;
}
fixPreviousRollupInputs(input);

Expand Down
22 changes: 0 additions & 22 deletions yarn-project/circuits.js/src/rollup/rollup_wasm_wrapper.ts

This file was deleted.

11 changes: 7 additions & 4 deletions yarn-project/sequencer-client/src/simulator/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
CircuitError,
CircuitsWasm,
MergeRollupInputs,
RollupWasmWrapper,
RootRollupInputs,
RootRollupPublicInputs,
baseRollupSim,
mergeRollupSim,
rootRollupSim,
} from '@aztec/circuits.js';
Expand All @@ -17,11 +17,9 @@ import { RollupSimulator } from './index.js';
* Implements the rollup circuit simulator using the wasm circuits implementation.
*/
export class WasmRollupCircuitSimulator implements RollupSimulator {
private rollupWasmWrapper: RollupWasmWrapper;
private wasm: CircuitsWasm;

constructor(wasm: CircuitsWasm) {
this.rollupWasmWrapper = new RollupWasmWrapper(wasm);
this.wasm = wasm;
}

Expand All @@ -39,7 +37,12 @@ export class WasmRollupCircuitSimulator implements RollupSimulator {
* @returns The public inputs as outputs of the simulation.
*/
baseRollupCircuit(input: BaseRollupInputs): Promise<BaseOrMergeRollupPublicInputs> {
return Promise.resolve(this.rollupWasmWrapper.simulateBaseRollup(input));
const result = baseRollupSim(this.wasm, input);
if (result instanceof CircuitError) {
throw new CircuitError(result.code, result.message);
}

return Promise.resolve(result);
}
/**
* Simulates the merge rollup circuit from its inputs.
Expand Down

0 comments on commit d33de03

Please sign in to comment.