Skip to content

Commit

Permalink
feat(avm): revert opcode (#6909)
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasRidhuan authored Jun 5, 2024
1 parent c3746f5 commit 620d3da
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const std::unordered_map<OpCode, std::vector<OperandType>> 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 } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@ std::vector<Row> Execution::gen_trace(std::vector<Instruction> const& instructio
std::get<uint32_t>(inst.operands.at(3)),
std::get<uint32_t>(inst.operands.at(4)));
break;
case OpCode::REVERT:
trace_builder.op_revert(std::get<uint8_t>(inst.operands.at(0)),
std::get<uint32_t>(inst.operands.at(1)),
std::get<uint32_t>(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) +
".");
Expand Down
6 changes: 6 additions & 0 deletions barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,12 @@ void AvmTraceBuilder::calldata_copy(
pc++;
}

// Credit to SEAN for coming up with this revert opcode
std::vector<FF> 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])
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class AvmTraceBuilder {
uint32_t dst_offset,
std::vector<FF> const& call_data_mem);

// REVERT Opcode (that just call return under the hood for now)
std::vector<FF> 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])
Expand Down

0 comments on commit 620d3da

Please sign in to comment.