Skip to content

Commit 28f4004

Browse files
Add_perp_and_dex_w_bitwise_layouts (#2067)
1 parent ba51705 commit 28f4004

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

vm/src/types/instance_definitions/builtins_instance_def.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,38 @@ impl BuiltinsInstanceDef {
282282
mul_mod,
283283
}
284284
}
285+
286+
pub(crate) fn perpetual() -> BuiltinsInstanceDef {
287+
BuiltinsInstanceDef {
288+
output: true,
289+
pedersen: Some(PedersenInstanceDef::new(Some(32))),
290+
range_check: Some(RangeCheckInstanceDef::new(Some(16))),
291+
ecdsa: Some(EcdsaInstanceDef::new(Some(2048))),
292+
bitwise: None,
293+
ec_op: None,
294+
keccak: None,
295+
poseidon: None,
296+
range_check96: None,
297+
add_mod: None,
298+
mul_mod: None,
299+
}
300+
}
301+
302+
pub(crate) fn dex_with_bitwise() -> BuiltinsInstanceDef {
303+
BuiltinsInstanceDef {
304+
output: true,
305+
pedersen: Some(PedersenInstanceDef::default()),
306+
range_check: Some(RangeCheckInstanceDef::default()),
307+
ecdsa: Some(EcdsaInstanceDef::default()),
308+
bitwise: Some(BitwiseInstanceDef::new(Some(64))),
309+
ec_op: None,
310+
keccak: None,
311+
poseidon: None,
312+
range_check96: None,
313+
add_mod: None,
314+
mul_mod: None,
315+
}
316+
}
285317
}
286318

287319
#[cfg(test)]

vm/src/types/layout.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,30 @@ impl CairoLayout {
169169
builtins: BuiltinsInstanceDef::dynamic(params),
170170
}
171171
}
172+
173+
pub(crate) fn perpetual_instance() -> CairoLayout {
174+
CairoLayout {
175+
name: LayoutName::perpetual,
176+
rc_units: 4,
177+
cpu_component_step: DEFAULT_CPU_COMPONENT_STEP,
178+
memory_units_per_step: DEFAULT_MEMORY_UNITS_PER_STEP,
179+
builtins: BuiltinsInstanceDef::perpetual(),
180+
public_memory_fraction: 4,
181+
diluted_pool_instance_def: None,
182+
}
183+
}
184+
185+
pub(crate) fn dex_with_bitwise_instance() -> CairoLayout {
186+
CairoLayout {
187+
name: LayoutName::dex_with_bitwise,
188+
rc_units: 4,
189+
cpu_component_step: DEFAULT_CPU_COMPONENT_STEP,
190+
memory_units_per_step: DEFAULT_MEMORY_UNITS_PER_STEP,
191+
builtins: BuiltinsInstanceDef::dex_with_bitwise(),
192+
public_memory_fraction: 4,
193+
diluted_pool_instance_def: Some(DilutedPoolInstanceDef::new(2, 4, 16)),
194+
}
195+
}
172196
}
173197

174198
#[cfg(feature = "test_utils")]
@@ -496,6 +520,31 @@ mod tests {
496520
);
497521
}
498522

523+
#[test]
524+
fn get_perpetual_instance() {
525+
let layout = CairoLayout::perpetual_instance();
526+
let builtins = BuiltinsInstanceDef::perpetual();
527+
assert_eq!(layout.name, LayoutName::perpetual);
528+
assert_eq!(layout.rc_units, 4);
529+
assert_eq!(layout.builtins, builtins);
530+
assert_eq!(layout.public_memory_fraction, 4);
531+
assert_eq!(layout.diluted_pool_instance_def, None);
532+
}
533+
534+
#[test]
535+
fn get_dex_with_bitwise_instance() {
536+
let layout = CairoLayout::dex_with_bitwise_instance();
537+
let builtins = BuiltinsInstanceDef::dex_with_bitwise();
538+
assert_eq!(layout.name, LayoutName::dex_with_bitwise);
539+
assert_eq!(layout.rc_units, 4);
540+
assert_eq!(layout.builtins, builtins);
541+
assert_eq!(layout.public_memory_fraction, 4);
542+
assert_eq!(
543+
layout.diluted_pool_instance_def,
544+
Some(DilutedPoolInstanceDef::new(2, 4, 16))
545+
);
546+
}
547+
499548
#[test]
500549
fn get_dynamic_instance() {
501550
// dummy cairo layout params

vm/src/types/layout_name.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub enum LayoutName {
2222
all_cairo,
2323
dynamic,
2424
all_cairo_stwo,
25+
perpetual,
26+
dex_with_bitwise,
2527
}
2628

2729
impl LayoutName {
@@ -39,6 +41,8 @@ impl LayoutName {
3941
LayoutName::all_cairo => "all_cairo",
4042
LayoutName::dynamic => "dynamic",
4143
LayoutName::all_cairo_stwo => "all_cairo_stwo",
44+
LayoutName::perpetual => "perpetual",
45+
LayoutName::dex_with_bitwise => "dex_with_bitwise",
4246
}
4347
}
4448
}
@@ -65,6 +69,8 @@ impl ValueEnum for LayoutName {
6569
Self::all_cairo,
6670
Self::dynamic,
6771
Self::all_cairo_stwo,
72+
Self::perpetual,
73+
Self::dex_with_bitwise,
6874
]
6975
}
7076

vm/src/vm/runners/cairo_runner.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ impl CairoRunner {
191191
LayoutName::all_cairo => CairoLayout::all_cairo_instance(),
192192
LayoutName::all_cairo_stwo => CairoLayout::all_cairo_stwo_instance(),
193193
LayoutName::all_solidity => CairoLayout::all_solidity_instance(),
194+
LayoutName::perpetual => CairoLayout::perpetual_instance(),
195+
LayoutName::dex_with_bitwise => CairoLayout::dex_with_bitwise_instance(),
194196
LayoutName::dynamic => {
195197
let params =
196198
dynamic_layout_params.ok_or(RunnerError::MissingDynamicLayoutParams)?;

0 commit comments

Comments
 (0)