openvm_circuit/system/program/
bus.rs
1use std::iter;
2
3use openvm_stark_backend::{
4 interaction::{BusIndex, InteractionBuilder, LookupBus},
5 p3_field::FieldAlgebra,
6};
7
8#[derive(Debug, Clone, Copy)]
9pub struct ProgramBus {
10 pub inner: LookupBus,
11}
12
13impl ProgramBus {
14 pub const fn new(index: BusIndex) -> Self {
15 Self {
16 inner: LookupBus::new(index),
17 }
18 }
19
20 #[inline(always)]
21 pub fn index(&self) -> BusIndex {
22 self.inner.index
23 }
24}
25
26impl ProgramBus {
27 pub fn lookup_instruction<AB: InteractionBuilder, E: Into<AB::Expr>>(
29 &self,
30 builder: &mut AB,
31 pc: impl Into<AB::Expr>,
32 opcode: impl Into<AB::Expr>,
33 operands: impl IntoIterator<Item = E>,
34 enabled: impl Into<AB::Expr>,
35 ) {
36 self.inner.lookup_key(
37 builder,
38 [pc.into(), opcode.into()].into_iter().chain(
39 operands
40 .into_iter()
41 .map(Into::into)
42 .chain(iter::repeat(AB::Expr::ZERO))
43 .take(7),
44 ),
45 enabled,
46 );
47 }
48}