Skip to content

Commit

Permalink
feat(avm): range check gadget (#7967)
Browse files Browse the repository at this point in the history
This doesnt replace the existing range check - this just sets up the initial work for a range check gadget
  • Loading branch information
IlyasRidhuan authored and codygunton committed Aug 30, 2024
1 parent 9935263 commit 82bd181
Show file tree
Hide file tree
Showing 11 changed files with 966 additions and 983 deletions.
1 change: 0 additions & 1 deletion barretenberg/cpp/pil/avm/alu.pil
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include "gadgets/range_check.pil";
include "gadgets/cmp.pil";
namespace alu(256);

// =============== Table ALU-TR =================================================
Expand Down
28 changes: 3 additions & 25 deletions barretenberg/cpp/pil/avm/gadgets/range_check.pil
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include "../main.pil";
include "../fixed/powers.pil";

namespace range_check(256);
// TODO: We should look to rename this to something like rng_idx
// Increasingly this is less likely to be associated directly with a subtrace's clk
pol commit clk;

// Range check selector
Expand All @@ -11,7 +11,7 @@ namespace range_check(256);
// Witnesses
// Value to range check
pol commit value;
// Number of bits to check against (this number must be <=128)
// Number of bits to check against
pol commit rng_chk_bits;

// Bit Size Columns
Expand Down Expand Up @@ -188,25 +188,3 @@ namespace range_check(256);
#[LOOKUP_RNG_CHK_7]
sel_rng_chk { u16_r7 } in main.sel_rng_16 { main.clk };

// ===== MEM TRACE RANGE CHECKS =====
pol commit mem_rng_chk;
// We range check 40 bits in the mem trace
mem_rng_chk * (rng_chk_bits - 40) = 0;


// ===== GAS TRACE RANGE CHECKS =====
pol commit gas_l2_rng_chk;
pol commit gas_da_rng_chk;
// We range check 32 bits in the gas trace
gas_l2_rng_chk * (rng_chk_bits - 32) = 0;
gas_da_rng_chk * (rng_chk_bits - 32) = 0;

// ==== CMP TRACE RANGE CHECKS =====
pol commit cmp_lo_bits_rng_chk;
pol commit cmp_hi_bits_rng_chk;
// We range check 128 bits in the cmp trace
cmp_lo_bits_rng_chk * (rng_chk_bits - 128) = 0;
cmp_hi_bits_rng_chk * (rng_chk_bits - 128) = 0;

// ==== ALU TRACE RANGE CHECKS ====
pol commit alu_rng_chk;
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,10 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.poseidon2_mem_addr_write_d[i] = rows[i].poseidon2_mem_addr_write_d;
polys.poseidon2_output_addr[i] = rows[i].poseidon2_output_addr;
polys.poseidon2_sel_poseidon_perm[i] = rows[i].poseidon2_sel_poseidon_perm;
polys.range_check_alu_rng_chk[i] = rows[i].range_check_alu_rng_chk;
polys.range_check_clk[i] = rows[i].range_check_clk;
polys.range_check_cmp_hi_bits_rng_chk[i] = rows[i].range_check_cmp_hi_bits_rng_chk;
polys.range_check_cmp_lo_bits_rng_chk[i] = rows[i].range_check_cmp_lo_bits_rng_chk;
polys.range_check_dyn_diff[i] = rows[i].range_check_dyn_diff;
polys.range_check_dyn_rng_chk_bits[i] = rows[i].range_check_dyn_rng_chk_bits;
polys.range_check_dyn_rng_chk_pow_2[i] = rows[i].range_check_dyn_rng_chk_pow_2;
polys.range_check_gas_da_rng_chk[i] = rows[i].range_check_gas_da_rng_chk;
polys.range_check_gas_l2_rng_chk[i] = rows[i].range_check_gas_l2_rng_chk;
polys.range_check_is_lte_u112[i] = rows[i].range_check_is_lte_u112;
polys.range_check_is_lte_u128[i] = rows[i].range_check_is_lte_u128;
polys.range_check_is_lte_u16[i] = rows[i].range_check_is_lte_u16;
Expand All @@ -613,7 +608,6 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
polys.range_check_is_lte_u64[i] = rows[i].range_check_is_lte_u64;
polys.range_check_is_lte_u80[i] = rows[i].range_check_is_lte_u80;
polys.range_check_is_lte_u96[i] = rows[i].range_check_is_lte_u96;
polys.range_check_mem_rng_chk[i] = rows[i].range_check_mem_rng_chk;
polys.range_check_rng_chk_bits[i] = rows[i].range_check_rng_chk_bits;
polys.range_check_sel_lookup_0[i] = rows[i].range_check_sel_lookup_0;
polys.range_check_sel_lookup_1[i] = rows[i].range_check_sel_lookup_1;
Expand Down
Loading

0 comments on commit 82bd181

Please sign in to comment.