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

feat!: call stack validation optimisation. #3387

Merged
merged 27 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b9c103a
Array utils.
LeilaWang Nov 16, 2023
1550bb1
No need to check the format of the arrays from previous kernel.
LeilaWang Nov 16, 2023
8f6a3f8
Remove unnecessary array length checks.
LeilaWang Nov 16, 2023
ee48cce
Remove tests for previous arrays format.
LeilaWang Nov 16, 2023
2acac30
Optimise call stack checks.
LeilaWang Nov 16, 2023
43395b8
Don't push to private call stack for tests by default.
LeilaWang Nov 17, 2023
3057ed6
Use self in a struct.
LeilaWang Nov 17, 2023
1e6a217
Optimise and fix private call stack validation.
LeilaWang Nov 18, 2023
1ff7ce6
Optimise call stack checks for public kernels.
LeilaWang Nov 20, 2023
2e095ff
Move test data builder to tests folder.
LeilaWang Nov 20, 2023
c89539b
Fix test data.
LeilaWang Nov 20, 2023
d039a0b
Update artifects.
LeilaWang Nov 21, 2023
f8b620d
Remove cpp kernel sims.
LeilaWang Nov 21, 2023
ea72b44
Stop generating types from cpp.
LeilaWang Nov 21, 2023
b66f8c4
Regenerate artifacts.
LeilaWang Nov 21, 2023
18f78f9
Update ts structs and types.
LeilaWang Nov 21, 2023
1d4542f
Fix call stack item data.
LeilaWang Nov 22, 2023
601da61
Don't expose caller context for regular calls.
LeilaWang Nov 22, 2023
2758d6b
Update artifacts.
LeilaWang Nov 22, 2023
6b2de46
Use CallRequest.
LeilaWang Nov 22, 2023
4bd9206
Fix.
LeilaWang Nov 23, 2023
899bc04
Checks for static calls.
LeilaWang Nov 23, 2023
ff4b4ac
Add tests for call requests.
LeilaWang Nov 23, 2023
bf56c0e
Merge remote-tracking branch 'origin/master' into lw/kernel_refactor
LeilaWang Nov 23, 2023
7db1f64
Fix test.
LeilaWang Nov 23, 2023
a21d960
Merge remote-tracking branch 'origin/master' into lw/kernel_refactor
LeilaWang Nov 24, 2023
fd5d826
Rename fn.
LeilaWang Nov 27, 2023
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
4 changes: 2 additions & 2 deletions yarn-project/acir-simulator/src/acvm/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ export function toACVMPublicInputs(publicInputs: PrivateCircuitPublicInputs): AC
...publicInputs.newCommitments.map(toACVMField),
...publicInputs.newNullifiers.map(toACVMField),
...publicInputs.nullifiedCommitments.map(toACVMField),
...publicInputs.privateCallStack.map(toACVMField),
...publicInputs.publicCallStack.map(toACVMField),
...publicInputs.privateCallStackHashes.map(toACVMField),
...publicInputs.publicCallStackHashes.map(toACVMField),
...publicInputs.newL2ToL1Msgs.map(toACVMField),
...publicInputs.encryptedLogsHash.map(toACVMField),
...publicInputs.unencryptedLogsHash.map(toACVMField),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
TxContext,
} from '@aztec/circuits.js';
import {
computeCallStackItemHash,
computeCommitmentNonce,
computeSecretMessageHash,
computeVarArgsHash,
Expand Down Expand Up @@ -371,8 +370,8 @@ describe('Private Execution test suite', () => {
expect(result.nestedExecutions[0].callStackItem.publicInputs.returnValues[0]).toEqual(new Fr(privateIncrement));

// check that Aztec.nr calculated the call stack item hash like cpp does
const expectedCallStackItemHash = computeCallStackItemHash(result.nestedExecutions[0].callStackItem);
expect(result.callStackItem.publicInputs.privateCallStack[0]).toEqual(expectedCallStackItemHash);
const expectedCallStackItemHash = result.nestedExecutions[0].callStackItem.hash();
expect(result.callStackItem.publicInputs.privateCallStackHashes[0]).toEqual(expectedCallStackItemHash);
});
});

Expand Down Expand Up @@ -557,11 +556,11 @@ describe('Private Execution test suite', () => {
sideEffectCounter: 0,
});

const publicCallRequestHash = computeCallStackItemHash(publicCallRequest.toPublicCallStackItem());
const publicCallRequestHash = publicCallRequest.toPublicCallStackItem().hash();

expect(result.enqueuedPublicFunctionCalls).toHaveLength(1);
expect(result.enqueuedPublicFunctionCalls[0]).toEqual(publicCallRequest);
expect(result.callStackItem.publicInputs.publicCallStack[0]).toEqual(publicCallRequestHash);
expect(result.callStackItem.publicInputs.publicCallStackHashes[0]).toEqual(publicCallRequestHash);
});
});

