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: enable avm contract test #5497

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace bb::avm_trace {
class AvmMemTraceBuilder {

public:
static const size_t MEM_SIZE = 1024;
static const size_t MEM_SIZE = 2048;
static const uint32_t SUB_CLK_IND_LOAD_A = 0;
static const uint32_t SUB_CLK_IND_LOAD_B = 1;
static const uint32_t SUB_CLK_IND_LOAD_C = 2;
Expand Down Expand Up @@ -101,4 +101,4 @@ class AvmMemTraceBuilder {
void store_in_mem_trace(
uint32_t clk, IntermRegister interm_reg, uint32_t addr, FF const& val, AvmMemoryTag m_in_tag);
};
} // namespace bb::avm_trace
} // namespace bb::avm_trace
22 changes: 2 additions & 20 deletions yarn-project/simulator/src/public/avm_executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,16 @@ describe('AVM WitGen and Proof Generation', () => {
header = makeHeader(randomInt(1000000));
}, 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('IAAAAAAAAAAAAgAAAAAAAAYAAAAAAAAAAQAAAAI4AAAAAAIAAAAB', '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)];
it('Should prove valid execution contract function that performs addition', async () => {
const args: Fr[] = [new Fr(99), new Fr(12)];

const addArtifact = AvmTestContractArtifact.functions.find(f => f.name === 'add_args_return')!;
const bytecode = addArtifact.bytecode;
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);
Expand Down
1 change: 1 addition & 0 deletions yarn-project/simulator/src/public/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export class PublicExecutor {

// Create the directory if it does not exist
await fs.mkdir(artifactsPath, { recursive: true });
await fs.rm(artifactsPath, { recursive: true, force: true });

const calldataPath = path.join(artifactsPath, 'calldata.bin');
const bytecodePath = path.join(artifactsPath, 'avm_bytecode.bin');
Expand Down
Loading