diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp index d6f60f98079..2ff668808ea 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp @@ -18,6 +18,11 @@ const std::vector three_operand_format = { OperandType::INDIRECT, OperandType::TAG, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32, }; +const std::vector getter_format = { + OperandType::INDIRECT, + OperandType::UINT32, +}; + // Contrary to TS, the format does not contain the opcode byte which prefixes any instruction. // The format for OpCode::SET has to be handled separately as it is variable based on the tag. const std::unordered_map> OPCODE_WIRE_FORMAT = { @@ -33,18 +38,38 @@ const std::unordered_map> OPCODE_WIRE_FORMAT = { OpCode::LT, three_operand_format }, { OpCode::LTE, three_operand_format }, // Compute - Bitwise - { OpCode::NOT, { OperandType::INDIRECT, OperandType::TAG, OperandType::UINT32, OperandType::UINT32 } }, { OpCode::AND, three_operand_format }, { OpCode::OR, three_operand_format }, { OpCode::XOR, three_operand_format }, - { OpCode::SHR, three_operand_format }, + { OpCode::NOT, { OperandType::INDIRECT, OperandType::TAG, OperandType::UINT32, OperandType::UINT32 } }, { OpCode::SHL, three_operand_format }, + { OpCode::SHR, three_operand_format }, // Compute - Type Conversions { OpCode::CAST, { OperandType::INDIRECT, OperandType::TAG, OperandType::UINT32, OperandType::UINT32 } }, + // Execution Environment - Globals + { OpCode::ADDRESS, getter_format }, + { OpCode::STORAGEADDRESS, getter_format }, + { OpCode::SENDER, getter_format }, + { OpCode::FEEPERL2GAS, getter_format }, + { OpCode::FEEPERDAGAS, getter_format }, + { OpCode::TRANSACTIONFEE, getter_format }, + // CONTRACTCALLDEPTH, -- not in simulator + // Execution Environment - Globals + { OpCode::CHAINID, getter_format }, + { OpCode::VERSION, getter_format }, + { OpCode::BLOCKNUMBER, getter_format }, + { OpCode::TIMESTAMP, getter_format }, + // COINBASE, -- not in simulator + // BLOCKL2GASLIMIT, -- not in simulator + // BLOCKDAGASLIMIT, -- not in simulator // Execution Environment - Calldata { OpCode::CALLDATACOPY, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, + // Machine State - Gas + { OpCode::L2GASLEFT, getter_format }, + { OpCode::DAGASLEFT, getter_format }, // Machine State - Internal Control Flow { OpCode::JUMP, { OperandType::UINT32 } }, + // JUMPI { OpCode::INTERNALCALL, { OperandType::UINT32 } }, { OpCode::INTERNALRETURN, {} }, // Machine State - Memory @@ -52,8 +77,33 @@ const std::unordered_map> OPCODE_WIRE_FORMAT = { OpCode::MOV, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32 } }, { OpCode::CMOV, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, + // World State + // SLOAD, + // SSTORE, + // NOTEHASHEXISTS, + // EMITNOTEHASH, + // NULLIFIEREXISTS, + // EMITNULLIFIER, + // L1TOL2MSGEXISTS, + // HEADERMEMBER, + // GETCONTRACTINSTANCE, + // Accrued Substate + // EMITUNENCRYPTEDLOG, + // SENDL2TOL1MSG, // Control Flow - Contract Calls + // CALL, + // STATICCALL, + // DELEGATECALL, -- not in simulator { OpCode::RETURN, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32 } }, + // REVERT, + // Misc + { OpCode::DEBUGLOG, + { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, + // Gadgets + // KECCAK, + // POSEIDON2, + // SHA256, + // PEDERSEN, // Gadget - Conversion { OpCode::TORADIXLE, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, @@ -200,4 +250,5 @@ std::vector Deserialization::parse(std::vector const& byte } return instructions; }; + } // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp index b7585d1f20d..36e338d359d 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp @@ -91,9 +91,7 @@ std::vector Execution::gen_trace(std::vector const& instructio // on opcode logic and therefore is not maintained here. However, the next opcode in the execution // is determined by this value which require read access to the code below. uint32_t pc = 0; - auto const inst_size = instructions.size(); - - while ((pc = trace_builder.getPc()) < inst_size) { + while ((pc = trace_builder.getPc()) < instructions.size()) { auto inst = instructions.at(pc); // TODO: We do not yet support the indirect flag. Therefore we do not extract @@ -275,6 +273,11 @@ std::vector Execution::gen_trace(std::vector const& instructio returndata.insert(returndata.end(), ret.begin(), ret.end()); break; } + case OpCode::DEBUGLOG: + // We want a noop, but we need to execute something that both advances the PC, + // and adds a valid row to the trace. + trace_builder.jump(pc + 1); + break; case OpCode::TORADIXLE: trace_builder.op_to_radix_le(std::get(inst.operands.at(0)), std::get(inst.operands.at(1)), @@ -283,6 +286,8 @@ std::vector Execution::gen_trace(std::vector const& instructio std::get(inst.operands.at(4))); break; default: + throw_or_abort("Don't know how to execute opcode " + to_hex(inst.op_code) + " at pc " + std::to_string(pc) + + "."); break; } } diff --git a/yarn-project/simulator/src/avm/serialization/bytecode_serialization.ts b/yarn-project/simulator/src/avm/serialization/bytecode_serialization.ts index d5b029cb103..f7906fffc26 100644 --- a/yarn-project/simulator/src/avm/serialization/bytecode_serialization.ts +++ b/yarn-project/simulator/src/avm/serialization/bytecode_serialization.ts @@ -136,7 +136,7 @@ const INSTRUCTION_SET = () => // Misc [DebugLog.opcode, DebugLog], - // //// Gadgets + // Gadgets [Keccak.opcode, Keccak], [Poseidon2.opcode, Poseidon2], [Sha256.opcode, Sha256],