Skip to content

Commit d5d6525

Browse files
authored
Adding precompile fields for RvTraceRow struct (a16z#600)
* updated instructions with new fields for RvTraceRow struct * fixed clippy errors * fixed lhu.rs test
1 parent 170ae18 commit d5d6525

File tree

17 files changed

+229
-8
lines changed

17 files changed

+229
-8
lines changed

common/src/rv_trace.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub struct RVTraceRow {
1212
pub register_state: RegisterState,
1313
pub memory_state: Option<MemoryState>,
1414
pub advice_value: Option<u64>,
15+
pub precompile_input: Option<[u32; 16]>,
16+
pub precompile_output_address: Option<u64>,
1517
}
1618

1719
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]

jolt-core/benches/commit.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,11 @@ fn benchmark_commit<PCS, F, ProofTranscript>(
7979
.into_iter()
8080
.map(|layer| MultilinearPolynomial::from(layer))
8181
.collect::<Vec<_>>();
82-
c.bench_function(
83-
&format!("{} Commit: {}% Ones", name, threshold),
84-
|b| {
85-
b.iter(|| {
86-
PCS::batch_commit(&leaves, &setup);
87-
});
88-
},
89-
);
82+
c.bench_function(&format!("{} Commit: {}% Ones", name, threshold), |b| {
83+
b.iter(|| {
84+
PCS::batch_commit(&leaves, &setup);
85+
});
86+
});
9087
}
9188

9289
fn main() {

jolt-core/src/jolt/instruction/div.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVInstruction<WORD_
7777
},
7878
memory_state: None,
7979
advice_value: Some(quotient),
80+
precompile_input: None,
81+
precompile_output_address: None,
8082
});
8183

8284
let r = ADVICEInstruction::<WORD_SIZE>(remainder).lookup_entry();
@@ -97,6 +99,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVInstruction<WORD_
9799
},
98100
memory_state: None,
99101
advice_value: Some(remainder),
102+
precompile_input: None,
103+
precompile_output_address: None,
100104
});
101105

102106
let is_valid: u64 = AssertValidSignedRemainderInstruction::<WORD_SIZE>(r, y).lookup_entry();
@@ -118,6 +122,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVInstruction<WORD_
118122
},
119123
memory_state: None,
120124
advice_value: None,
125+
precompile_input: None,
126+
precompile_output_address: None,
121127
});
122128

123129
let is_valid: u64 = AssertValidDiv0Instruction::<WORD_SIZE>(y, q).lookup_entry();
@@ -139,6 +145,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVInstruction<WORD_
139145
},
140146
memory_state: None,
141147
advice_value: None,
148+
precompile_input: None,
149+
precompile_output_address: None,
142150
});
143151

144152
let q_y = MULInstruction::<WORD_SIZE>(q, y).lookup_entry();
@@ -159,6 +167,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVInstruction<WORD_
159167
},
160168
memory_state: None,
161169
advice_value: None,
170+
precompile_input: None,
171+
precompile_output_address: None,
162172
});
163173

164174
let add_0 = ADDInstruction::<WORD_SIZE>(q_y, r).lookup_entry();
@@ -179,6 +189,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVInstruction<WORD_
179189
},
180190
memory_state: None,
181191
advice_value: None,
192+
precompile_input: None,
193+
precompile_output_address: None,
182194
});
183195

184196
let _assert_eq = BEQInstruction::<WORD_SIZE>(add_0, x).lookup_entry();
@@ -199,6 +211,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVInstruction<WORD_
199211
},
200212
memory_state: None,
201213
advice_value: None,
214+
precompile_input: None,
215+
precompile_output_address: None,
202216
});
203217

204218
virtual_trace.push(RVTraceRow {
@@ -218,6 +232,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVInstruction<WORD_
218232
},
219233
memory_state: None,
220234
advice_value: None,
235+
precompile_input: None,
236+
precompile_output_address: None,
221237
});
222238

223239
virtual_trace

jolt-core/src/jolt/instruction/divu.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVUInstruction<WORD
6060
},
6161
memory_state: None,
6262
advice_value: Some(quotient),
63+
precompile_input: None,
64+
precompile_output_address: None,
6365
});
6466

