Skip to content

Blackbox range function (WIP)#18

Merged
vishady721 merged 12 commits into
fiat-shamirfrom
range
Apr 24, 2025
Merged

Blackbox range function (WIP)#18
vishady721 merged 12 commits into
fiat-shamirfrom
range

Conversation

@vishady721
Copy link
Copy Markdown
Collaborator

No description provided.

@vishady721 vishady721 changed the base branch from main to fiat-shamir April 12, 2025 02:05
@benjaminwilson benjaminwilson self-assigned this Apr 15, 2025
Copy link
Copy Markdown
Collaborator

@benjaminwilson benjaminwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!! btw if you pull on fiat-shamir there are some tests that would serve as a useful template!

Comment thread noir-r1cs/src/compiler.rs Outdated
};

const NUM_WITNESS_THRESHOLD_FOR_LOOKUP_TABLE: usize = 5;
const NUM_BITS_THRESHOLD_FOR_DIGITAL_DECOMP: u32 = 32;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like maybe 32 might be too large for NUM_BITS_THRESHOLD_FOR_DIGITAL_DECOMP?

Comment thread noir-r1cs/src/compiler.rs Outdated

const NUM_WITNESS_THRESHOLD_FOR_LOOKUP_TABLE: usize = 5;
const NUM_BITS_THRESHOLD_FOR_DIGITAL_DECOMP: u32 = 32;
pub const LOG_BASE_DECOMPOSITION: u32 = 32;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto?

Comment thread noir-r1cs/src/compiler.rs
let mut memory_blocks: BTreeMap<usize, ReadOnlyMemoryBlock> = BTreeMap::new();
// Range blocks to map the number of bits threshold to the vector of values that
// are meant to be constrained within that range.
let mut range_blocks: BTreeMap<u32, Vec<usize>> = BTreeMap::new();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you mentioned, looks like we need to support also RANGE(T) for T not a power of two, as well, so will need to use T as a key to this map (not logT)

Comment thread noir-r1cs/src/compiler.rs Outdated
let mut range_blocks: BTreeMap<u32, Vec<usize>> = BTreeMap::new();
// Same as above, but for number of bits that are above the [NUM_BITS_THRESHOLD_FOR_DIGITAL_DECOMP].
// Separated so that we can separate the witness values into digits to do smaller range checks.
let mut range_blocks_outside_threshold: BTreeMap<u32, &Vec<usize>> = BTreeMap::new();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we don't actually populate this guy until later on, immediately before we use it - I think even perhaps it's redundant, since could just inline that case with the others in the if block starting line 257

Comment thread noir-r1cs/src/compiler.rs
@@ -151,9 +164,36 @@ impl R1CS {
}

// These are calls to built-in functions, for this we need to create.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing some words here somehow :)

Comment thread noir-r1cs/src/compiler.rs Outdated
.push(input_witness);
// Keep track of the different ranges we are checking in order
// to track and update multiplicities.
range_blocks.keys().for_each(|key| {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't feel like the right place to do this - currently this is happening for every RANGE opcode instance?

Comment thread noir-r1cs/src/compiler.rs
});
}
_ => {
println!("Other black box function: {:?}", black_box_func_call);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's panic or error?

Comment thread noir-r1cs/src/compiler.rs Outdated
///
/// Checks that both sums (LHS and RHS) are equal at the end.
fn add_logup_summations(&mut self, num_bits: u32, values_to_lookup: &[usize]) {
// Sample the Shwartz-Zippel challenge for the log derivative
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schwartz

Comment thread noir-r1cs/src/compiler.rs
current_product_witness = next_product_witness;
});

self.matrices.add_constraint(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this constraint is correct? Shouldn't it be current_product_witness == 0?

Comment thread noir-r1cs/src/solver.rs
/// Products with linear operations on the witness indices.
/// Fields are Product((index, a, b), (index, c, d)) such that
/// we wish to compute (ax + b) * (cx + d).
ProductLinearOperation(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if witness * (another_witness + const) would be sufficiently general? (it's faster to solve for)

@vishady721 vishady721 merged commit ea5016d into fiat-shamir Apr 24, 2025
0 of 2 checks passed
dcbuild3r pushed a commit that referenced this pull request May 16, 2026
Blackbox range function (WIP)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants