Skip to content

Commit

Permalink
feat: v1.06-testnet (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtguibas authored Jun 3, 2024
2 parents 466fbb9 + bedc606 commit 1049583
Show file tree
Hide file tree
Showing 156 changed files with 3,542 additions and 2,778 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ web-time = "1.1.0"
rayon-scan = "0.1.1"
thiserror = "1.0.60"
num-bigint = { version = "0.4.3", default-features = false }
rand = "0.8.5"

[dev-dependencies]
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
Expand Down
8 changes: 8 additions & 0 deletions core/src/air/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ pub trait AluAirBuilder: BaseAirBuilder {
c: Word<impl Into<Self::Expr>>,
shard: impl Into<Self::Expr>,
channel: impl Into<Self::Expr>,
nonce: impl Into<Self::Expr>,
multiplicity: impl Into<Self::Expr>,
) {
let values = once(opcode.into())
Expand All @@ -316,6 +317,7 @@ pub trait AluAirBuilder: BaseAirBuilder {
.chain(c.0.into_iter().map(Into::into))
.chain(once(shard.into()))
.chain(once(channel.into()))
.chain(once(nonce.into()))
.collect();

self.send(AirInteraction::new(
Expand All @@ -335,6 +337,7 @@ pub trait AluAirBuilder: BaseAirBuilder {
c: Word<impl Into<Self::Expr>>,
shard: impl Into<Self::Expr>,
channel: impl Into<Self::Expr>,
nonce: impl Into<Self::Expr>,
multiplicity: impl Into<Self::Expr>,
) {
let values = once(opcode.into())
Expand All @@ -343,6 +346,7 @@ pub trait AluAirBuilder: BaseAirBuilder {
.chain(c.0.into_iter().map(Into::into))
.chain(once(shard.into()))
.chain(once(channel.into()))
.chain(once(nonce.into()))
.collect();

self.receive(AirInteraction::new(
Expand All @@ -359,6 +363,7 @@ pub trait AluAirBuilder: BaseAirBuilder {
shard: impl Into<Self::Expr> + Clone,
channel: impl Into<Self::Expr> + Clone,
clk: impl Into<Self::Expr> + Clone,
nonce: impl Into<Self::Expr> + Clone,
syscall_id: impl Into<Self::Expr> + Clone,
arg1: impl Into<Self::Expr> + Clone,
arg2: impl Into<Self::Expr> + Clone,
Expand All @@ -369,6 +374,7 @@ pub trait AluAirBuilder: BaseAirBuilder {
shard.clone().into(),
channel.clone().into(),
clk.clone().into(),
nonce.clone().into(),
syscall_id.clone().into(),
arg1.clone().into(),
arg2.clone().into(),
Expand All @@ -385,6 +391,7 @@ pub trait AluAirBuilder: BaseAirBuilder {
shard: impl Into<Self::Expr> + Clone,
channel: impl Into<Self::Expr> + Clone,
clk: impl Into<Self::Expr> + Clone,
nonce: impl Into<Self::Expr> + Clone,
syscall_id: impl Into<Self::Expr> + Clone,
arg1: impl Into<Self::Expr> + Clone,
arg2: impl Into<Self::Expr> + Clone,
Expand All @@ -395,6 +402,7 @@ pub trait AluAirBuilder: BaseAirBuilder {
shard.clone().into(),
channel.clone().into(),
clk.clone().into(),
nonce.clone().into(),
syscall_id.clone().into(),
arg1.clone().into(),
arg2.clone().into(),
Expand Down
23 changes: 22 additions & 1 deletion core/src/alu/add_sub/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use core::borrow::{Borrow, BorrowMut};
use core::mem::size_of;

use p3_air::{Air, BaseAir};
use p3_air::{Air, AirBuilder, BaseAir};
use p3_field::AbstractField;
use p3_field::PrimeField;
use p3_matrix::dense::RowMajorMatrix;
use p3_matrix::Matrix;
Expand Down Expand Up @@ -38,6 +39,9 @@ pub struct AddSubCols<T> {
/// The channel number, used for byte lookup table.
pub channel: T,

/// The nonce of the operation.
pub nonce: T,

/// Instance of `AddOperation` to handle addition logic in `AddSubChip`'s ALU operations.
/// It's result will be `a` for the add operation and `b` for the sub operation.
pub add_operation: AddOperation<T>,
Expand Down Expand Up @@ -129,6 +133,13 @@ impl<F: PrimeField> MachineAir<F> for AddSubChip {
// Pad the trace to a power of two.
pad_to_power_of_two::<NUM_ADD_SUB_COLS, F>(&mut trace.values);

// Write the nonces to the trace.
for i in 0..trace.height() {
let cols: &mut AddSubCols<F> =
trace.values[i * NUM_ADD_SUB_COLS..(i + 1) * NUM_ADD_SUB_COLS].borrow_mut();
cols.nonce = F::from_canonical_usize(i);
}

trace
}

Expand All @@ -151,6 +162,14 @@ where
let main = builder.main();
let local = main.row_slice(0);
let local: &AddSubCols<AB::Var> = (*local).borrow();
let next = main.row_slice(1);
let next: &AddSubCols<AB::Var> = (*next).borrow();

// Constrain the incrementing nonce.
builder.when_first_row().assert_zero(local.nonce);
builder
.when_transition()
.assert_eq(local.nonce + AB::Expr::one(), next.nonce);

// Evaluate the addition operation.
AddOperation::<AB::F>::eval(
Expand All @@ -172,6 +191,7 @@ where
local.operand_2,
local.shard,
local.channel,
local.nonce,
local.is_add,
);

Expand All @@ -183,6 +203,7 @@ where
local.operand_2,
local.shard,
local.channel,
local.nonce,
local.is_sub,
);

Expand Down
20 changes: 20 additions & 0 deletions core/src/alu/bitwise/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use core::borrow::{Borrow, BorrowMut};
use core::mem::size_of;

use p3_air::AirBuilder;
use p3_air::{Air, BaseAir};
use p3_field::AbstractField;
use p3_field::PrimeField;
use p3_matrix::dense::RowMajorMatrix;
use p3_matrix::Matrix;
Expand Down Expand Up @@ -31,6 +33,9 @@ pub struct BitwiseCols<T> {
/// The channel number, used for byte lookup table.
pub channel: T,

/// The nonce of the operation.
pub nonce: T,

/// The output operand.
pub a: Word<T>,

Expand Down Expand Up @@ -111,6 +116,12 @@ impl<F: PrimeField> MachineAir<F> for BitwiseChip {
// Pad the trace to a power of two.
pad_to_power_of_two::<NUM_BITWISE_COLS, F>(&mut trace.values);

for i in 0..trace.height() {
let cols: &mut BitwiseCols<F> =
trace.values[i * NUM_BITWISE_COLS..(i + 1) * NUM_BITWISE_COLS].borrow_mut();
cols.nonce = F::from_canonical_usize(i);
}

trace
}

Expand All @@ -133,6 +144,14 @@ where
let main = builder.main();
let local = main.row_slice(0);
let local: &BitwiseCols<AB::Var> = (*local).borrow();
let next = main.row_slice(1);
let next: &BitwiseCols<AB::Var> = (*next).borrow();

// Constrain the incrementing nonce.
builder.when_first_row().assert_zero(local.nonce);
builder
.when_transition()
.assert_eq(local.nonce + AB::Expr::one(), next.nonce);

// Get the opcode for the operation.
let opcode = local.is_xor * ByteOpcode::XOR.as_field::<AB::F>()
Expand Down Expand Up @@ -166,6 +185,7 @@ where
local.c,
local.shard,
local.channel,
local.nonce,
local.is_xor + local.is_or + local.is_and,
);

Expand Down
Loading

0 comments on commit 1049583

Please sign in to comment.