6567
let r = ADVICEInstruction::<WORD_SIZE>(remainder).lookup_entry();
@@ -80,6 +82,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVUInstruction<WORD
8082
},
8183
memory_state: None,
8284
advice_value: Some(remainder),
85+
precompile_input: None,
86+
precompile_output_address: None,
8387
});
8488

8589
let q_y = MULUInstruction::<WORD_SIZE>(q, y).lookup_entry();
@@ -100,6 +104,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVUInstruction<WORD
100104
},
101105
memory_state: None,
102106
advice_value: None,
107+
precompile_input: None,
108+
precompile_output_address: None,
103109
});
104110

105111
let is_valid = AssertValidUnsignedRemainderInstruction::<WORD_SIZE>(r, y).lookup_entry();
@@ -121,6 +127,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVUInstruction<WORD
121127
},
122128
memory_state: None,
123129
advice_value: None,
130+
precompile_input: None,
131+
precompile_output_address: None,
124132
});
125133

126134
let lte = ASSERTLTEInstruction::<WORD_SIZE>(q_y, x).lookup_entry();
@@ -142,6 +150,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVUInstruction<WORD
142150
},
143151
memory_state: None,
144152
advice_value: None,
153+
precompile_input: None,
154+
precompile_output_address: None,
145155
});
146156

147157
let is_valid = AssertValidDiv0Instruction::<WORD_SIZE>(y, q).lookup_entry();
@@ -163,6 +173,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVUInstruction<WORD
163173
},
164174
memory_state: None,
165175
advice_value: None,
176+
precompile_input: None,
177+
precompile_output_address: None,
166178
});
167179

168180
let add_0 = ADDInstruction::<WORD_SIZE>(q_y, r).lookup_entry();
@@ -183,6 +195,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVUInstruction<WORD
183195
},
184196
memory_state: None,
185197
advice_value: None,
198+
precompile_input: None,
199+
precompile_output_address: None,
186200
});
187201

188202
let _assert_eq = BEQInstruction::<WORD_SIZE>(add_0, x).lookup_entry();
@@ -203,6 +217,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVUInstruction<WORD
203217
},
204218
memory_state: None,
205219
advice_value: None,
220+
precompile_input: None,
221+
precompile_output_address: None,
206222
});
207223

208224
virtual_trace.push(RVTraceRow {
@@ -222,6 +238,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVUInstruction<WORD
222238
},
223239
memory_state: None,
224240
advice_value: None,
241+
precompile_input: None,
242+
precompile_output_address: None,
225243
});
226244

227245
virtual_trace

jolt-core/src/jolt/instruction/lb.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBInstruction<WORD_S
5353
},
5454
memory_state: None,
5555
advice_value: None,
56+
precompile_input: None,
57+
precompile_output_address: None,
5658
});
5759

5860
let word_address_bitmask = ((1u128 << WORD_SIZE) - 4) as u64;
@@ -75,6 +77,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBInstruction<WORD_S
7577
},
7678
memory_state: None,
7779
advice_value: None,
80+
precompile_input: None,
81+
precompile_output_address: None,
7882
});
7983

8084
let word = match trace_row.memory_state.unwrap() {
@@ -113,6 +117,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBInstruction<WORD_S
113117
value: word,
114118
}),
115119
advice_value: None,
120+
precompile_input: None,
121+
precompile_output_address: None,
116122
});
117123

118124
let byte_shift = XORInstruction::<WORD_SIZE>(ram_address, 0b11).lookup_entry();
@@ -133,6 +139,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBInstruction<WORD_S
133139
},
134140
memory_state: None,
135141
advice_value: None,
142+
precompile_input: None,
143+
precompile_output_address: None,
136144
});
137145

138146
let bit_shift = SLLInstruction::<WORD_SIZE>(byte_shift, 3).lookup_entry();
@@ -153,6 +161,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBInstruction<WORD_S
153161
},
154162
memory_state: None,
155163
advice_value: None,
164+
precompile_input: None,
165+
precompile_output_address: None,
156166
});
157167

