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/Verify Aggregation VM with binary #89

Merged
merged 93 commits into from
Jun 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
ac1f18c
Create stark-vm crate
TlatoaniHJ Jun 18, 2024
aaf5c55
Add lib.rs, add afs-chips dependency, add CPU chip
TlatoaniHJ Jun 18, 2024
74f86d8
Make and use OpCode enum
TlatoaniHJ Jun 18, 2024
6698d7f
Refactor CPU tests
TlatoaniHJ Jun 18, 2024
b436471
Add program chip
TlatoaniHJ Jun 19, 2024
c8c6535
Actually add program chip
TlatoaniHJ Jun 19, 2024
13e7fd8
feat: imp arithmetic unit, minus tests
Jun 19, 2024
b73125c
chore: merge branch 'feat/vm' of github.com:axiom-crypto/afs-prototyp…
Jun 19, 2024
65c8d30
Use destructuring in cpu/air.rs
TlatoaniHJ Jun 19, 2024
33c40e8
Merge branch 'feat/vm' of https://github.com/axiom-crypto/afs-prototy…
TlatoaniHJ Jun 19, 2024
66d8057
Add negative test for CPU
TlatoaniHJ Jun 19, 2024
61ce20e
Reformat cpu and program
TlatoaniHJ Jun 19, 2024
c99b9df
chore: fix generate_trace, remove AUChip and replace with AUAir
Jun 20, 2024
f5080bf
Merge branch 'feat/vm' of github.com:axiom-crypto/afs-prototype into …
Jun 20, 2024
d09b186
Add explanations for test programs
TlatoaniHJ Jun 20, 2024
0a1dfaf
Merge branch 'feat/vm' of https://github.com/axiom-crypto/afs-prototy…
TlatoaniHJ Jun 20, 2024
d581205
chore: resolve conflict
bfan05 Jun 20, 2024
e8dbabf
Derive new for instruction
TlatoaniHJ Jun 20, 2024
2abdbcc
Merge branch 'feat/vm' of https://github.com/axiom-crypto/afs-prototy…
TlatoaniHJ Jun 20, 2024
d784145
chore: change Operation to MemoryAccess
bfan05 Jun 20, 2024
90a17d1
Align MemoryAccess with memory chip
TlatoaniHJ Jun 20, 2024
c956771
fix(au): width misalignment, incorrect trace generation
Jun 20, 2024
bd61350
Merge branch 'feat/vm' of github.com:axiom-crypto/afs-prototype into …
Jun 20, 2024
70e3730
fix(au bridge): positive tests run
Jun 20, 2024
5416c69
fix(trace): fix bug in AUCols::new, add negative tests
Jun 20, 2024
684dc4f
chore: rename AUAir -> FieldArithmeticAir, remove AUChip
Jun 20, 2024
6f907f6
Add terminate instruction
TlatoaniHJ Jun 20, 2024
e7f1846
chore: un-expand constraints using AB::Expr::one()
Jun 20, 2024
106e1c0
Address some zlangley comments
TlatoaniHJ Jun 20, 2024
892628c
docs(au)
Jun 20, 2024
578bbf4
Commit zlangley suggestion
TlatoaniHJ Jun 20, 2024
8b8cb47
merge: Merge branch 'feat/vm' of github.com:axiom-crypto/afs-prototyp…
Jun 20, 2024
d8d2fc6
Commit zlangley suggestion
TlatoaniHJ Jun 20, 2024
68a16e5
Merge branch 'feat/vm' of github.com:axiom-crypto/afs-prototype into …
Jun 20, 2024
c53d5a9
Make inst_width.clone() unnecessary
TlatoaniHJ Jun 20, 2024
526b7c7
Address zlangley comment
TlatoaniHJ Jun 20, 2024
d829bc0
Rename as_b, as_c to d, e
TlatoaniHJ Jun 20, 2024
f3990b9
feat: Memory op interactions
bfan05 Jun 20, 2024
5955589
Add negative test for termination check
TlatoaniHJ Jun 20, 2024
7bdbd00
Merge branch 'feat/vm' of https://github.com/axiom-crypto/afs-prototy…
TlatoaniHJ Jun 20, 2024
ea4e33d
Add failing test for secret write vulnerability
TlatoaniHJ Jun 20, 2024
7ed127c
Add failing test for disable write vulnerability
TlatoaniHJ Jun 20, 2024
754643e
Add failing test for disable read vulnerability
TlatoaniHJ Jun 20, 2024
534e322
Check access enabled in AIR
TlatoaniHJ Jun 20, 2024
365d694
Actually fix access enabled check
TlatoaniHJ Jun 20, 2024
f783a5c
Simplify cpu/tests/mod.rs
TlatoaniHJ Jun 20, 2024
821e7bc
Don't mock arithmetic chip when testing with is_field_arithmetic = false
TlatoaniHJ Jun 20, 2024
b4f59bc
chore: add test for invalid read
bfan05 Jun 20, 2024
becd9a6
Attempt to write integration test
TlatoaniHJ Jun 20, 2024
cdb3662
Merge branch 'feat/vm' of https://github.com/axiom-crypto/afs-prototy…
TlatoaniHJ Jun 20, 2024
f7f9d47
Conditionally use arith chip in integration test
TlatoaniHJ Jun 20, 2024
7c4e59b
Fix integration test wrt range checker
TlatoaniHJ Jun 20, 2024
88aacf8
Lint
TlatoaniHJ Jun 21, 2024
d46bcf9
Use unique memory timestamp instead of clock cycle
TlatoaniHJ Jun 24, 2024
011e3ae
Merge branch 'main' into feat/vm-bin
TlatoaniHJ Jun 24, 2024
d5ebe91
chore: rename MemoryAccess clock field to timestamp
bfan05 Jun 24, 2024
e86a7ab
feat: change default FRI config to blowup factor 4 (#73)
jonathanpwang Jun 18, 2024
c75ff83
feat: Offline Checker delete support (#74)
OsamaAlkhodairy Jun 20, 2024
0a1b361
feat: add engines for BabyBear with blake3 and keccak256 (#78)
jonathanpwang Jun 20, 2024
86e17fb
chore: auto-implement `Rap` when builder is not `Sync` (#80)
jonathanpwang Jun 20, 2024
f2a0614
[feat] Query binary (#46)
ytham Jun 21, 2024
34597bc
perf: Offline Checker Optimization (#82)
OsamaAlkhodairy Jun 21, 2024
087c530
Add macros for testing
ytham Jun 21, 2024
3ab513d
Additional tests
ytham Jun 21, 2024
fbbba0d
Remove unused function
ytham Jun 21, 2024
b55d64d
Update naming and add comment
ytham Jun 21, 2024
cac966e
Feat/rename page air update from slice (#84)
MonkeyKing-1 Jun 23, 2024
9acf484
VM binary
TlatoaniHJ Jun 24, 2024
11cc318
Merge branch 'feat/vm-bin' of https://github.com/axiom-crypto/afs-pro…
TlatoaniHJ Jun 24, 2024
740be67
Merge branch 'main' into feat/vm-bin
TlatoaniHJ Jun 25, 2024
ee10f3b
Merge branch 'main' into feat/vm-bin
TlatoaniHJ Jun 25, 2024
0eb9571
Resolve merge conflicts
TlatoaniHJ Jun 25, 2024
7bbf0fb
Add back fibonacci integration test
TlatoaniHJ Jun 25, 2024
d5e3679
Redo CLI test
TlatoaniHJ Jun 25, 2024
8eaa6d5
Remove extraneous au directory
TlatoaniHJ Jun 25, 2024
412a9bd
Fix lint
TlatoaniHJ Jun 25, 2024
11ab41a
Remove keys and proof
TlatoaniHJ Jun 26, 2024
6838565
Remove commented code
TlatoaniHJ Jun 26, 2024
a255aee
Use FromStr to parse OpCode
TlatoaniHJ Jun 26, 2024
26046a9
VM* -> Vm*, VM -> VirtualMachine
TlatoaniHJ Jun 26, 2024
a6e8300
Return Result from VmConfig::read_config_file
TlatoaniHJ Jun 26, 2024
88f4014
Minor zlangley comments
TlatoaniHJ Jun 26, 2024
38660c1
Remove 8
TlatoaniHJ Jun 26, 2024
ff44277
Use zip for chips and traces
TlatoaniHJ Jun 26, 2024
103b89d
zip_eq -> zip
TlatoaniHJ Jun 26, 2024
5d8e6a9
Use Path and replace unwrap with ?
TlatoaniHJ Jun 26, 2024
a9be406
Removed unnecessary casts
TlatoaniHJ Jun 26, 2024
e576def
Fix lint
TlatoaniHJ Jun 26, 2024
bf9950f
Address jonathan comments, fix proof file path
TlatoaniHJ Jun 26, 2024
e42414c
Delete prove.bin
TlatoaniHJ Jun 26, 2024
732a3ab
Use zip_eq and remove unnecessary clones
TlatoaniHJ Jun 26, 2024
332525d
Use eyre::Result in asm/mod.rs
TlatoaniHJ Jun 26, 2024
2478e00
Fix lint
TlatoaniHJ Jun 26, 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
chore: rename AUAir -> FieldArithmeticAir, remove AUChip
Alex Zhao committed Jun 20, 2024
commit 684dc4f50b2e0df0b776c9bb03c031cda0c36e0b
18 changes: 9 additions & 9 deletions vm/src/au/air.rs
Original file line number Diff line number Diff line change
@@ -4,35 +4,35 @@ use p3_air::{Air, AirBuilder, BaseAir};
use p3_field::{AbstractField, Field};
use p3_matrix::Matrix;

use super::{columns::AUCols, AUAir};
use super::{columns::FieldArithmeticCols, FieldArithmeticAir};
use afs_chips::sub_chip::AirConfig;

impl AirConfig for AUAir {
type Cols<T> = AUCols<T>;
impl AirConfig for FieldArithmeticAir {
type Cols<T> = FieldArithmeticCols<T>;
}

impl<F: Field> BaseAir<F> for AUAir {
impl<F: Field> BaseAir<F> for FieldArithmeticAir {
fn width(&self) -> usize {
AUCols::<F>::NUM_COLS
FieldArithmeticCols::<F>::NUM_COLS
}
}

impl<AB: AirBuilder> Air<AB> for AUAir {
impl<AB: AirBuilder> Air<AB> for FieldArithmeticAir {
fn eval(&self, builder: &mut AB) {
let main = builder.main();

let local = main.row_slice(0);
let au_cols: &AUCols<_> = (*local).borrow();
let au_cols: &FieldArithmeticCols<_> = (*local).borrow();

let AUCols { io, aux } = au_cols;
let FieldArithmeticCols { io, aux } = au_cols;

builder.assert_bool(aux.opcode_0bit);
builder.assert_bool(aux.opcode_1bit);
builder.assert_eq(
io.opcode,
aux.opcode_0bit
+ aux.opcode_1bit * AB::F::two()
+ AB::F::from_canonical_u8(AUAir::BASE_OP),
+ AB::F::from_canonical_u8(FieldArithmeticAir::BASE_OP),
);

builder.assert_eq(
6 changes: 3 additions & 3 deletions vm/src/au/bridge.rs
Original file line number Diff line number Diff line change
@@ -2,9 +2,9 @@ use afs_stark_backend::interaction::{AirBridge, Interaction};
use p3_air::VirtualPairCol;
use p3_field::Field;

use crate::au::{columns::AUCols, AUAir};
use crate::au::{columns::FieldArithmeticCols, FieldArithmeticAir};

impl<T: Field> AirBridge<T> for AUAir {
impl<T: Field> AirBridge<T> for FieldArithmeticAir {
fn receives(&self) -> Vec<Interaction<T>> {
// (0..AUCols::<T>::NUM_IO_COLS)
// .map(|i| Interaction {
@@ -13,7 +13,7 @@ impl<T: Field> AirBridge<T> for AUAir {
// argument_index: Self::BUS_INDEX,
// })
vec![Interaction {
fields: (0..AUCols::<T>::NUM_IO_COLS)
fields: (0..FieldArithmeticCols::<T>::NUM_IO_COLS)
.map(VirtualPairCol::single_main)
.collect(),
count: VirtualPairCol::one(),
24 changes: 12 additions & 12 deletions vm/src/au/columns.rs
Original file line number Diff line number Diff line change
@@ -2,22 +2,22 @@ use crate::cpu::OpCode;
use afs_derive::AlignedBorrow;
use p3_field::Field;

use crate::au::AUAir;
use crate::au::FieldArithmeticAir;

#[derive(AlignedBorrow)]
pub struct AUCols<T> {
pub io: AUIOCols<T>,
pub aux: AUAuxCols<T>,
pub struct FieldArithmeticCols<T> {
pub io: FieldArithmeticIOCols<T>,
pub aux: FieldArithmeticAuxCols<T>,
}

pub struct AUIOCols<T> {
pub struct FieldArithmeticIOCols<T> {
pub opcode: T,
pub x: T,
pub y: T,
pub z: T,
}

pub struct AUAuxCols<T> {
pub struct FieldArithmeticAuxCols<T> {
pub opcode_0bit: T,
pub opcode_1bit: T,
pub is_mul: T,
@@ -27,7 +27,7 @@ pub struct AUAuxCols<T> {
pub div_result: T,
}

impl<T> AUCols<T>
impl<T> FieldArithmeticCols<T>
where
T: Field,
{
@@ -37,7 +37,7 @@ where

pub fn new(op: OpCode, x: T, y: T) -> Self {
let opcode = op as u32;
let opcode_value = opcode - AUAir::BASE_OP as u32;
let opcode_value = opcode - FieldArithmeticAir::BASE_OP as u32;
let opcode_0bit_u32 = opcode_value % 2;
let opcode_1bit_u32 = opcode_value / 2;
let opcode_0bit = T::from_canonical_u32(opcode_0bit_u32);
@@ -50,13 +50,13 @@ where
let z = is_mul * mul_result + is_div * div_result + (T::one() - opcode_1bit) * lin_term;

Self {
io: AUIOCols {
io: FieldArithmeticIOCols {
opcode: T::from_canonical_u32(opcode),
x,
y,
z,
},
aux: AUAuxCols {
aux: FieldArithmeticAuxCols {
opcode_0bit,
opcode_1bit,
is_mul,
@@ -79,7 +79,7 @@ where
}
}

impl<T: Field> AUIOCols<T> {
impl<T: Field> FieldArithmeticIOCols<T> {
pub fn get_width() -> usize {
4
}
@@ -89,7 +89,7 @@ impl<T: Field> AUIOCols<T> {
}
}

impl<T: Field> AUAuxCols<T> {
impl<T: Field> FieldArithmeticAuxCols<T> {
pub fn get_width() -> usize {
7
}
9 changes: 2 additions & 7 deletions vm/src/au/mod.rs
Original file line number Diff line number Diff line change
@@ -11,14 +11,9 @@ pub mod columns;
pub mod trace;

#[derive(Default, Clone, Copy)]
pub struct AUAir {}
pub struct FieldArithmeticAir {}

pub struct AUChip<T> {
pub air: AUAir,
pub arithmetic_operations: Vec<ArithmeticOperation<T>>,
}

impl AUAir {
impl FieldArithmeticAir {
pub const BASE_OP: u8 = 5;
pub const BUS_INDEX: usize = 2;

19 changes: 11 additions & 8 deletions vm/src/au/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::au::columns::AUIOCols;
use crate::au::AUAir;
use crate::au::columns::FieldArithmeticIOCols;
use crate::au::FieldArithmeticAir;
use crate::cpu::trace::ProgramExecution;
use crate::cpu::OpCode;
use afs_stark_backend::prover::USE_DEBUG_BUILDER;
@@ -25,7 +25,7 @@ fn generate_arith_program(len_ops: usize) -> ProgramExecution<BabyBear> {
)
})
.collect();
let arith_ops = AUAir::request(ops, operands);
let arith_ops = FieldArithmeticAir::request(ops, operands);

ProgramExecution {
program: vec![],
@@ -41,7 +41,7 @@ fn au_air_test() {
let mut rng = create_seeded_rng();
let len_ops = 1 << 5;
let prog = generate_arith_program(len_ops);
let au_air = AUAir::new();
let au_air = FieldArithmeticAir::new();

let dummy_trace = RowMajorMatrix::new(
prog.arithmetic_ops
@@ -54,13 +54,16 @@ fn au_air_test() {
.collect::<Vec<_>>()
})
.collect(),
AUIOCols::<BabyBear>::get_width() + 1,
FieldArithmeticIOCols::<BabyBear>::get_width() + 1,
);

let mut au_trace = au_air.generate_trace(&prog);

let page_requester =
DummyInteractionAir::new(AUIOCols::<BabyBear>::get_width(), true, AUAir::BUS_INDEX);
let page_requester = DummyInteractionAir::new(
FieldArithmeticIOCols::<BabyBear>::get_width(),
true,
FieldArithmeticAir::BUS_INDEX,
);

// positive test
run_simple_test_no_pis(
@@ -70,7 +73,7 @@ fn au_air_test() {
.expect("Verification failed");

for height in 0..(prog.arithmetic_ops.len()) {
for width in 0..AUIOCols::<BabyBear>::get_width() {
for width in 0..FieldArithmeticIOCols::<BabyBear>::get_width() {
let prank_value = BabyBear::from_canonical_u32(rng.gen_range(1..=100));
au_trace.row_mut(height)[width] = prank_value;
}
10 changes: 5 additions & 5 deletions vm/src/au/trace.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use p3_field::Field;
use p3_matrix::dense::RowMajorMatrix;

use crate::au::columns::AUCols;
use crate::au::columns::FieldArithmeticCols;
use crate::cpu::trace::ProgramExecution;

use super::AUAir;
use super::FieldArithmeticAir;

impl AUAir {
impl FieldArithmeticAir {
pub fn generate_trace<T: Field>(&self, prog_exec: &ProgramExecution<T>) -> RowMajorMatrix<T> {
let trace = prog_exec
.arithmetic_ops
.iter()
.flat_map(|op| {
let cols = AUCols::new(op.opcode, op.operand1, op.operand2);
let cols = FieldArithmeticCols::new(op.opcode, op.operand1, op.operand2);
cols.flatten()
})
.collect();

RowMajorMatrix::new(trace, AUCols::<T>::NUM_COLS)
RowMajorMatrix::new(trace, FieldArithmeticCols::<T>::NUM_COLS)
}
}