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 23, 2024
1 parent a2ed567 commit 3a26a38
Show file tree
Hide file tree
Showing 35 changed files with 911 additions and 923 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 @@ -1042,7 +1042,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 @@ -83,7 +83,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 @@ -241,7 +241,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 @@ -414,7 +414,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 @@ -535,9 +535,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 @@ -166,7 +166,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 @@ -281,7 +281,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 All @@ -290,7 +290,6 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.main_sel_op_sload.set_if_valid_index(i, rows[i].main_sel_op_sload);
polys.main_sel_op_sstore.set_if_valid_index(i, rows[i].main_sel_op_sstore);
polys.main_sel_op_static_call.set_if_valid_index(i, rows[i].main_sel_op_static_call);
polys.main_sel_op_storage_address.set_if_valid_index(i, rows[i].main_sel_op_storage_address);
polys.main_sel_op_sub.set_if_valid_index(i, rows[i].main_sel_op_sub);
polys.main_sel_op_timestamp.set_if_valid_index(i, rows[i].main_sel_op_timestamp);
polys.main_sel_op_transaction_fee.set_if_valid_index(i, rows[i].main_sel_op_transaction_fee);
Expand Down
Loading

0 comments on commit 3a26a38

Please sign in to comment.