Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.

Commit 884877e

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/ir-enhancements
2 parents 5deab01 + a9a83b8 commit 884877e

27 files changed

Lines changed: 1633 additions & 605 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@ noname.0.7.0
2+
@ public inputs: 3
3+
4+
DoubleGeneric<1>
5+
DoubleGeneric<1>
6+
DoubleGeneric<1>
7+
DoubleGeneric<1,0,0,0,-3>
8+
DoubleGeneric<1,0,0,0,-3>
9+
DoubleGeneric<1,0,0,0,-1>
10+
DoubleGeneric<1,0,0,0,-2>
11+
DoubleGeneric<1,0,-1,0,2>
12+
DoubleGeneric<1,0,0,0,-5>
13+
DoubleGeneric<1,0,0,0,-1>
14+
DoubleGeneric<1,0,0,0,-2>
15+
DoubleGeneric<1,0,-1,0,2>
16+
DoubleGeneric<0,0,-1,1>
17+
DoubleGeneric<1,1,-1>
18+
DoubleGeneric<1,1,-1>
19+
DoubleGeneric<1,0,0,0,-5>
20+
DoubleGeneric<1,0,0,0,-1>
21+
DoubleGeneric<1,0,0,0,-1>
22+
DoubleGeneric<1,0,0,0,-2>
23+
DoubleGeneric<1,0,0,0,-3>
24+
DoubleGeneric<1,0,0,0,-4>
25+
DoubleGeneric<1,0,0,0,-5>
26+
(0,0) -> (5,0) -> (9,0) -> (12,1) -> (13,0) -> (16,0) -> (17,0)
27+
(1,0) -> (6,0) -> (10,0) -> (14,0) -> (18,0)
28+
(2,0) -> (3,0) -> (4,0) -> (7,0) -> (11,0) -> (12,0) -> (14,1) -> (19,0)
29+
(7,2) -> (8,0)
30+
(11,2) -> (15,0)
31+
(12,2) -> (13,1)
32+
(13,2) -> (20,0)
33+
(14,2) -> (21,0)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@ noname.0.7.0
2+
@ public inputs: 3
3+
4+
3 == (v_3) * (1)
5+
3 == (v_3) * (1)
6+
1 == (v_1) * (1)
7+
2 == (v_2) * (1)
8+
5 == (v_3 + 2) * (1)
9+
1 == (v_1) * (1)
10+
2 == (v_2) * (1)
11+
v_4 == (v_3) * (v_1)
12+
5 == (v_3 + 2) * (1)
13+
1 == (v_1) * (1)
14+
1 == (v_1) * (1)
15+
2 == (v_2) * (1)
16+
3 == (v_3) * (1)
17+
4 == (v_1 + v_4) * (1)
18+
5 == (v_2 + v_3) * (1)

examples/functions.no

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ fn main(pub one: Field) {
1010
let four = add(one, 3);
1111
assert_eq(four, 4);
1212

13+
// double() should not be folded to return 8
14+
// the asm test will catch the missing constraint if it is folded
1315
let eight = double(4);
1416
assert_eq(eight, double(four));
1517
}

examples/generic_assert_eq.no

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const size = 2;
2+
struct Thing {
3+
xx: Field,
4+
yy: [Field; 2],
5+
}
6+
7+
struct Nestedthing {
8+
xx: Field,
9+
another: [Another; 2],
10+
}
11+
12+
struct Another {
13+
aa: Field,
14+
bb: [Field; 2],
15+
}
16+
17+
fn init_arr(element: Field, const LEN: Field) -> [Field; LEN] {
18+
let arr = [element; LEN];
19+
return arr;
20+
}
21+
22+
fn main(pub public_arr: [Field; 2], pub public_input: Field) {
23+
let generic_arr = init_arr(public_input, size);
24+
let arr = [3, 3];
25+
26+
assert_eq(generic_arr, arr);
27+
let mut concrete_arr = [1, 2];
28+
29+
// instead of the following:
30+
// assert_eq(public_arr[0], concrete_arr[0]);
31+
// assert_eq(public_arr[1], concrete_arr[1]);
32+
// we can write:
33+
assert_eq(public_arr, concrete_arr);
34+
35+
let thing = Thing { xx: 5, yy: [1, 2] };
36+
let other_thing = Thing { xx: generic_arr[0] + 2, yy: public_arr };
37+
38+
// instead of the following:
39+
// assert_eq(thing.xx, other_thing.xx);
40+
// assert_eq(thing.yy[0], other_thing.yy[0]);
41+
// assert_eq(thing.yy[1], other_thing.yy[1]);
42+
// we can write:
43+
assert_eq(thing, other_thing);
44+
45+
let nested_thing = Nestedthing { xx: 5, another: [
46+
Another { aa: public_arr[0], bb: [1, 2] },
47+
Another { aa: generic_arr[1], bb: [4, 5] }
48+
] };
49+
let other_nested_thing = Nestedthing { xx: generic_arr[0] + 2, another: [
50+
Another { aa: 1, bb: public_arr },
51+
Another { aa: 3, bb: [public_arr[0] + (public_input * public_arr[0]), public_arr[1] + public_input] }
52+
] };
53+
54+
// instead of the following:
55+
// assert_eq(nested_thing.xx, other_nested_thing.xx);
56+
// assert_eq(nested_thing.another[0].aa, other_nested_thing.another[0].aa);
57+
// assert_eq(nested_thing.another[0].bb[0], other_nested_thing.another[0].bb[0]);
58+
// assert_eq(nested_thing.another[0].bb[1], other_nested_thing.another[0].bb[1]);
59+
// assert_eq(nested_thing.another[1].aa, other_nested_thing.another[1].aa);
60+
// assert_eq(nested_thing.another[1].bb[0], other_nested_thing.another[1].bb[0]);
61+
// assert_eq(nested_thing.another[1].bb[1], other_nested_thing.another[1].bb[1]);
62+
// we can write:
63+
assert_eq(nested_thing, other_nested_thing);
64+
}