158168
let left_aligned_byte = SLLInstruction::<WORD_SIZE>(word, bit_shift).lookup_entry();
@@ -173,6 +183,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBInstruction<WORD_S
173183
},
174184
memory_state: None,
175185
advice_value: None,
186+
precompile_input: None,
187+
precompile_output_address: None,
176188
});
177189

178190
let sign_extended_byte = SRAInstruction::<WORD_SIZE>(left_aligned_byte, 24).lookup_entry();
@@ -194,6 +206,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBInstruction<WORD_S
194206
},
195207
memory_state: None,
196208
advice_value: None,
209+
precompile_input: None,
210+
precompile_output_address: None,
197211
});
198212

199213
virtual_trace
@@ -216,6 +230,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBInstruction<WORD_S
216230
value: 0,
217231
}),
218232
advice_value: None,
233+
precompile_input: None,
234+
precompile_output_address: None,
219235
};
220236
Self::virtual_trace(dummy_trace_row)
221237
.into_iter()
@@ -279,6 +295,8 @@ mod test {
279295
value: word,
280296
}),
281297
advice_value: None,
298+
precompile_input: None,
299+
precompile_output_address: None,
282300
};
283301

284302
let trace = LBInstruction::<32>::virtual_trace(lb_trace_row);

jolt-core/src/jolt/instruction/lbu.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBUInstruction<WORD_
5353
},
5454
memory_state: None,
5555
advice_value: None,
56+
precompile_input: None,
57+
precompile_output_address: None,
5658
});
5759

5860
let word_address_bitmask = ((1u128 << WORD_SIZE) - 4) as u64;
@@ -75,6 +77,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBUInstruction<WORD_
7577
},
7678
memory_state: None,
7779
advice_value: None,
80+
precompile_input: None,
81+
precompile_output_address: None,
7882
});
7983

8084
let word = match trace_row.memory_state.unwrap() {
@@ -113,6 +117,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBUInstruction<WORD_
113117
value: word,
114118
}),
115119
advice_value: None,
120+
precompile_input: None,
121+
precompile_output_address: None,
116122
});
117123

118124
let byte_shift = XORInstruction::<WORD_SIZE>(ram_address, 0b11).lookup_entry();
@@ -133,6 +139,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBUInstruction<WORD_
133139
},
134140
memory_state: None,
135141
advice_value: None,
142+
precompile_input: None,
143+
precompile_output_address: None,
136144
});
137145

138146
let bit_shift = SLLInstruction::<WORD_SIZE>(byte_shift, 3).lookup_entry();
@@ -153,6 +161,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBUInstruction<WORD_
153161
},
154162
memory_state: None,
155163
advice_value: None,
164+
precompile_input: None,
165+
precompile_output_address: None,
156166
});
157167

158168
let left_aligned_byte = SLLInstruction::<WORD_SIZE>(word, bit_shift).lookup_entry();
@@ -173,6 +183,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBUInstruction<WORD_
173183
},
174184
memory_state: None,
175185
advice_value: None,
186+
precompile_input: None,
187+
precompile_output_address: None,
176188
});
177189

178190
let zero_extended_byte = SRLInstruction::<WORD_SIZE>(left_aligned_byte, 24).lookup_entry();
@@ -194,6 +206,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBUInstruction<WORD_
194206
},
195207
memory_state: None,
196208
advice_value: None,
209+
precompile_input: None,
210+
precompile_output_address: None,
197211
});
198212

199213
virtual_trace
@@ -216,6 +230,8 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for LBUInstruction<WORD_
216230
value: 0,
217231
}),
218232
advice_value: None,
233+
precompile_input: None,
234+
precompile_output_address: None,
219235
};
220236
Self::virtual_trace(dummy_trace_row)
221237
.into_iter()
@@ -279,6 +295,8 @@ mod test {
279295
value: word,
280296
}),
281297
advice_value: None,
298+
precompile_input: None,
299+
precompile_output_address: None,
282300
};
283301

284302
let trace = LBUInstruction::<32>::virtual_trace(lbu_trace_row);

0 commit comments

Comments
 (0)