Expand Down
3 changes: 1 addition & 2 deletions yarn-project/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ for package in "@aztec/foundation" "@aztec/noir-compiler"; do
yarn workspace $package build
done

# Run remake bindings before building Aztec.nr contracts or l1 contracts as they depend on files created by it.
yarn workspace @aztec/circuits.js remake-bindings
# Run remake constants before building Aztec.nr contracts or l1 contracts as they depend on files created by it.
yarn workspace @aztec/circuits.js remake-constants

(cd noir-contracts && ./bootstrap.sh)
Expand Down
1 change: 0 additions & 1 deletion yarn-project/circuits.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"clean": "rm -rf ./dest .tsbuildinfo",
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"remake-bindings": "DEBUG=wasm ts-node-esm src/cbind/circuits.in.ts && prettier -w src/cbind/circuits.gen.ts",
"remake-constants": "ts-node-esm src/cbind/constants.in.ts && prettier -w src/cbind/constants.gen.ts",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
},
Expand Down
7 changes: 4 additions & 3 deletions yarn-project/circuits.js/src/abis/abis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from '../tests/factories.js';
import {
computeBlockHashWithGlobals,
computeCallStackItemHash,
computeCommitmentNonce,
computeCompleteAddress,
computeContractAddressFromPartial,
Expand All @@ -29,6 +28,8 @@ import {
computeFunctionSelector,
computeFunctionTreeRoot,
computeGlobalsHash,
computePrivateCallStackItemHash,
computePublicCallStackItemHash,
computePublicDataTreeIndex,
computePublicDataTreeValue,
computeSecretMessageHash,
Expand Down Expand Up @@ -209,13 +210,13 @@ describe('abis wasm bindings', () => {

it('compute private call stack item hash', () => {
const item = makePrivateCallStackItem();
const hash = computeCallStackItemHash(item);
const hash = computePrivateCallStackItemHash(item);
expect(hash).toMatchSnapshot();
});

it('compute public call stack item hash', () => {
const item = makePublicCallStackItem();
const hash = computeCallStackItemHash(item);
const hash = computePublicCallStackItemHash(item);
expect(hash).toMatchSnapshot();
});

Expand Down
21 changes: 3 additions & 18 deletions yarn-project/circuits.js/src/abis/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,21 +490,6 @@ function computeContractDeploymentDataHash(data: ContractDeploymentData): Fr {
);
}

/**
* Computes a call stack item hash.
* @param callStackItem - The call stack item.
* @returns The call stack item hash.
*/
export function computeCallStackItemHash(callStackItem: PrivateCallStackItem | PublicCallStackItem): Fr {
if (callStackItem instanceof PrivateCallStackItem) {
return computePrivateCallStackItemHash(callStackItem);
} else if (callStackItem instanceof PublicCallStackItem) {
return computePublicCallStackItemHash(callStackItem);
} else {
throw new Error(`Unexpected call stack item type`);
}
}

/**
*
*/
Expand Down Expand Up @@ -536,8 +521,8 @@ function computePrivateInputsHash(input: PrivateCircuitPublicInputs) {
...input.newCommitments.map(fr => fr.toBuffer()),
...input.newNullifiers.map(fr => fr.toBuffer()),
...input.nullifiedCommitments.map(fr => fr.toBuffer()),
...input.privateCallStack.map(fr => fr.toBuffer()),
...input.publicCallStack.map(fr => fr.toBuffer()),
...input.privateCallStackHashes.map(fr => fr.toBuffer()),
...input.publicCallStackHashes.map(fr => fr.toBuffer()),
...input.newL2ToL1Msgs.map(fr => fr.toBuffer()),
...input.encryptedLogsHash.map(fr => fr.toBuffer()),
...input.unencryptedLogsHash.map(fr => fr.toBuffer()),
Expand Down Expand Up @@ -605,7 +590,7 @@ function computePublicInputsHash(input: PublicCircuitPublicInputs) {
...input.returnValues.map(fr => fr.toBuffer()),
...input.contractStorageUpdateRequests.map(computeContractStorageUpdateRequestHash),
...input.contractStorageReads.map(computeContractStorageReadsHash),
...input.publicCallStack.map(fr => fr.toBuffer()),
...input.publicCallStackHashes.map(fr => fr.toBuffer()),
...input.newCommitments.map(fr => fr.toBuffer()),
...input.newNullifiers.map(fr => fr.toBuffer()),
...input.newL2ToL1Msgs.map(fr => fr.toBuffer()),
Expand Down
Loading