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

Feat/benchmark multitier #198

Merged
merged 173 commits into from
Jul 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
eed044d
feat: sorted_limbs chip checking each limb less than limb_bits bits
bfan05 May 29, 2024
473670c
wip
OsamaAlkhodairy May 29, 2024
8792d55
Merge branch 'main' into feat/page_read_write_checker
OsamaAlkhodairy May 29, 2024
023c034
feat: completed sorted_limbs chip with tests
bfan05 May 30, 2024
4c21140
Merge branch 'main' into feat/sort-limbs
bfan05 May 30, 2024
f080051
wip
OsamaAlkhodairy May 31, 2024
6a7fafd
Merge branch 'main' into feat/page_read_write_checker
OsamaAlkhodairy May 31, 2024
a5c0982
feat: SortedLimbsChip with LessThan subchip
bfan05 May 31, 2024
06ada4b
feat: less_than subchip refactored
bfan05 May 31, 2024
0caddfd
chore: merge main
bfan05 May 31, 2024
b349571
feat: rename SortedLimbsChip to AssertSortedChip and write LessThanCh…
bfan05 May 31, 2024
dbada83
chore: change name of assert sorted chip
bfan05 May 31, 2024
b62172a
chore: fix names in tests for AssertSortedChip
bfan05 May 31, 2024
7f8daba
Merge branch 'main' into feat/page_read_write_checker
OsamaAlkhodairy Jun 2, 2024
0cf5509
Merge branch 'main' into feat/sort-limbs
bfan05 Jun 3, 2024
451f4c4
chore: address comments
bfan05 Jun 3, 2024
d77fd08
chore: cleanup
bfan05 Jun 3, 2024
c320b27
Merge branch 'main' into feat/sort-limbs
bfan05 Jun 3, 2024
3c81318
chore: change MAX from generic to instance field for LessThanChip and…
bfan05 Jun 3, 2024
00f38a4
wip: added extra bits to middle chip trace
OsamaAlkhodairy Jun 3, 2024
1aa7cea
Merge branch 'main' into feat/page_read_write_checker
OsamaAlkhodairy Jun 3, 2024
f0c371d
wip
OsamaAlkhodairy Jun 3, 2024
7a7cf4c
adding connection to IsEqualVec chip
OsamaAlkhodairy Jun 4, 2024
296b66f
feat: IsLessThanChip to compare two numbers
bfan05 Jun 4, 2024
c860b80
Merge branch 'main' into feat/sort-limbs
bfan05 Jun 4, 2024
3610e0d
feat: IsLessThanTuple subchip for different limb_bits
bfan05 Jun 4, 2024
8dac425
test: added tests for partially and non-allocated pages
OsamaAlkhodairy Jun 4, 2024
295b3c8
Merge branch 'main' into feat/page_read_write_checker
OsamaAlkhodairy Jun 4, 2024
3811b1c
test: added negative tests
OsamaAlkhodairy Jun 4, 2024
b755a28
added constraints
OsamaAlkhodairy Jun 4, 2024
2ab6964
adding comments
OsamaAlkhodairy Jun 4, 2024
50d54a4
feat: IsLessThanTupleChip subchip in AssertSortedChip
bfan05 Jun 4, 2024
12949c8
renaming
OsamaAlkhodairy Jun 4, 2024
8db7282
removing TODO comments
OsamaAlkhodairy Jun 4, 2024
d35655a
Merge branch 'feat/sort-limbs' into feat/page_read_write_checker
OsamaAlkhodairy Jun 4, 2024
1748721
fixing clippy
OsamaAlkhodairy Jun 4, 2024
ce03626
Add MVP bin
ytham Jun 5, 2024
fcfe0cc
Add MVP bin
ytham Jun 5, 2024
9d3199e
Merge branch 'feat/query-binary' of github.com:axiom-crypto/afs-proto…
ytham Jun 5, 2024
9fe511a
chore: renaming to idx and data
OsamaAlkhodairy Jun 5, 2024
d0ae2cf
chore: address comments first pass
bfan05 Jun 5, 2024
81494d9
Merge branch 'main' into feat/sort-limbs
bfan05 Jun 5, 2024
0099324
chore: moving page_controller inside page_read
OsamaAlkhodairy Jun 5, 2024
664ca0f
Merge branch 'main' into feat/page_read_write_checker
OsamaAlkhodairy Jun 5, 2024
6ca339f
chore: refactor AssertSorted, IsEqual, IsLessThan, and IsLessThanTupl…
bfan05 Jun 5, 2024
aef744a
chore: address comments
bfan05 Jun 5, 2024
5ef5344
Update cache command
ytham Jun 5, 2024
782cd0f
Refactor cmd line items
ytham Jun 5, 2024
38d5dec
chore: eliminate high dim poly from IsLessThanTupleChip
bfan05 Jun 5, 2024
d76a94d
chore: fix tests
bfan05 Jun 5, 2024
eca7ef3
chore: address comments for AssertSortedChip
bfan05 Jun 6, 2024
4890798
chore: cleanup AssertSorted
bfan05 Jun 6, 2024
a086260
chore: cleanup
bfan05 Jun 6, 2024
6896610
chore: include roundtrip flatten and from_slice tests
bfan05 Jun 6, 2024
7c23b03
feat: flatten and from_slice for IO and Aux columns
bfan05 Jun 6, 2024
4ad8d5d
wip
MonkeyKing-1 Jun 6, 2024
64dda36
Merge branch 'feat/sort-limbs' of github.com:axiom-crypto/afs-prototy…
MonkeyKing-1 Jun 6, 2024
771c2a6
wip
MonkeyKing-1 Jun 7, 2024
f62e1bf
merge new sort features
MonkeyKing-1 Jun 7, 2024
aa7a132
complete the merge
MonkeyKing-1 Jun 7, 2024
ed6bfc3
apparently there were more diffs
MonkeyKing-1 Jun 7, 2024
28be1cd
most of testing infra done
MonkeyKing-1 Jun 7, 2024
0f1b2cc
most of testing infra done
MonkeyKing-1 Jun 7, 2024
32f9c1f
finish merge
MonkeyKing-1 Jun 10, 2024
5be7d05
finish merging again
MonkeyKing-1 Jun 10, 2024
dec4535
feat: write tests for general case
MonkeyKing-1 Jun 11, 2024
898d527
Merge branch 'main' of github.com:axiom-crypto/afs-prototype into fea…
MonkeyKing-1 Jun 11, 2024
1a39217
add btree implementation
MonkeyKing-1 Jun 12, 2024
22c8ffb
chore: do some refactors
MonkeyKing-1 Jun 12, 2024
888003c
Merge branch 'main' of github.com:axiom-crypto/afs-prototype into fea…
ytham Jun 12, 2024
53d4652
Merge main
ytham Jun 13, 2024
1d30e42
Mock subcommand + logical interface updates
ytham Jun 13, 2024
b0d4e10
Update interface for reading db
ytham Jun 13, 2024
d181923
Change interface to read
ytham Jun 13, 2024
ad83c52
Change interface to read
ytham Jun 13, 2024
e6f0984
Add write command
ytham Jun 13, 2024
fa34c68
Add output command for write
ytham Jun 13, 2024
de2b2e3
chore: appease clippy (partially)
MonkeyKing-1 Jun 13, 2024
a3e475e
Feat/m1 execution air (#66)
MonkeyKing-1 Jun 13, 2024
e551058
Add print flag to afi command, update readmes
ytham Jun 13, 2024
2cea7ba
Merge branch 'feat/query-binary' of github.com:axiom-crypto/afs-proto…
ytham Jun 13, 2024
019d78d
Update warnings
ytham Jun 13, 2024
e7ce2b9
wip keygen
MonkeyKing-1 Jun 13, 2024
22dd404
finish merge
MonkeyKing-1 Jun 13, 2024
22f4b82
wip: start prove
MonkeyKing-1 Jun 13, 2024
d7b3791
Predicate
ytham Jun 13, 2024
811310b
wip: prove and verify
MonkeyKing-1 Jun 13, 2024
ec8639f
change branches
zlangley Jun 13, 2024
b86515a
Add to_page for Table
ytham Jun 13, 2024
8e4d565
Use btreemap
ytham Jun 14, 2024
2510781
Merge branch 'feat/query-binary' of github.com:axiom-crypto/afs-proto…
ytham Jun 14, 2024
edc37d5
Update functions
ytham Jun 14, 2024
9a02e0d
Update page to/from
ytham Jun 14, 2024
4cdfe07
Update tests
ytham Jun 14, 2024
a5663d9
Add predicate binary
ytham Jun 14, 2024
ec39f03
wip: proof not serializable
zlangley Jun 13, 2024
4813894
finish merge
MonkeyKing-1 Jun 14, 2024
5f1fece
chore: patch stuff
MonkeyKing-1 Jun 14, 2024
f4dd631
add serde bounds
jonathanpwang Jun 14, 2024
7c79646
feat: zk commands (not debugged yet)
MonkeyKing-1 Jun 14, 2024
4e4d2e5
update mockdb
ytham Jun 14, 2024
46782db
wip: mold into new format
MonkeyKing-1 Jun 14, 2024
7c07089
chore: remove extraneous stuff
MonkeyKing-1 Jun 14, 2024
9bb4a7d
[WIP: query-binary] Merge r/w changes (#69)
ytham Jun 17, 2024
1f316ca
feat: merge main and cleanup
MonkeyKing-1 Jun 17, 2024
44ce8da
Tmp: remove predicate
ytham Jun 17, 2024
5326a8c
Resolve merge conflicts
ytham Jun 17, 2024
2e19a54
Update readme
ytham Jun 17, 2024
2fb1947
clean up code
MonkeyKing-1 Jun 17, 2024
7a044bb
feat: rename chips to airs
MonkeyKing-1 Jun 17, 2024
bbb6681
Merge branch 'main' of github.com:axiom-crypto/afs-prototype into fea…
MonkeyKing-1 Jun 17, 2024
3caac57
feat: fix duplication attack
MonkeyKing-1 Jun 17, 2024
7edb798
Update commands for newest rows
ytham Jun 17, 2024
da8889b
feat: migrate to bincode
MonkeyKing-1 Jun 17, 2024
c9e0050
finish merge
MonkeyKing-1 Jun 17, 2024
47335af
finish merge
MonkeyKing-1 Jun 17, 2024
2965b83
feat: add tracing and switch default fri params to log_blowup_factor = 3
jonathanpwang Jun 18, 2024
4a1641b
chore: update logging
jonathanpwang Jun 18, 2024
ff8c9df
Fix readme typo
ytham Jun 18, 2024
14cdaa5
Merge branch 'feat/query-binary' of github.com:axiom-crypto/afs-proto…
ytham Jun 18, 2024
68aad34
Fix clippy warnings
ytham Jun 18, 2024
08cc9d3
finish merge
MonkeyKing-1 Jun 18, 2024
cc2db8d
Merge branch 'feat/query-binary' of github.com:axiom-crypto/afs-proto…
MonkeyKing-1 Jun 18, 2024
2d20cf3
add afs-1b folder
MonkeyKing-1 Jun 18, 2024
fe10dc9
Merge branch 'main' of github.com:axiom-crypto/afs-prototype into fea…
MonkeyKing-1 Jun 18, 2024
6822893
Merge branch 'main' into feat/query-binary
jonathanpwang Jun 18, 2024
9f02efc
Update to handle input byte lengths
ytham Jun 18, 2024
9bad23e
Remove extraneous code
ytham Jun 18, 2024
b322ecb
Revert 9f02efc1bd6d658bda7c7b79f74cafa5ee87bb6c^..9bad23e28c941d33fc2…
ytham Jun 19, 2024
b0b78bd
feat: working query binary
MonkeyKing-1 Jun 19, 2024
4d2c63a
add config file
MonkeyKing-1 Jun 19, 2024
b1eadfd
Update logical interface to add byte lengths
ytham Jun 19, 2024
de0a3ef
Remove generics from logical-interface
ytham Jun 19, 2024
8310cdb
Merge branch 'main' into feat/query-binary
OsamaAlkhodairy Jun 20, 2024
68397d6
finish main merge
MonkeyKing-1 Jun 20, 2024
30bfd22
merging new Offline Checker changes
OsamaAlkhodairy Jun 20, 2024
2ff13db
Merge branch 'main' into feat/query-binary
OsamaAlkhodairy Jun 20, 2024
b1527d3
finish merge with feat/query-binary
MonkeyKing-1 Jun 20, 2024
1836f15
merge main
MonkeyKing-1 Jun 20, 2024
9de1ec4
merge main
MonkeyKing-1 Jun 20, 2024
8d33b66
change page format
MonkeyKing-1 Jun 20, 2024
00540e4
merge new multitier_page_rw updates
MonkeyKing-1 Jun 20, 2024
da1123e
feat: remove btree generics
MonkeyKing-1 Jun 20, 2024
4ce3595
merge feat/multitier_page_rw
MonkeyKing-1 Jun 20, 2024
8f02bec
feat: binsearch optimization for btree
MonkeyKing-1 Jun 20, 2024
8f6fe51
merge btree updates
MonkeyKing-1 Jun 20, 2024
3c52b30
feat: add 1b scripting
MonkeyKing-1 Jun 21, 2024
273fcc6
wip
Jul 11, 2024
e778ab4
finish merge
Jul 11, 2024
fe79381
finish merge
Jul 11, 2024
09dc37c
wip: resolve provertracedata cloen issue
Jul 11, 2024
479752b
benchmark multitier
Jul 19, 2024
56b2c93
finish changes
Jul 22, 2024
c4e246a
finish merge
Jul 22, 2024
86dd35a
wip
Jul 22, 2024
8d33489
wip
Jul 23, 2024
201b164
wip
Jul 24, 2024
d76c95c
merge main
Jul 24, 2024
429f9e6
wip
Jul 24, 2024
ef29c24
merge main
Jul 24, 2024
ab8c9ea
finish merge
Jul 25, 2024
766f842
finish merge
Jul 25, 2024
c86c7df
finish merging
Jul 25, 2024
54d881c
finish cleaning
Jul 26, 2024
70a689e
move files
Jul 26, 2024
0efdfcf
fix cargo.toml
Jul 26, 2024
b620921
wip
Jul 29, 2024
f22ff0b
finish merge
Jul 29, 2024
2cee3b7
wip
Jul 29, 2024
b5d9c77
finish requested changes
Jul 30, 2024
86e2a1e
Merge branch 'main' into feat/benchmark_multitier
MonkeyKing-1 Jul 30, 2024
4c9f93c
fix leaf trace gen
Jul 30, 2024
582df3b
edit comment
Jul 30, 2024
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
Prev Previous commit
Next Next commit
test: added negative tests
  • Loading branch information
OsamaAlkhodairy committed Jun 4, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
danielleadams Danielle Adams
commit 3811b1cfb3cc3ce4b87b8a2e403ab8a3a504a5d7
11 changes: 3 additions & 8 deletions chips/src/is_equal/air.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ use super::columns::{IsEqualCols, IsEqualIOCols, NUM_COLS};
use super::IsEqualChip;
use crate::sub_chip::{AirConfig, SubAir};
use afs_stark_backend::interaction::Chip;
use p3_air::{Air, AirBuilder, BaseAir, FilteredAirBuilder};
use p3_air::{Air, AirBuilder, BaseAir};
use p3_field::AbstractField;
use p3_field::Field;
use p3_matrix::Matrix;
@@ -22,12 +22,7 @@ impl<AB: AirBuilder> Air<AB> for IsEqualChip {
let local = main.row_slice(0);
let is_equal_cols: &IsEqualCols<_> = (*local).borrow();

SubAir::<AB>::eval(
self,
&mut builder.when(AB::Expr::one()),
is_equal_cols.io,
is_equal_cols.inv,
);
SubAir::<AB>::eval(self, builder, is_equal_cols.io, is_equal_cols.inv);
}
}

@@ -42,7 +37,7 @@ impl<AB: AirBuilder> SubAir<AB> for IsEqualChip {
type IoView = IsEqualIOCols<AB::Var>;
type AuxView = AB::Var;

fn eval(&self, builder: &mut FilteredAirBuilder<AB>, io: Self::IoView, inv: Self::AuxView) {
fn eval(&self, builder: &mut AB, io: Self::IoView, inv: Self::AuxView) {
builder.assert_eq((io.x - io.y) * inv + io.is_equal, AB::F::one());
builder.assert_eq((io.x - io.y) * io.is_equal, AB::F::zero());
}
11 changes: 3 additions & 8 deletions chips/src/is_equal_vec/air.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::borrow::Borrow;

use afs_stark_backend::interaction::Chip;
use p3_air::{Air, AirBuilder, BaseAir, FilteredAirBuilder};
use p3_air::{Air, AirBuilder, BaseAir};
use p3_field::AbstractField;
use p3_field::Field;
use p3_matrix::Matrix;
@@ -46,20 +46,15 @@ impl<AB: AirBuilder> Air<AB> for IsEqualVecChip {

let is_equal_vec_cols = IsEqualVecCols::from_slice(local, self.vec_len);

SubAir::<AB>::eval(
self,
&mut builder.when(AB::Expr::one()),
is_equal_vec_cols.io,
is_equal_vec_cols.aux,
);
SubAir::<AB>::eval(self, builder, is_equal_vec_cols.io, is_equal_vec_cols.aux);
}
}

impl<AB: AirBuilder> SubAir<AB> for IsEqualVecChip {
type IoView = IsEqualVecIOCols<AB::Var>;
type AuxView = IsEqualVecAuxCols<AB::Var>;

fn eval(&self, builder: &mut FilteredAirBuilder<AB>, io: Self::IoView, aux: Self::AuxView) {
fn eval(&self, builder: &mut AB, io: Self::IoView, aux: Self::AuxView) {
let IsEqualVecIOCols { x, y, prod: _ } = io;
let IsEqualVecAuxCols { prods, invs } = aux;
let vec_len = self.vec_len;
11 changes: 3 additions & 8 deletions chips/src/is_zero/air.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::borrow::Borrow;

use afs_stark_backend::interaction::Chip;
use p3_air::{Air, AirBuilder, BaseAir, FilteredAirBuilder};
use p3_air::{Air, AirBuilder, BaseAir};
use p3_field::AbstractField;
use p3_field::Field;
use p3_matrix::Matrix;
@@ -33,20 +33,15 @@ impl<AB: AirBuilder> Air<AB> for IsZeroChip {
let local = main.row_slice(0);
let is_zero_cols: &IsZeroCols<_> = (*local).borrow();

SubAir::<AB>::eval(
self,
&mut builder.when(AB::Expr::one()),
is_zero_cols.io,
is_zero_cols.inv,
);
SubAir::<AB>::eval(self, builder, is_zero_cols.io, is_zero_cols.inv);
}
}

impl<AB: AirBuilder> SubAir<AB> for IsZeroChip {
type IoView = IsZeroIOCols<AB::Var>;
type AuxView = AB::Var;

fn eval(&self, builder: &mut FilteredAirBuilder<AB>, io: Self::IoView, inv: Self::AuxView) {
fn eval(&self, builder: &mut AB, io: Self::IoView, inv: Self::AuxView) {
builder.assert_eq(io.x * io.is_zero, AB::F::zero());
builder.assert_eq(io.is_zero + io.x * inv, AB::F::one());
}
2 changes: 0 additions & 2 deletions chips/src/page_read_write/init_final_chip/trace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::iter;

use p3_field::AbstractField;
use p3_matrix::dense::RowMajorMatrix;
use p3_uni_stark::{StarkGenericConfig, Val};
38 changes: 23 additions & 15 deletions chips/src/page_read_write/middle_chip/air.rs
Original file line number Diff line number Diff line change
@@ -7,11 +7,7 @@ use p3_matrix::Matrix;

use super::{columns::MiddleChipCols, MiddleChip};
use crate::{
is_equal::columns::IsEqualIOCols,
is_equal_vec::{
columns::{IsEqualVecCols, IsEqualVecIOCols},
IsEqualVecChip,
},
is_equal_vec::{columns::IsEqualVecCols, IsEqualVecChip},
sub_chip::{AirConfig, SubAir},
};

@@ -41,8 +37,6 @@ where
fn eval(&self, builder: &mut AB) {
let main = &builder.partitioned_main()[0].clone();

// let main = builder.main();

let (local, next) = (main.row_slice(0), main.row_slice(1));
let local: &[AB::Var] = (*local).borrow();
let next: &[AB::Var] = (*next).borrow();
@@ -68,23 +62,38 @@ where
builder.when_first_row().assert_zero(local_cols.same_key);
builder.when_first_row().assert_zero(local_cols.same_val);

let is_equal_cols_vec = local_cols.page_row[1..self.key_len + 1]
// Making sure same_key is correct across rows
let is_equal_keys_vec = local_cols.page_row[1..self.key_len + 1]
.to_vec()
.into_iter()
.chain(next_cols.page_row[1..self.key_len + 1].to_vec())
.chain(next_cols.is_equal_key_aux.flatten())
.collect::<Vec<AB::Var>>();
let is_equal_keys = IsEqualVecCols::from_slice(&is_equal_keys_vec, self.key_len);
let is_equal_keys_chip = IsEqualVecChip::new(self.key_len);

let is_equal_cols = IsEqualVecCols::from_slice(&is_equal_cols_vec, self.key_len);
SubAir::eval(
&is_equal_keys_chip,
&mut builder.when_transition(),
is_equal_keys.io,
is_equal_keys.aux,
);

let is_equal_vec_chip = IsEqualVecChip::new(self.key_len);
// Making sure same_val is correct across rows
let is_equal_vals_vec = local_cols.page_row[self.key_len + 1..]
.to_vec()
.into_iter()
.chain(next_cols.page_row[self.key_len + 1..].to_vec())
.chain(next_cols.is_equal_val_aux.flatten())
.collect::<Vec<AB::Var>>();
let is_equal_vals = IsEqualVecCols::from_slice(&is_equal_vals_vec, self.val_len);
let is_equal_vals_chip = IsEqualVecChip::new(self.val_len);

// TODO: make sure same_key and same_val are correct for the rest of the rows
SubAir::eval(
&is_equal_vec_chip,
&is_equal_vals_chip,
&mut builder.when_transition(),
is_equal_cols.io,
is_equal_cols.aux,
is_equal_vals.io,
is_equal_vals.aux,
);

// TODO: make sure all rows are sorted
@@ -127,7 +136,6 @@ where

// Making sure that every read uses the same value as the last operation
// read => same_val
println!("local_cols: {:?}", local_cols);
builder.assert_one(or(
local_cols.is_extra.into(),
or(local_cols.op_type.into(), local_cols.same_val.into()),
4 changes: 2 additions & 2 deletions chips/src/page_read_write/middle_chip/chip.rs
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ impl<F: PrimeField64> Chip<F> for MiddleChip {
let num_cols = self.air_width();
let all_cols = (0..num_cols).collect::<Vec<usize>>();

let cols_to_receive = MiddleChipCols::<F>::cols_numbered(
let cols_to_receive = MiddleChipCols::<usize>::from_slice(
&all_cols,
self.page_width(),
self.key_len,
@@ -55,7 +55,7 @@ impl<F: PrimeField64> Chip<F> for MiddleChip {
let num_cols = self.air_width();
let all_cols = (0..num_cols).collect::<Vec<usize>>();

let cols_to_send = MiddleChipCols::<F>::cols_numbered(
let cols_to_send = MiddleChipCols::<usize>::from_slice(
&all_cols,
self.page_width(),
self.key_len,
52 changes: 10 additions & 42 deletions chips/src/page_read_write/middle_chip/columns.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use crate::is_equal_vec::columns::IsEqualVecAuxCols;

// TODO: maybe separate into two structs, io and aux
// TODO: add comments on what those bits do
#[derive(Debug)]
pub struct MiddleChipCols<T> {
pub is_initial: T,
pub is_final: T,
pub clk: T,
pub page_row: Vec<T>,
pub op_type: T, // 0 for read, 1 for write
pub is_initial: T, // this bit indicates if this row comes from the initial page
pub is_final: T, // this bit indicates if this row should go to the final page (last row for the key)

pub same_key: T,
pub same_val: T,
pub clk: T, // timestamp for the operation
pub page_row: Vec<T>, // the row of the page: starts with is_alloc bit, then key, then val
pub op_type: T, // 0 for read, 1 for write

pub same_key: T, // this bit indicates if the key matches the one in the previous row (should be 0 in first row)
pub same_val: T, // this bit indicates if the val matches the one in the previous row (should be 0 in first row)

pub is_extra: T, // a bit to indicate if this is an extra row that should be ignored

pub is_equal_key_aux: IsEqualVecAuxCols<T>,
pub is_equal_val_aux: IsEqualVecAuxCols<T>,
pub is_equal_key_aux: IsEqualVecAuxCols<T>, // auxiliary columns used for same_key
pub is_equal_val_aux: IsEqualVecAuxCols<T>, // auxiliary columns used for same_val
}

impl<T> MiddleChipCols<T>
@@ -74,7 +74,6 @@ where
flattened
}

// TODO: is there a way to merge from_slice and cols_numbered?
pub fn from_slice(slc: &[T], page_width: usize, key_len: usize, val_len: usize) -> Self {
Self {
is_initial: slc[0].clone(),
@@ -95,35 +94,4 @@ where
),
}
}

pub fn cols_numbered(
cols: &[usize],
page_width: usize,
key_len: usize,
val_len: usize,
) -> MiddleChipCols<usize> {
println!("cols numbered: {} {} {}", page_width, key_len, val_len);
println!("cols_len: {}", cols.len());

MiddleChipCols {
is_initial: cols[0],
is_final: cols[1],
clk: cols[2],
page_row: cols[3..3 + page_width].to_vec(),
op_type: cols[3 + page_width],
same_key: cols[4 + page_width],
same_val: cols[5 + page_width],
is_extra: cols[6 + page_width],
is_equal_key_aux: IsEqualVecAuxCols::new(
cols[7 + page_width..7 + page_width + key_len].to_vec(),
cols[7 + page_width + key_len..7 + page_width + 2 * key_len].to_vec(),
),
is_equal_val_aux: IsEqualVecAuxCols::new(
cols[7 + page_width + 2 * key_len..7 + page_width + 2 * key_len + val_len].to_vec(),
cols[7 + page_width + 2 * key_len + val_len
..7 + page_width + 2 * key_len + 2 * val_len]
.to_vec(),
),
}
}
}
2 changes: 0 additions & 2 deletions chips/src/page_read_write/middle_chip/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use super::page_controller::Operation;

mod air;
mod chip;
mod columns;
24 changes: 20 additions & 4 deletions chips/src/page_read_write/middle_chip/trace.rs
Original file line number Diff line number Diff line change
@@ -53,7 +53,8 @@ impl MiddleChip {
.collect::<Vec<Val<SC>>>()
};

let gen_row = |page: &mut Vec<Vec<u32>>,
let gen_row = |is_first_row: &mut bool,
page: &mut Vec<Vec<u32>>,
index: usize,
is_initial: u8,
is_final: u8,
@@ -72,6 +73,17 @@ impl MiddleChip {
let cur_key = page[index][1..self.key_len + 1].to_vec();
let cur_val = page[index][self.key_len + 1..].to_vec();

if *is_first_row {
// Making sure the last_key and last_val are different from current when its the first row
*last_key = cur_key.clone();
*last_val = cur_val.clone();

last_key[0] += 1;
last_val[0] += 1;

*is_first_row = false;
}

let my_last_key = last_key.clone();
let my_last_val = last_val.clone();

@@ -118,9 +130,9 @@ impl MiddleChip {

let mut rows = vec![];

// TODO: do I need to make sure this is different than first actual row?
let mut last_key = vec![4234233; self.key_len];
let mut last_val = vec![3534543; self.val_len];
let mut last_key = vec![0; self.key_len];
let mut last_val = vec![0; self.val_len];
let mut is_first_row = true;

let mut i = 0;
while i < ops.len() {
@@ -137,6 +149,7 @@ impl MiddleChip {
idx = *key_index_map.get(&cur_key).unwrap();

rows.push(gen_row(
&mut is_first_row,
page,
idx,
1,
@@ -161,6 +174,7 @@ impl MiddleChip {
.collect();

rows.push(gen_row(
&mut is_first_row,
page,
idx,
0,
@@ -175,6 +189,7 @@ impl MiddleChip {

// Adding the is_final row to the trace
rows.push(gen_row(
&mut is_first_row,
page,
idx,
0,
@@ -195,6 +210,7 @@ impl MiddleChip {
// Adding rows to the trace to make the height trace_degree
while rows.len() < trace_degree {
rows.push(gen_row(
&mut is_first_row,
page,
0,
0,
6 changes: 3 additions & 3 deletions chips/src/page_read_write/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod init_final_chip;
mod middle_chip;
mod page_controller;
pub mod init_final_chip;
pub mod middle_chip;
pub mod page_controller;

#[cfg(test)]
pub mod tests;
9 changes: 4 additions & 5 deletions chips/src/page_read_write/page_controller/mod.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ use p3_field::AbstractField;
use p3_matrix::dense::{DenseMatrix, RowMajorMatrix};
use p3_matrix::Matrix;
use p3_uni_stark::{StarkGenericConfig, Val};
use std::collections::HashMap;

use super::init_final_chip::InitFinalChip;
use super::middle_chip::MiddleChip;
@@ -52,11 +51,11 @@ where
}

impl<SC: StarkGenericConfig> PageController<SC> {
pub fn new(bus_index: usize) -> Self {
pub fn new(bus_index: usize, key_len: usize, val_len: usize) -> Self {
Self {
init_chip: InitFinalChip::new(bus_index, 1, true),
middle_chip: MiddleChip::new(bus_index, 1, 1),
final_chip: InitFinalChip::new(bus_index, 1, false),
init_chip: InitFinalChip::new(bus_index, 1 + key_len + val_len, true),
middle_chip: MiddleChip::new(bus_index, key_len, val_len),
final_chip: InitFinalChip::new(bus_index, 1 + key_len + val_len, false),

init_chip_trace: None,
middle_chip_trace: None,
Loading