examples/log.no

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
struct Thing {
3+
xx: Field,
4+
yy: Field
5+
}
6+
7+
fn main(pub public_input: Field) -> Field {
8+
9+
log(1234);
10+
log(true);
11+
12+
let arr = [1,2,3];
13+
log(arr);
14+
15+
let thing = Thing { xx : public_input , yy: public_input + 1};
16+
17+
log(thing);
18+
19+
let tup = (1 , true , thing);
20+
log("formatted string with a number {} boolean {} arr {} tuple {} struct {}" , 1234 , true, arr, tup, thing);
21+
22+
return public_input + 1;
23+
}

examples/tuple.no

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
struct Thing {
2+
xx: Field,
3+
tuple_field: (Field,Bool)
4+
}
5+
6+
// return tuples from functions
7+
fn Thing.new(xx: Field , tup: (Field,Bool)) -> (Thing , (Field,Bool)) {
8+
return (
9+
Thing {
10+
xx: xx,
11+
tuple_field:tup
12+
},
13+
tup
14+
);
15+
}
16+
17+
fn generic_array_tuple_test(var : ([[Field;NN];LEN],Bool)) -> (Field , [Field;NN]) {
18+
let zero = 0;
19+
let result = if var[1] {var[0][LEN - 1][NN - 1]} else { var[0][LEN - 2][NN - 2] };
20+
return (result , var[0][LEN - 1]);
21+
}
22+
23+
// xx should be 0
24+
fn main(pub xx: [Field; 2]) -> Field {
25+
// creation of new tuple with different types
26+
let tup = (1, true);
27+
28+
// create nested tuples
29+
let nested_tup = ((false, [1,2,3]), 1);
30+
log(nested_tup); // (1, (true , [1,2,3]))
31+
32+
let incr = nested_tup[1]; // 1
33+
34+
// tuples can be input to function
35+
let mut thing = Thing.new(xx[1] , (xx[0] , xx[0] == 0));
36+
37+
// you can access a tuple type just like you access a array
38+
thing[0].tuple_field[0] += incr;
39+
log(thing[0].tuple_field[0]);
40+
let new_allocation = [xx,xx];
41+
let ret = generic_array_tuple_test((new_allocation, true));
42+
43+
assert_eq(thing[0].tuple_field[0] , 1);
44+
log(ret[1]); // logs xx i.e [0,123]
45+
46+
return ret[0];
47+
}

src/backends/kimchi/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
backends::kimchi::asm::parse_coeffs,
2323
circuit_writer::{
2424
writer::{AnnotatedCell, Cell, PendingGate},
25-
DebugInfo, Gate, GateKind, Wiring,
25+
DebugInfo, Gate, GateKind, VarInfo, Wiring,
2626
},
2727
compiler::Sources,
2828
constants::Span,
@@ -128,6 +128,9 @@ pub struct KimchiVesta {
128128
/// Indexes used by the private inputs
129129
/// (this is useful to check that they appear in the circuit)
130130
pub(crate) private_input_cell_vars: Vec<KimchiCellVar>,
131+
132+
/// Log information
133+
pub(crate) log_info: Vec<(Span, VarInfo<VestaField, KimchiCellVar>)>,
131134
}
132135

133136
impl Witness {
@@ -174,6 +177,7 @@ impl KimchiVesta {
174177
finalized: false,
175178
public_input_size: 0,
176179
private_input_cell_vars: vec![],
180+
log_info: vec![],
177181
}
178182
}
179183

@@ -428,11 +432,11 @@ impl Backend for KimchiVesta {
428432
self.compute_val(env, &val.0, var.index)
429433
}
430434

431-
fn generate_witness<B: Backend>(
435+
fn generate_witness(
432436
&self,
433437
witness_env: &mut WitnessEnv<VestaField>,
434438
sources: &Sources,
435-
_typed: &Mast<B>,
439+
typed: &Mast<Self>,
436440
) -> Result<GeneratedWitness> {
437441
if !self.finalized {
438442
unreachable!("the circuit must be finalized before generating a witness");
@@ -481,6 +485,7 @@ impl Backend for KimchiVesta {
481485
}
482486
public_outputs.push(val);
483487
}
488+
self.print_log(witness_env, &self.log_info, sources, typed)?;
484489

485490
// sanity check the witness
486491
for (row, (gate, witness_row, debug_info)) in
@@ -809,9 +814,8 @@ impl Backend for KimchiVesta {
809814
fn log_var(
810815
&mut self,
811816
var: &crate::circuit_writer::VarInfo<Self::Field, Self::Var>,
812-
msg: String,
813817
span: Span,
814818
) {
815-
println!("todo: implement log_var for kimchi backend");
819+
self.log_info.push((span, var.clone()));
816820
}
817821
}

0 commit comments

Comments
 (0)