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)!: byte indexed PC #9582

Merged
merged 17 commits into from
Nov 4, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fixing gcc compilation failure
jeanmon committed Nov 4, 2024

Verified

This commit was signed with the committer’s verified signature.
flip1995 Philipp Krones
commit 08732e38a6b243634af9ac96e90526ef72b09cd2
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ TEST_F(AvmControlFlowTests, simpleJump)
TEST_F(AvmControlFlowTests, simpleCallAndReturn)
{
uint32_t const CALL_PC = 20;
uint32_t const RETURN_PC = static_cast<uint32_t>(Deserialization::get_pc_increment(OpCode::INTERNALCALL));
uint32_t const RETURN_PC = Deserialization::get_pc_increment(OpCode::INTERNALCALL);
// trace_builder for the following operation
// pc opcode
// 0 INTERNAL_CALL(pc=20)
@@ -183,7 +183,7 @@ TEST_F(AvmControlFlowTests, multipleCallsAndReturns)

const uint32_t JUMP_PC_1 = 22;

const uint32_t INTERNALCALL_SIZE = static_cast<uint32_t>(Deserialization::get_pc_increment(OpCode::INTERNALCALL));
const uint32_t INTERNALCALL_SIZE = Deserialization::get_pc_increment(OpCode::INTERNALCALL);
const uint32_t NEXT_PC_1 = INTERNALCALL_SIZE;
const uint32_t NEXT_PC_2 = CALL_PC_1 + INTERNALCALL_SIZE;
const uint32_t NEXT_PC_3 = CALL_PC_2 + INTERNALCALL_SIZE;
Original file line number Diff line number Diff line change
@@ -187,7 +187,7 @@ const std::unordered_map<OpCode, std::vector<OperandType>> OPCODE_WIRE_FORMAT =
OperandType::UINT8 } },
};

const std::unordered_map<OperandType, size_t> OPERAND_TYPE_SIZE = {
const std::unordered_map<OperandType, uint32_t> OPERAND_TYPE_SIZE = {
{ OperandType::INDIRECT8, 1 }, { OperandType::INDIRECT16, 2 }, { OperandType::TAG, 1 },
{ OperandType::UINT8, 1 }, { OperandType::UINT16, 2 }, { OperandType::UINT32, 4 },
{ OperandType::UINT64, 8 }, { OperandType::UINT128, 16 }, { OperandType::FF, 32 }
@@ -196,7 +196,7 @@ const std::unordered_map<OperandType, size_t> OPERAND_TYPE_SIZE = {
} // Anonymous namespace

// TODO: once opcodes are frozen, this function can be replaced by a table/map of constants
size_t Deserialization::get_pc_increment(OpCode opcode)
uint32_t Deserialization::get_pc_increment(OpCode opcode)
{
const auto iter = OPCODE_WIRE_FORMAT.find(opcode);

@@ -205,7 +205,7 @@ size_t Deserialization::get_pc_increment(OpCode opcode)
}

// OPCODE_WIRE_FORMAT does not contain the opcode itself which accounts for 1 byte
size_t increment = 1;
uint32_t increment = 1;

const std::vector<OperandType>& inst_format = iter->second;
for (const auto& op_type : inst_format) {
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ class Deserialization {

static Instruction parse(const std::vector<uint8_t>& bytecode, size_t pos);
static std::vector<Instruction> parse_bytecode_statically(const std::vector<uint8_t>& bytecode);
static size_t get_pc_increment(OpCode opcode);
static uint32_t get_pc_increment(OpCode opcode);
};

} // namespace bb::avm_trace
Original file line number Diff line number Diff line change
@@ -721,7 +721,7 @@ std::vector<Row> Execution::gen_trace(std::vector<FF> const& calldata,
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.op_jump(pc + static_cast<uint32_t>(Deserialization::get_pc_increment(OpCode::DEBUGLOG)));
trace_builder.op_jump(pc + Deserialization::get_pc_increment(OpCode::DEBUGLOG));
break;

// Gadgets
3 changes: 1 addition & 2 deletions barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp
Original file line number Diff line number Diff line change
@@ -1803,8 +1803,7 @@ void AvmTraceBuilder::op_jumpi(uint8_t indirect, uint32_t jmp_dest, uint32_t con

const bool id_zero = read_d.val == 0;
FF const inv = !id_zero ? read_d.val.invert() : 1;
uint32_t next_pc =
!id_zero ? jmp_dest : pc + static_cast<uint32_t>(Deserialization::get_pc_increment(OpCode::JUMPI_32));
uint32_t next_pc = !id_zero ? jmp_dest : pc + Deserialization::get_pc_increment(OpCode::JUMPI_32);

// Constrain gas cost
gas_trace_builder.constrain_gas(clk, OpCode::JUMPI_32);