Skip to content
Merged
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
11 changes: 0 additions & 11 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,17 +475,6 @@ pub fn brillig_to_avm(brillig_bytecode: &[BrilligOpcode<FieldElement>]) -> (Vec<
*value = resolved_location;
}

// TEMPORARY: Add a "magic number" instruction to the end of the program.
// This makes it possible to know that the bytecode corresponds to the AVM.
// We are adding a MOV instruction that moves a value to itself.
// This should therefore not affect the program's execution.
avm_instrs.push(AvmInstruction {
opcode: AvmOpcode::MOV_16,
indirect: Some(AddressingModeBuilder::default().build()),
operands: vec![AvmOperand::U16 { value: 0x18ca }, AvmOperand::U16 { value: 0x18ca }],
..Default::default()
});

dbg_print_avm_program(&avm_instrs);

// Constructing bytecode from instructions
Expand Down
18 changes: 4 additions & 14 deletions yarn-project/simulator/src/public/avm/avm_simulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import type { AvmContext } from './avm_context.js';
import type { AvmExecutionEnvironment } from './avm_execution_environment.js';
import { type MemoryValue, TypeTag, type Uint8, type Uint64 } from './avm_memory_types.js';
import { AvmSimulator } from './avm_simulator.js';
import { isAvmBytecode, markBytecodeAsAvm } from './bytecode_utils.js';
import {
getAvmGadgetsTestContractBytecode,
getAvmTestContractArtifact,
Expand Down Expand Up @@ -108,13 +107,9 @@ describe('AVM simulator: injected bytecode', () => {
]);
});

it('Should not be recognized as AVM bytecode (magic missing)', () => {
expect(!isAvmBytecode(bytecode));
});

