Skip to content

Commit

Permalink
chore!: ToRadixLE -> ToRadixBE in Brillig and AVM
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanks12 committed Oct 28, 2024
1 parent e50303d commit 19f9c48
Show file tree
Hide file tree
Showing 34 changed files with 135 additions and 119 deletions.
4 changes: 2 additions & 2 deletions avm-transpiler/src/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub enum AvmOpcode {
ECADD,
MSM,
// Conversions
TORADIXLE,
TORADIXBE,
}

impl AvmOpcode {
Expand Down Expand Up @@ -171,7 +171,7 @@ impl AvmOpcode {
AvmOpcode::ECADD => "ECADD",
AvmOpcode::MSM => "MSM",
// Conversions
AvmOpcode::TORADIXLE => "TORADIXLE",
AvmOpcode::TORADIXBE => "TORADIXBE",
}
}
}
2 changes: 1 addition & 1 deletion avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ fn handle_black_box_function(avm_instrs: &mut Vec<AvmInstruction>, operation: &B
let radix_offset = radix.to_usize() as u32;

avm_instrs.push(AvmInstruction {
opcode: AvmOpcode::TORADIXLE,
opcode: AvmOpcode::TORADIXBE,
indirect: Some(
AddressingModeBuilder::default()
.direct_operand(input)
Expand Down
7 changes: 4 additions & 3 deletions barretenberg/cpp/pil/avm/gadgets/conversion.pil
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ namespace conversion(256);
pol commit clk;

// Selector for Radix Operation
pol commit sel_to_radix_le;
sel_to_radix_le * (1 - sel_to_radix_le) = 0;
pol commit sel_to_radix_be;
sel_to_radix_be * (1 - sel_to_radix_be) = 0;

// ===== DRAFT: Planned Constraints for To Radix LE
// ===== DRAFT: Planned Constraints for To Radix BE
// Similar to the binary trace; multi-row decomposition of the input using the number of limbs specified as the row count.
// TODO: modify this draft plan to work for big-endian To Radix
// (1) limb_ctr' - limb_ctr + 1 = 0; // Next row decrements the limb_ctr
// (2) Check equality to 0 of limb_ctr to terminate the operations.
// (3) An accumulation column to track the partial re-composition of the limbs
Expand Down
10 changes: 5 additions & 5 deletions barretenberg/cpp/pil/avm/main.pil
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace main(256);
pol commit opcode_val;

//===== Gadget Selectors ======================================================
pol commit sel_op_radix_le;
pol commit sel_op_radix_be;
pol commit sel_op_sha256;
pol commit sel_op_poseidon2;
pol commit sel_op_keccak;
Expand Down Expand Up @@ -244,7 +244,7 @@ namespace main(256);
sel_op_sload * (1 - sel_op_sload) = 0;
sel_op_sstore * (1 - sel_op_sstore) = 0;

sel_op_radix_le * (1 - sel_op_radix_le) = 0;
sel_op_radix_be * (1 - sel_op_radix_be) = 0;
sel_op_sha256 * (1 - sel_op_sha256) = 0;
sel_op_poseidon2 * (1 - sel_op_poseidon2) = 0;
sel_op_keccak * (1 - sel_op_keccak) = 0;
Expand Down Expand Up @@ -416,7 +416,7 @@ namespace main(256);
pol SEL_ALL_ALU = SEL_ALU_R_TAG + SEL_ALU_W_TAG;
pol SEL_ALL_LEFTGAS = sel_op_dagasleft + sel_op_l2gasleft;
pol SEL_ALL_BINARY = sel_op_and + sel_op_or + sel_op_xor;
pol SEL_ALL_GADGET = sel_op_radix_le + sel_op_sha256 + sel_op_poseidon2 + sel_op_keccak
pol SEL_ALL_GADGET = sel_op_radix_be + sel_op_sha256 + sel_op_poseidon2 + sel_op_keccak
+ sel_op_ecadd + sel_op_msm;
pol SEL_ALL_MEMORY = sel_op_mov + sel_op_set;
pol OPCODE_SELECTORS = sel_op_fdiv + sel_op_calldata_copy + sel_op_get_contract_instance
Expand Down Expand Up @@ -537,9 +537,9 @@ namespace main(256);
binary.start {binary.clk, binary.acc_ia, binary.acc_ib, binary.acc_ic, binary.op_id, binary.in_tag};

#[PERM_MAIN_CONV]
sel_op_radix_le {clk, ia, ib, ic, id}
sel_op_radix_be {clk, ia, ib, ic, id}
is
conversion.sel_to_radix_le {conversion.clk, conversion.input, conversion.radix, conversion.num_limbs, conversion.output_bits};
conversion.sel_to_radix_be {conversion.clk, conversion.input, conversion.radix, conversion.num_limbs, conversion.output_bits};

#[PERM_MAIN_SHA256]
sel_op_sha256 {clk, ia, ib, ic}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.conversion_num_limbs.set_if_valid_index(i, rows[i].conversion_num_limbs);
polys.conversion_output_bits.set_if_valid_index(i, rows[i].conversion_output_bits);
polys.conversion_radix.set_if_valid_index(i, rows[i].conversion_radix);
polys.conversion_sel_to_radix_le.set_if_valid_index(i, rows[i].conversion_sel_to_radix_le);
polys.conversion_sel_to_radix_be.set_if_valid_index(i, rows[i].conversion_sel_to_radix_be);
polys.keccakf1600_clk.set_if_valid_index(i, rows[i].keccakf1600_clk);
polys.keccakf1600_input.set_if_valid_index(i, rows[i].keccakf1600_input);
polys.keccakf1600_output.set_if_valid_index(i, rows[i].keccakf1600_output);
Expand Down Expand Up @@ -356,7 +356,7 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.main_sel_op_nullifier_exists.set_if_valid_index(i, rows[i].main_sel_op_nullifier_exists);
polys.main_sel_op_or.set_if_valid_index(i, rows[i].main_sel_op_or);
polys.main_sel_op_poseidon2.set_if_valid_index(i, rows[i].main_sel_op_poseidon2);
polys.main_sel_op_radix_le.set_if_valid_index(i, rows[i].main_sel_op_radix_le);
polys.main_sel_op_radix_be.set_if_valid_index(i, rows[i].main_sel_op_radix_be);
polys.main_sel_op_sender.set_if_valid_index(i, rows[i].main_sel_op_sender);
polys.main_sel_op_set.set_if_valid_index(i, rows[i].main_sel_op_set);
polys.main_sel_op_sha256.set_if_valid_index(i, rows[i].main_sel_op_sha256);
Expand Down
12 changes: 6 additions & 6 deletions barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ AvmFlavor::AllConstRefValues::AllConstRefValues(
, conversion_num_limbs(il[138])
, conversion_output_bits(il[139])
, conversion_radix(il[140])
, conversion_sel_to_radix_le(il[141])
, conversion_sel_to_radix_be(il[141])
, keccakf1600_clk(il[142])
, keccakf1600_input(il[143])
, keccakf1600_output(il[144])
Expand Down Expand Up @@ -254,7 +254,7 @@ AvmFlavor::AllConstRefValues::AllConstRefValues(
, main_sel_op_nullifier_exists(il[246])
, main_sel_op_or(il[247])
, main_sel_op_poseidon2(il[248])
, main_sel_op_radix_le(il[249])
, main_sel_op_radix_be(il[249])
, main_sel_op_sender(il[250])
, main_sel_op_set(il[251])
, main_sel_op_sha256(il[252])
Expand Down Expand Up @@ -987,7 +987,7 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id
conversion_num_limbs[row_idx],
conversion_output_bits[row_idx],
conversion_radix[row_idx],
conversion_sel_to_radix_le[row_idx],
conversion_sel_to_radix_be[row_idx],
keccakf1600_clk[row_idx],
keccakf1600_input[row_idx],
keccakf1600_output[row_idx],
Expand Down Expand Up @@ -1095,7 +1095,7 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id
main_sel_op_nullifier_exists[row_idx],
main_sel_op_or[row_idx],
main_sel_op_poseidon2[row_idx],
main_sel_op_radix_le[row_idx],
main_sel_op_radix_be[row_idx],
main_sel_op_sender[row_idx],
main_sel_op_set[row_idx],
main_sel_op_sha256[row_idx],
Expand Down Expand Up @@ -1816,7 +1816,7 @@ AvmFlavor::CommitmentLabels::CommitmentLabels()
Base::conversion_num_limbs = "CONVERSION_NUM_LIMBS";
Base::conversion_output_bits = "CONVERSION_OUTPUT_BITS";
Base::conversion_radix = "CONVERSION_RADIX";
Base::conversion_sel_to_radix_le = "CONVERSION_SEL_TO_RADIX_LE";
Base::conversion_sel_to_radix_be = "CONVERSION_SEL_TO_RADIX_BE";
Base::keccakf1600_clk = "KECCAKF1600_CLK";
Base::keccakf1600_input = "KECCAKF1600_INPUT";
Base::keccakf1600_output = "KECCAKF1600_OUTPUT";
Expand Down Expand Up @@ -1924,7 +1924,7 @@ AvmFlavor::CommitmentLabels::CommitmentLabels()
Base::main_sel_op_nullifier_exists = "MAIN_SEL_OP_NULLIFIER_EXISTS";
Base::main_sel_op_or = "MAIN_SEL_OP_OR";
Base::main_sel_op_poseidon2 = "MAIN_SEL_OP_POSEIDON2";
Base::main_sel_op_radix_le = "MAIN_SEL_OP_RADIX_LE";
Base::main_sel_op_radix_be = "MAIN_SEL_OP_RADIX_BE";
Base::main_sel_op_sender = "MAIN_SEL_OP_SENDER";
Base::main_sel_op_set = "MAIN_SEL_OP_SET";
Base::main_sel_op_sha256 = "MAIN_SEL_OP_SHA256";
Expand Down
Loading

0 comments on commit 19f9c48

Please sign in to comment.