-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial integration avm prover (#4878)
Basic shim to integrate avm simulator with the avm witgen/prover. Currently uses the bb binary and supports proving(including passing in calldata) and verifying (although both are currently WIP in the avm prover). Built on top of #4877
- Loading branch information
1 parent
f6d17c9
commit 2e2554e
Showing
10 changed files
with
304 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ node_modules | |
.tsbuildinfo | ||
tsconfig.tsbuildinfo | ||
.eslintcache | ||
simulator/target | ||
|
||
.yarn/* | ||
!.yarn/patches | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { AztecAddress, CallContext, EthAddress, FunctionData, FunctionSelector, Header } from '@aztec/circuits.js'; | ||
import { makeHeader } from '@aztec/circuits.js/testing'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
import { AvmTestContractArtifact } from '@aztec/noir-contracts.js'; | ||
|
||
import { MockProxy, mock } from 'jest-mock-extended'; | ||
|
||
import { CommitmentsDB, PublicContractsDB, PublicStateDB } from './db.js'; | ||
import { PublicExecution } from './execution.js'; | ||
import { PublicExecutor } from './executor.js'; | ||
|
||
describe('AVM WitGen and Proof Generation', () => { | ||
let publicState: MockProxy<PublicStateDB>; | ||
let publicContracts: MockProxy<PublicContractsDB>; | ||
let commitmentsDb: MockProxy<CommitmentsDB>; | ||
let header: Header; | ||
|
||
const callContext = CallContext.from({ | ||
msgSender: AztecAddress.random(), | ||
storageContractAddress: AztecAddress.random(), | ||
portalContractAddress: EthAddress.random(), | ||
functionSelector: FunctionSelector.empty(), | ||
isContractDeployment: false, | ||
isDelegateCall: false, | ||
isStaticCall: false, | ||
startSideEffectCounter: 0, | ||
}); | ||
const contractAddress = AztecAddress.random(); | ||
|
||
beforeEach(() => { | ||
publicState = mock<PublicStateDB>(); | ||
publicContracts = mock<PublicContractsDB>(); | ||
commitmentsDb = mock<CommitmentsDB>(); | ||
|
||
const randomInt = Math.floor(Math.random() * 1000000); | ||
header = makeHeader(randomInt); | ||
}, 10000); | ||
|
||
it('Should prove valid execution of bytecode that performs addition', async () => { | ||
const args: Fr[] = [new Fr(1), new Fr(2)]; | ||
// Bytecode for the following contract is encoded: | ||
// const bytecode = encodeToBytecode([ | ||
// new CalldataCopy(/*indirect=*/ 0, /*cdOffset=*/ 0, /*copySize=*/ 2, /*dstOffset=*/ 0), | ||
// new Add(/*indirect=*/ 0, TypeTag.FIELD, /*aOffset=*/ 0, /*bOffset=*/ 1, /*dstOffset=*/ 2), | ||
// new Return(/*indirect=*/ 0, /*returnOffset=*/ 2, /*copySize=*/ 1), | ||
// ]); | ||
const bytecode: Buffer = Buffer.from('HwAAAAAAAAAAAgAAAAAAAAYAAAAAAAAAAQAAAAI3AAAAAAIAAAAB', 'base64'); | ||
publicContracts.getBytecode.mockResolvedValue(bytecode); | ||
const executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); | ||
const functionData = FunctionData.empty(); | ||
const execution: PublicExecution = { contractAddress, functionData, args, callContext }; | ||
const [proof, vk] = await executor.getAvmProof(execution); | ||
const valid = await executor.verifyAvmProof(vk, proof); | ||
expect(valid).toBe(true); | ||
}); | ||
|
||
// This is skipped as we require MOV to be implemented in the AVM | ||
it.skip('Should prove valid execution contract function that performs addition', async () => { | ||
const args: Fr[] = [new Fr(1), new Fr(2)]; | ||
|
||
const addArtifact = AvmTestContractArtifact.functions.find(f => f.name === 'avm_addArgsReturn')!; | ||
const bytecode = Buffer.from(addArtifact.bytecode, 'base64'); | ||
publicContracts.getBytecode.mockResolvedValue(bytecode); | ||
const functionData = FunctionData.fromAbi(addArtifact); | ||
const execution: PublicExecution = { contractAddress, functionData, args, callContext }; | ||
|
||
const executor = new PublicExecutor(publicState, publicContracts, commitmentsDb, header); | ||
const [proof, vk] = await executor.getAvmProof(execution); | ||
const valid = await executor.verifyAvmProof(vk, proof); | ||
expect(valid).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.