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

chore(debt): unbounded F: Field types on operation callsites #1679

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion crates/core/machine/src/alu/add_sub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ where
builder.when_transition().assert_eq(local.nonce + AB::Expr::one(), next.nonce);

// Evaluate the addition operation.
AddOperation::<AB::F>::eval(
AddOperation::eval(
builder,
local.operand_1,
local.operand_2,
Expand Down
6 changes: 3 additions & 3 deletions crates/core/machine/src/alu/divrem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,15 @@ where

// Calculate is_overflow. is_overflow = is_equal(b, -2^{31}) * is_equal(c, -1) * is_signed
{
IsEqualWordOperation::<AB::F>::eval(
IsEqualWordOperation::eval(
builder,
local.b.map(|x| x.into()),
Word::from(i32::MIN as u32).map(|x: AB::F| x.into()),
local.is_overflow_b,
local.is_real.into(),
);

IsEqualWordOperation::<AB::F>::eval(
IsEqualWordOperation::eval(
builder,
local.c.map(|x| x.into()),
Word::from(-1i32 as u32).map(|x: AB::F| x.into()),
Expand Down Expand Up @@ -631,7 +631,7 @@ where
// When division by 0, quotient must be 0xffffffff per RISC-V spec.
{
// Calculate whether c is 0.
IsZeroWordOperation::<AB::F>::eval(
IsZeroWordOperation::eval(
builder,
local.c.map(|x| x.into()),
local.is_c_0,
Expand Down
10 changes: 5 additions & 5 deletions crates/core/machine/src/cpu/air/ecall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl CpuChip {

// Compute whether this ecall is ENTER_UNCONSTRAINED.
let is_enter_unconstrained = {
IsZeroOperation::<AB::F>::eval(
IsZeroOperation::eval(
builder,
syscall_id
- AB::Expr::from_canonical_u32(SyscallCode::ENTER_UNCONSTRAINED.syscall_id()),
Expand All @@ -76,7 +76,7 @@ impl CpuChip {

// Compute whether this ecall is HINT_LEN.
let is_hint_len = {
IsZeroOperation::<AB::F>::eval(
IsZeroOperation::eval(
builder,
syscall_id - AB::Expr::from_canonical_u32(SyscallCode::HINT_LEN.syscall_id()),
ecall_cols.is_hint_len,
Expand Down Expand Up @@ -238,7 +238,7 @@ impl CpuChip {

// Compute whether this ecall is HALT.
let is_halt = {
IsZeroOperation::<AB::F>::eval(
IsZeroOperation::eval(
builder,
syscall_id - AB::Expr::from_canonical_u32(SyscallCode::HALT.syscall_id()),
ecall_cols.is_halt,
Expand Down Expand Up @@ -268,7 +268,7 @@ impl CpuChip {

// Compute whether this ecall is COMMIT.
let is_commit = {
IsZeroOperation::<AB::F>::eval(
IsZeroOperation::eval(
builder,
syscall_id - AB::Expr::from_canonical_u32(SyscallCode::COMMIT.syscall_id()),
ecall_cols.is_commit,
Expand All @@ -279,7 +279,7 @@ impl CpuChip {

// Compute whether this ecall is COMMIT_DEFERRED_PROOFS.
let is_commit_deferred_proofs = {
IsZeroOperation::<AB::F>::eval(
IsZeroOperation::eval(
builder,
syscall_id
- AB::Expr::from_canonical_u32(
Expand Down
2 changes: 1 addition & 1 deletion crates/core/machine/src/memory/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ where

// Constrain the is_prev_addr_zero operation only in the first row.
let is_first_row = builder.is_first_row();
IsZeroOperation::<AB::F>::eval(builder, prev_addr, local.is_prev_addr_zero, is_first_row);
IsZeroOperation::eval(builder, prev_addr, local.is_prev_addr_zero, is_first_row);

// Constrain the is_first_comp column.
builder.assert_bool(local.is_first_comp);
Expand Down
2 changes: 1 addition & 1 deletion crates/core/machine/src/memory/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ where
public_values_slice.as_slice().borrow();

// Constrain `is_first_shard` to be 1 if and only if the shard is the first shard.
IsZeroOperation::<AB::F>::eval(
IsZeroOperation::eval(
builder,
public_values.shard.clone() - AB::F::one(),
mult_local.is_first_shard,
Expand Down
6 changes: 4 additions & 2 deletions crates/core/machine/src/operations/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ impl<F: Field> AddOperation<F> {
expected
}

pub fn eval<AB: SP1AirBuilder>(
pub fn eval<AB>(
builder: &mut AB,
a: Word<AB::Var>,
b: Word<AB::Var>,
cols: AddOperation<AB::Var>,
is_real: AB::Expr,
) {
) where
AB: SP1AirBuilder<F = F>,
{
let one = AB::Expr::one();
let base = AB::F::from_canonical_u32(256);

Expand Down
6 changes: 4 additions & 2 deletions crates/core/machine/src/operations/add4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,17 @@ impl<F: Field> Add4Operation<F> {
}

#[allow(clippy::too_many_arguments)]
pub fn eval<AB: SP1AirBuilder>(
pub fn eval<AB>(
builder: &mut AB,
a: Word<AB::Var>,
b: Word<AB::Var>,
c: Word<AB::Var>,
d: Word<AB::Var>,
is_real: AB::Var,
cols: Add4Operation<AB::Var>,
) {
) where
AB: SP1AirBuilder<F = F>,
{
// Range check each byte.
{
builder.slice_range_check_u8(&a.0, is_real);
Expand Down
6 changes: 4 additions & 2 deletions crates/core/machine/src/operations/add5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ impl<F: Field> Add5Operation<F> {
expected
}

pub fn eval<AB: SP1AirBuilder>(
pub fn eval<AB>(
builder: &mut AB,
words: &[Word<AB::Var>; 5],
is_real: AB::Var,
cols: Add5Operation<AB::Var>,
) {
) where
AB: SP1AirBuilder<F = F>,
{
builder.assert_bool(is_real);
// Range check each byte.
{
Expand Down
8 changes: 5 additions & 3 deletions crates/core/machine/src/operations/and.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use p3_field::{AbstractField, Field};
use p3_field::Field;
use sp1_derive::AlignedBorrow;

use sp1_core_executor::{
Expand Down Expand Up @@ -39,13 +39,15 @@ impl<F: Field> AndOperation<F> {
}

#[allow(unused_variables)]
pub fn eval<AB: SP1AirBuilder>(
pub fn eval<AB>(
builder: &mut AB,
a: Word<AB::Var>,
b: Word<AB::Var>,
cols: AndOperation<AB::Var>,
is_real: AB::Var,
) {
) where
AB: SP1AirBuilder<F = F>,
{
for i in 0..WORD_SIZE {
builder.send_byte(
AB::F::from_canonical_u32(ByteOpcode::AND as u32),
Expand Down
6 changes: 4 additions & 2 deletions crates/core/machine/src/operations/baby_bear_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ impl<F: Field> BabyBearBitDecomposition<F> {
self.and_most_sig_byte_decomp_3_to_6 * most_sig_byte_decomp[6];
}

pub fn range_check<AB: SP1AirBuilder>(
pub fn range_check<AB>(
builder: &mut AB,
value: AB::Var,
cols: BabyBearBitDecomposition<AB::Var>,
is_real: AB::Expr,
) {
) where
AB: SP1AirBuilder<F = F>,
{
let mut reconstructed_value = AB::Expr::zero();
for (i, bit) in cols.bits.iter().enumerate() {
builder.when(is_real.clone()).assert_bool(*bit);
Expand Down
6 changes: 4 additions & 2 deletions crates/core/machine/src/operations/baby_bear_word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ impl<F: Field> BabyBearWordRangeChecker<F> {
self.and_most_sig_byte_decomp_3_to_6 * self.most_sig_byte_decomp[6];
}

pub fn range_check<AB: SP1AirBuilder>(
pub fn range_check<AB>(
builder: &mut AB,
value: Word<AB::Var>,
cols: BabyBearWordRangeChecker<AB::Var>,
is_real: AB::Expr,
) {
) where
AB: SP1AirBuilder<F = F>,
{
let mut recomposed_byte = AB::Expr::zero();
cols.most_sig_byte_decomp.iter().enumerate().for_each(|(i, value)| {
builder.when(is_real.clone()).assert_bool(*value);
Expand Down
6 changes: 4 additions & 2 deletions crates/core/machine/src/operations/fixed_rotate_right.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ impl<F: Field> FixedRotateRightOperation<F> {
expected
}

pub fn eval<AB: SP1AirBuilder>(
pub fn eval<AB>(
builder: &mut AB,
input: Word<AB::Var>,
rotation: usize,
cols: FixedRotateRightOperation<AB::Var>,
is_real: AB::Var,
) {
) where
AB: SP1AirBuilder<F = F>,
{
// Compute some constants with respect to the rotation needed for the rotation.
let nb_bytes_to_shift = Self::nb_bytes_to_shift(rotation);
let nb_bits_to_shift = Self::nb_bits_to_shift(rotation);
Expand Down
6 changes: 4 additions & 2 deletions crates/core/machine/src/operations/fixed_shift_right.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ impl<F: Field> FixedShiftRightOperation<F> {
expected
}

pub fn eval<AB: SP1AirBuilder>(
pub fn eval<AB>(
builder: &mut AB,
input: Word<AB::Var>,
rotation: usize,
cols: FixedShiftRightOperation<AB::Var>,
is_real: AB::Var,
) {
) where
AB: SP1AirBuilder<F = F>,
{
// Compute some constants with respect to the rotation needed for the rotation.
let nb_bytes_to_shift = Self::nb_bytes_to_shift(rotation);
let nb_bits_to_shift = Self::nb_bits_to_shift(rotation);
Expand Down
8 changes: 5 additions & 3 deletions crates/core/machine/src/operations/is_equal_word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ impl<F: Field> IsEqualWordOperation<F> {
(a_u32 == b_u32) as u32
}

pub fn eval<AB: SP1AirBuilder>(
pub fn eval<AB>(
builder: &mut AB,
a: Word<AB::Expr>,
b: Word<AB::Expr>,
cols: IsEqualWordOperation<AB::Var>,
is_real: AB::Expr,
) {
) where
AB: SP1AirBuilder<F = F>,
{
builder.assert_bool(is_real.clone());

// Calculate differences in limbs.
Expand All @@ -46,6 +48,6 @@ impl<F: Field> IsEqualWordOperation<F> {
]);

// Check if the difference is 0.
IsZeroWordOperation::<AB::F>::eval(builder, diff, cols.is_diff_zero, is_real.clone());
IsZeroWordOperation::eval(builder, diff, cols.is_diff_zero, is_real.clone());
}
}
8 changes: 5 additions & 3 deletions crates/core/machine/src/operations/is_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! The idea is that 1 - input * inverse is exactly the boolean value indicating whether the input
//! is 0.
use p3_air::AirBuilder;
use p3_field::{AbstractField, Field};
use p3_field::Field;
use sp1_derive::AlignedBorrow;

use sp1_stark::air::SP1AirBuilder;
Expand Down Expand Up @@ -39,12 +39,14 @@ impl<F: Field> IsZeroOperation<F> {
(a == F::zero()) as u32
}

pub fn eval<AB: SP1AirBuilder>(
pub fn eval<AB>(
builder: &mut AB,
a: AB::Expr,
cols: IsZeroOperation<AB::Var>,
is_real: AB::Expr,
) {
) where
AB: SP1AirBuilder<F = F>,
{
let one: AB::Expr = AB::F::one().into();

// 1. Input == 0 => is_zero = 1 regardless of the inverse.
Expand Down
8 changes: 5 additions & 3 deletions crates/core/machine/src/operations/is_zero_word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ impl<F: Field> IsZeroWordOperation<F> {
is_zero as u32
}

pub fn eval<AB: SP1AirBuilder>(
pub fn eval<AB>(
builder: &mut AB,
a: Word<AB::Expr>,
cols: IsZeroWordOperation<AB::Var>,
is_real: AB::Expr,
) {
) where
AB: SP1AirBuilder<F = F>,
{
// Calculate whether each byte is 0.
for i in 0..WORD_SIZE {
IsZeroOperation::<AB::F>::eval(
IsZeroOperation::eval(
builder,
a[i].clone(),
cols.is_zero_byte[i],
Expand Down
8 changes: 5 additions & 3 deletions crates/core/machine/src/operations/not.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use p3_air::AirBuilder;
use p3_field::{AbstractField, Field};
use p3_field::Field;
use sp1_core_executor::{events::ByteRecord, ByteOpcode};
use sp1_derive::AlignedBorrow;
use sp1_primitives::consts::WORD_SIZE;
Expand All @@ -25,12 +25,14 @@ impl<F: Field> NotOperation<F> {
}

#[allow(unused_variables)]
pub fn eval<AB: SP1AirBuilder>(
pub fn eval<AB>(
builder: &mut AB,
a: Word<AB::Var>,
cols: NotOperation<AB::Var>,
is_real: impl Into<AB::Expr> + Copy,
) {
) where
AB: SP1AirBuilder<F = F>,
{
for i in (0..WORD_SIZE).step_by(2) {
builder.send_byte_pair(
AB::F::from_canonical_u32(ByteOpcode::U8Range as u32),
Expand Down
8 changes: 5 additions & 3 deletions crates/core/machine/src/operations/or.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use p3_field::{AbstractField, Field};
use p3_field::Field;
use sp1_core_executor::{events::ByteRecord, ByteOpcode, ExecutionRecord};
use sp1_derive::AlignedBorrow;
use sp1_primitives::consts::WORD_SIZE;
Expand All @@ -24,13 +24,15 @@ impl<F: Field> OrOperation<F> {
expected
}

pub fn eval<AB: SP1AirBuilder>(
pub fn eval<AB>(
builder: &mut AB,
a: Word<AB::Var>,
b: Word<AB::Var>,
cols: OrOperation<AB::Var>,
is_real: AB::Var,
) {
) where
AB: SP1AirBuilder<F = F>,
{
for i in 0..WORD_SIZE {
builder.send_byte(
AB::F::from_canonical_u32(ByteOpcode::OR as u32),
Expand Down
8 changes: 5 additions & 3 deletions crates/core/machine/src/operations/xor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use p3_field::{AbstractField, Field};
use p3_field::Field;
use sp1_core_executor::{
events::{ByteLookupEvent, ByteRecord},
ByteOpcode,
Expand Down Expand Up @@ -38,13 +38,15 @@ impl<F: Field> XorOperation<F> {
}

#[allow(unused_variables)]
pub fn eval<AB: SP1AirBuilder>(
pub fn eval<AB>(
builder: &mut AB,
a: Word<AB::Var>,
b: Word<AB::Var>,
cols: XorOperation<AB::Var>,
is_real: AB::Var,
) {
) where
AB: SP1AirBuilder<F = F>,
{
for i in 0..WORD_SIZE {
builder.send_byte(
AB::F::from_canonical_u32(ByteOpcode::XOR as u32),
Expand Down
Loading