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(avm): Indirect memory support for arithmetic/bitwise opcodes #5328

Merged
merged 4 commits into from
Mar 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ template <typename PCS> class ZeroMorphVerifier_ {
using Curve = typename PCS::Curve;
using FF = typename Curve::ScalarField;
using Commitment = typename Curve::AffineElement;
using VerifierAccumulator = PCS::VerifierAccumulator;
using VerifierAccumulator = typename PCS::VerifierAccumulator;

public:
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,38 +101,44 @@ std::vector<Row> Execution::gen_trace(std::vector<Instruction> const& instructio
// Compute
// Compute - Arithmetic
case OpCode::ADD:
trace_builder.op_add(std::get<uint32_t>(inst.operands.at(2)),
trace_builder.op_add(std::get<uint8_t>(inst.operands.at(0)),
std::get<uint32_t>(inst.operands.at(2)),
std::get<uint32_t>(inst.operands.at(3)),
std::get<uint32_t>(inst.operands.at(4)),
std::get<AvmMemoryTag>(inst.operands.at(1)));
break;
case OpCode::SUB:
trace_builder.op_sub(std::get<uint32_t>(inst.operands.at(2)),
trace_builder.op_sub(std::get<uint8_t>(inst.operands.at(0)),
std::get<uint32_t>(inst.operands.at(2)),
std::get<uint32_t>(inst.operands.at(3)),
std::get<uint32_t>(inst.operands.at(4)),
std::get<AvmMemoryTag>(inst.operands.at(1)));
break;
case OpCode::MUL:
trace_builder.op_mul(std::get<uint32_t>(inst.operands.at(2)),
trace_builder.op_mul(std::get<uint8_t>(inst.operands.at(0)),
std::get<uint32_t>(inst.operands.at(2)),
std::get<uint32_t>(inst.operands.at(3)),
std::get<uint32_t>(inst.operands.at(4)),
std::get<AvmMemoryTag>(inst.operands.at(1)));
break;
case OpCode::DIV:
trace_builder.op_div(std::get<uint32_t>(inst.operands.at(2)),
trace_builder.op_div(std::get<uint8_t>(inst.operands.at(0)),
std::get<uint32_t>(inst.operands.at(2)),
std::get<uint32_t>(inst.operands.at(3)),
std::get<uint32_t>(inst.operands.at(4)),
std::get<AvmMemoryTag>(inst.operands.at(1)));
break;
// Compute - Bitwise
case OpCode::NOT:
trace_builder.op_not(std::get<uint32_t>(inst.operands.at(2)),
trace_builder.op_not(std::get<uint8_t>(inst.operands.at(0)),
std::get<uint32_t>(inst.operands.at(2)),
std::get<uint32_t>(inst.operands.at(4)),
std::get<AvmMemoryTag>(inst.operands.at(1)));
break;
// Execution Environment - Calldata
case OpCode::CALLDATACOPY:
trace_builder.calldata_copy(std::get<uint32_t>(inst.operands.at(1)),
trace_builder.calldata_copy(std::get<uint8_t>(inst.operands.at(0)),
std::get<uint32_t>(inst.operands.at(1)),
std::get<uint32_t>(inst.operands.at(2)),
std::get<uint32_t>(inst.operands.at(3)),
calldata);
Expand Down Expand Up @@ -185,8 +191,9 @@ std::vector<Row> Execution::gen_trace(std::vector<Instruction> const& instructio
break;
// Control Flow - Contract Calls
case OpCode::RETURN:
// Skip indirect at index 0
trace_builder.return_op(std::get<uint32_t>(inst.operands.at(1)), std::get<uint32_t>(inst.operands.at(2)));
trace_builder.return_op(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:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,13 @@ void log_avm_trace(std::vector<Row> const& trace, size_t beg, size_t end, bool e
}
}

bool is_operand_indirect(uint8_t ind_value, uint8_t operand_idx)
{
if (operand_idx > 7) {
return false;
}

return static_cast<bool>((ind_value & (1 << operand_idx)) >> operand_idx);
}

} // namespace bb::avm_trace
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ namespace bb::avm_trace {

void log_avm_trace(std::vector<Row> const& trace, size_t beg, size_t end, bool enable_selectors = false);

bool is_operand_indirect(uint8_t ind_value, uint8_t operand_idx);

} // namespace bb::avm_trace
Loading
Loading