Skip to content

Commit 15bf794

Browse files
fmolettaOppen
andauthored
Add recursive_with_poseidon layout (#1724)
* Use enum for LayoutName * Move LayoutName to its own module + fix tests * Fix clap enum parsing * Fix tests * Fix test & doc * Manually implement ValueEnum * fmt * Simplify code * Move arbitrary impl to module * Fix benchmark code * Add changelog entry * Remove unnecessary impl * Use value instead of reference Co-authored-by: Mario Rugiero <[email protected]> * Fix test added by merge * Add `recursive_with_poseidon` layout * Add changelog entry * Add comment + fix log_units in diluted pool * Fix log_units & comment --------- Co-authored-by: Mario Rugiero <[email protected]>
1 parent 932986c commit 15bf794

File tree

7 files changed

+33
-2
lines changed

7 files changed

+33
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#### Upcoming Changes
44

5+
* feat: Add `recursive_with_poseidon` layout[#1724](https://github.com/lambdaclass/cairo-vm/pull/1724)
6+
57
* refactor(BREAKING): Use an enum to represent layout name[#1715](https://github.com/lambdaclass/cairo-vm/pull/1715)
68
* Add enum `LayoutName` to represent cairo layout names.
79
* `CairoRunConfig`, `Cairo1RunConfig` & `CairoRunner` field `layout` type changed from `String` to `LayoutName`.

vm/src/tests/compare_factorial_outputs_all_layouts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ passed_tests=0
55
failed_tests=0
66
exit_code=0
77

8-
for layout in "plain" "small" "dex" "recursive" "starknet" "starknet_with_keccak" "recursive_large_output" "all_solidity" "starknet_with_keccak"; do
8+
for layout in "plain" "small" "dex" "recursive" "starknet" "starknet_with_keccak" "recursive_large_output" "recursive_with_poseidon" "all_solidity" "starknet_with_keccak"; do
99
# Run cairo_vm
1010
echo "Running cairo-vm with layout $layout"
1111
cargo run -p cairo-vm-cli --release -- --layout $layout --proof_mode $factorial_compiled --trace_file factorial_rs.trace --memory_file factorial_rs.memory --air_public_input factorial_rs.air_public_input --air_private_input factorial_rs.air_private_input

vm/src/types/instance_definitions/builtins_instance_def.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ impl BuiltinsInstanceDef {
138138
}
139139
}
140140

141+
pub(crate) fn recursive_with_poseidon() -> BuiltinsInstanceDef {
142+
BuiltinsInstanceDef {
143+
output: true,
144+
pedersen: Some(PedersenInstanceDef::new(Some(256))),
145+
range_check: Some(RangeCheckInstanceDef::new(Some(16))),
146+
ecdsa: None,
147+
bitwise: Some(BitwiseInstanceDef::new(Some(16))),
148+
ec_op: None,
149+
keccak: None,
150+
poseidon: Some(PoseidonInstanceDef::new(Some(64))),
151+
range_check96: None,
152+
add_mod: None,
153+
mul_mod: None,
154+
}
155+
}
156+
141157
pub(crate) fn all_cairo() -> BuiltinsInstanceDef {
142158
BuiltinsInstanceDef {
143159
output: true,

vm/src/types/instance_definitions/diluted_pool_instance_def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use serde::Serialize;
22

33
#[derive(Serialize, Debug, PartialEq)]
44
pub(crate) struct DilutedPoolInstanceDef {
5-
pub(crate) units_per_step: u32,
5+
pub(crate) units_per_step: u32, // 2 ^ log_units_per_step (for cairo_lang comparison)
66
pub(crate) spacing: u32,
77
pub(crate) n_bits: u32,
88
}

vm/src/types/layout.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ impl CairoLayout {
8787
diluted_pool_instance_def: Some(DilutedPoolInstanceDef::default()),
8888
}
8989
}
90+
pub(crate) fn recursive_with_poseidon() -> CairoLayout {
91+
CairoLayout {
92+
name: LayoutName::recursive_with_poseidon,
93+
rc_units: 4,
94+
builtins: BuiltinsInstanceDef::recursive_with_poseidon(),
95+
public_memory_fraction: 8,
96+
diluted_pool_instance_def: Some(DilutedPoolInstanceDef::new(8, 4, 16)),
97+
}
98+
}
9099

91100
pub(crate) fn all_cairo_instance() -> CairoLayout {
92101
CairoLayout {

vm/src/types/layout_name.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub enum LayoutName {
1717
starknet,
1818
starknet_with_keccak,
1919
recursive_large_output,
20+
recursive_with_poseidon,
2021
all_solidity,
2122
all_cairo,
2223
dynamic,
@@ -32,6 +33,7 @@ impl LayoutName {
3233
LayoutName::starknet => "starknet",
3334
LayoutName::starknet_with_keccak => "starknet_with_keccak",
3435
LayoutName::recursive_large_output => "recursive_large_output",
36+
LayoutName::recursive_with_poseidon => "recursive_with_poseidon",
3537
LayoutName::all_solidity => "all_solidity",
3638
LayoutName::all_cairo => "all_cairo",
3739
LayoutName::dynamic => "all_cairo",
@@ -56,6 +58,7 @@ impl ValueEnum for LayoutName {
5658
Self::starknet,
5759
Self::starknet_with_keccak,
5860
Self::recursive_large_output,
61+
Self::recursive_with_poseidon,
5962
Self::all_solidity,
6063
Self::all_cairo,
6164
Self::dynamic,

vm/src/vm/runners/cairo_runner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ impl CairoRunner {
183183
LayoutName::starknet => CairoLayout::starknet_instance(),
184184
LayoutName::starknet_with_keccak => CairoLayout::starknet_with_keccak_instance(),
185185
LayoutName::recursive_large_output => CairoLayout::recursive_large_output_instance(),
186+
LayoutName::recursive_with_poseidon => CairoLayout::recursive_with_poseidon(),
186187
LayoutName::all_cairo => CairoLayout::all_cairo_instance(),
187188
LayoutName::all_solidity => CairoLayout::all_solidity_instance(),
188189
LayoutName::dynamic => CairoLayout::dynamic_instance(),

0 commit comments

Comments
 (0)