From 620d3dacc853c71e808ef58001eb4c8584fa59d9 Mon Sep 17 00:00:00 2001 From: Ilyas Ridhuan Date: Wed, 5 Jun 2024 17:27:40 +0100 Subject: [PATCH] feat(avm): revert opcode (#6909) --- .../src/barretenberg/vm/avm_trace/avm_deserialization.cpp | 1 + .../cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp | 5 +++++ .../cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp | 6 ++++++ .../cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp | 2 ++ 4 files changed, 14 insertions(+) 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 1a6554fb8ac..49cf55d0ee2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp @@ -133,6 +133,7 @@ const std::unordered_map> OPCODE_WIRE_FORMAT = // DELEGATECALL, -- not in simulator { OpCode::RETURN, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32 } }, // REVERT, + { OpCode::REVERT, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32 } }, // Misc { OpCode::DEBUGLOG, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, 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 12a4d1b611a..4aa6c03603c 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp @@ -635,6 +635,11 @@ std::vector Execution::gen_trace(std::vector const& instructio std::get(inst.operands.at(3)), std::get(inst.operands.at(4))); break; + case OpCode::REVERT: + trace_builder.op_revert(std::get(inst.operands.at(0)), + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2))); + break; default: throw_or_abort("Don't know how to execute opcode " + to_hex(inst.op_code) + " at pc " + std::to_string(pc) + "."); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp index d45c7967fd4..daaea2106ca 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp @@ -1843,6 +1843,12 @@ void AvmTraceBuilder::calldata_copy( pc++; } +// Credit to SEAN for coming up with this revert opcode +std::vector AvmTraceBuilder::op_revert(uint8_t indirect, uint32_t ret_offset, uint32_t ret_size) +{ + return return_op(indirect, ret_offset, ret_size); +} + /** * @brief RETURN opcode with direct and indirect memory access, i.e., * direct: return(M[ret_offset:ret_offset+ret_size]) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp index b641fc78836..63a68316433 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp @@ -153,6 +153,8 @@ class AvmTraceBuilder { uint32_t dst_offset, std::vector const& call_data_mem); + // REVERT Opcode (that just call return under the hood for now) + std::vector op_revert(uint8_t indirect, uint32_t ret_offset, uint32_t ret_size); // RETURN opcode with direct and indirect memory access, i.e., // direct: return(M[ret_offset:ret_offset+ret_size]) // indirect: return(M[M[ret_offset]:M[ret_offset]+ret_size])