Skip to content

Commit 79610d3

Browse files
authored
isa (#3)
Co-authored-by: Tom Wambsgans <[email protected]>
1 parent 9c1d590 commit 79610d3

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
use p3_koala_bear::KoalaBear;
2+
use std::collections::BTreeMap;
3+
4+
type Label = String;
5+
type F = KoalaBear;
6+
7+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
8+
pub struct Bytecode {
9+
pub instructions: Vec<Instruction>,
10+
pub hints: BTreeMap<usize, Vec<Hint>>, // pc -> hints
11+
pub public_input_start: usize,
12+
pub ending_pc: usize,
13+
}
14+
15+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
16+
pub enum MemOrConstant {
17+
Constant(F),
18+
MemoryAfterFp { shift: usize }, // m[fp + shift]
19+
}
20+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
21+
pub enum MemOrFpOrConstant {
22+
MemoryAfterFp { shift: usize }, // m[fp + shift]
23+
Fp,
24+
Constant(F),
25+
}
26+
27+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
28+
pub enum MemOrFp {
29+
MemoryAfterFp { shift: usize }, // m[fp + shift]
30+
Fp,
31+
}
32+
33+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
34+
pub enum Operation {
35+
Add,
36+
Mul,
37+
}
38+
39+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
40+
pub enum Instruction {
41+
Computation {
42+
operation: Operation,
43+
arg_a: MemOrConstant,
44+
arg_b: MemOrFp,
45+
res: MemOrConstant,
46+
},
47+
Deref {
48+
shift_0: usize,
49+
shift_1: usize,
50+
res: MemOrFpOrConstant,
51+
}, // res = m[m[fp + shift_0] + shift_1]
52+
JumpIfNotZero {
53+
condition: MemOrConstant,
54+
dest: MemOrConstant,
55+
updated_fp: MemOrFp,
56+
},
57+
Poseidon2_16 {
58+
shift: usize,
59+
}, /*
60+
Read 4 vectorized pointers from stack:
61+
Poseidon2(m[8 * m[fp + shift]] .. 8 * (1 + m[fp + shift])] | m[8 * m[fp + shift + 1]] .. 8 * (1 + m[fp + shift + 1])])
62+
= m[8 * m[fp + shift + 2]] .. 8 * (1 + m[fp + shift + 2])] | m[8 * m[fp + shift + 3]] .. 8 * (1 + m[fp + shift + 3])]
63+
*/
64+
Poseidon2_24 {
65+
shift: usize,
66+
}, // same as above, but with 24 field elements
67+
ExtensionMul {
68+
args: [usize; 3], // offset after fp
69+
},
70+
}
71+
72+
/// Hints does not appear in the verified bytecode, but are useful during execution
73+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
74+
pub enum Hint {
75+
RequestMemory {
76+
offset: usize, // the pointer to the allocated memory range will be stored at m[fp + offset]
77+
size: MemOrConstant,
78+
/// if vectorized == true, the start of the allocated memory will be aligned to 8 field elements
79+
/// m[8X...] and we set m[fp + offset] = X
80+
vectorized: bool,
81+
},
82+
DecomposeBits {
83+
res_offset: usize, // m[fp + res_offset..fp + res_offset + 31] will contain the decomposed bits
84+
to_decompose: MemOrConstant,
85+
},
86+
// Debug purpose
87+
Print {
88+
line_info: String,
89+
content: Vec<MemOrConstant>,
90+
},
91+
}

0 commit comments

Comments
 (0)