it('Should execute bytecode that performs basic addition', async () => {
const context = initContext({ env: initExecutionEnvironment({ calldata }) });
const results = await new AvmSimulator(context).executeBytecode(markBytecodeAsAvm(bytecode));
const results = await new AvmSimulator(context).executeBytecode(bytecode);

expect(results.reverted).toBe(false);
expect(results.output).toEqual([new Fr(3)]);
Expand All @@ -126,7 +121,7 @@ describe('AVM simulator: injected bytecode', () => {
machineState: initMachineState({ l2GasLeft: 5 }),
});

const results = await new AvmSimulator(context).executeBytecode(markBytecodeAsAvm(bytecode));
const results = await new AvmSimulator(context).executeBytecode(bytecode);
expect(results.reverted).toBe(true);
expect(results.output).toEqual([]);
expect(results.revertReason?.message).toEqual('Not enough L2GAS gas left');
Expand All @@ -141,7 +136,7 @@ describe('AVM simulator: injected bytecode', () => {
const badBytecode = encodeToBytecode([
new Div(/*indirect=*/ 0, /*aOffset=*/ 0, /*bOffset=*/ 0, /*dstOffset=*/ 0).as(Opcode.DIV_8, Div.wireFormat8),
]);
const results = await new AvmSimulator(context).executeBytecode(markBytecodeAsAvm(badBytecode));
const results = await new AvmSimulator(context).executeBytecode(badBytecode);
expect(results.reverted).toBe(true);
expect(results.output).toEqual([]);
expect(results.revertReason?.message).toMatch(/Tag mismatch/);
Expand Down Expand Up @@ -212,11 +207,6 @@ describe('AVM simulator: transpiled Noir contracts', () => {
expect(results.output).toEqual([new Fr(0)]);
});

it('Should be recognized as AVM bytecode (magic present)', () => {
const bytecode = getAvmTestContractBytecode('add_args_return');
expect(isAvmBytecode(bytecode));
});

it('Should handle calldata oracle', async () => {
const calldata: Fr[] = [new Fr(1), new Fr(2), new Fr(3)];
const context = initContext({ env: initExecutionEnvironment({ calldata }) });
Expand Down Expand Up @@ -1093,7 +1083,7 @@ describe('AVM simulator: transpiled Noir contracts', () => {
new Jump(/*jumpOffset*/ 15),
]);
const context = initContext({ persistableState });
const results = await new AvmSimulator(context).executeBytecode(markBytecodeAsAvm(bytecode));
const results = await new AvmSimulator(context).executeBytecode(bytecode);
expect(results.reverted).toBe(true);
expect(results.output).toEqual([]);
expect(results.revertReason?.message).toMatch('Reached the limit');
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/simulator/src/public/avm/avm_simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { AvmContractCallResult } from './avm_contract_call_result.js';
import { AvmExecutionEnvironment } from './avm_execution_environment.js';
import type { Gas } from './avm_gas.js';
import { AvmMachineState } from './avm_machine_state.js';
import { isAvmBytecode } from './bytecode_utils.js';
import {
AvmExecutionError,
AvmRevertReason,
Expand Down Expand Up @@ -139,7 +138,6 @@ export class AvmSimulator {
*/
public async executeBytecode(bytecode: Buffer): Promise<AvmContractCallResult> {
const startTotalTime = performance.now();
assert(isAvmBytecode(bytecode), "AVM simulator can't execute non-AVM bytecode");
assert(bytecode.length > 0, "AVM simulator can't execute empty bytecode");

this.bytecode = bytecode;
Expand Down
17 changes: 0 additions & 17 deletions yarn-project/simulator/src/public/avm/bytecode_utils.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type { PublicSideEffectTraceInterface } from '../../../public/side_effect
import type { PublicContractsDB, PublicTreesDB } from '../../public_db_sources.js';
import type { AvmContext } from '../avm_context.js';
import { Field, TypeTag, Uint1, Uint32 } from '../avm_memory_types.js';
import { markBytecodeAsAvm } from '../bytecode_utils.js';
import { initContext, initPersistableStateManager } from '../fixtures/index.js';
import type { AvmPersistableStateManager } from '../journal/journal.js';
import { encodeToBytecode } from '../serialization/bytecode_serialization.js';
Expand Down Expand Up @@ -118,16 +117,13 @@ describe('External Calls', () => {
// Define dst offset for SuccessCopy
const successDstOffset = 6;

const otherContextInstructionsBytecode = markBytecodeAsAvm(
encodeToBytecode([
new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, 0).as(Opcode.SET_8, Set.wireFormat8),
new Set(/*indirect=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT32, argsSize).as(Opcode.SET_8, Set.wireFormat8),
new Set(/*indirect=*/ 0, /*dstOffset=*/ 2, TypeTag.UINT32, 2).as(Opcode.SET_8, Set.wireFormat8),
new CalldataCopy(/*indirect=*/ 0, /*csOffsetAddress=*/ 0, /*copySizeOffset=*/ 1, /*dstOffset=*/ 3),
new Return(/*indirect=*/ 0, /*retOffset=*/ 3, /*sizeOffset=*/ 2),
]),
);

const otherContextInstructionsBytecode = encodeToBytecode([
new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, 0).as(Opcode.SET_8, Set.wireFormat8),
new Set(/*indirect=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT32, argsSize).as(Opcode.SET_8, Set.wireFormat8),
new Set(/*indirect=*/ 0, /*dstOffset=*/ 2, TypeTag.UINT32, 2).as(Opcode.SET_8, Set.wireFormat8),
new CalldataCopy(/*indirect=*/ 0, /*csOffsetAddress=*/ 0, /*copySizeOffset=*/ 1, /*dstOffset=*/ 3),
new Return(/*indirect=*/ 0, /*retOffset=*/ 3, /*sizeOffset=*/ 2),
]);
const contractClass = await makeContractClassPublic(0, {
bytecode: otherContextInstructionsBytecode,
selector: FunctionSelector.random(),
Expand Down Expand Up @@ -174,16 +170,14 @@ describe('External Calls', () => {
// Define dst offset for SuccessCopy
const successDstOffset = 6;

const otherContextInstructionsBytecode = markBytecodeAsAvm(
encodeToBytecode([
new GetEnvVar(/*indirect=*/ 0, /*dstOffset=*/ 0, /*envVar=*/ EnvironmentVariable.L2GASLEFT).as(
Opcode.GETENVVAR_16,
GetEnvVar.wireFormat16,
),
new Set(/*indirect=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT32, 1).as(Opcode.SET_8, Set.wireFormat8),
new Return(/*indirect=*/ 0, /*retOffset=*/ 0, /*size=*/ 1),
]),
);
const otherContextInstructionsBytecode = encodeToBytecode([
new GetEnvVar(/*indirect=*/ 0, /*dstOffset=*/ 0, /*envVar=*/ EnvironmentVariable.L2GASLEFT).as(
Opcode.GETENVVAR_16,
GetEnvVar.wireFormat16,
),
new Set(/*indirect=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT32, 1).as(Opcode.SET_8, Set.wireFormat8),
new Return(/*indirect=*/ 0, /*retOffset=*/ 0, /*size=*/ 1),
]);
mockGetNullifierIndex(treesDB, addr);

const contractClass = await makeContractClassPublic(0, {
Expand Down Expand Up @@ -264,7 +258,7 @@ describe('External Calls', () => {
new SStore(/*indirect=*/ 0, /*srcOffset=*/ 0, /*slotOffset=*/ 0),
];

const otherContextInstructionsBytecode = markBytecodeAsAvm(encodeToBytecode(otherContextInstructions));
const otherContextInstructionsBytecode = encodeToBytecode(otherContextInstructions);
mockGetNullifierIndex(treesDB, addr.toFr());

const contractClass = await makeContractClassPublic(0, {
Expand Down