-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
318 additions
and
20 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
stwo_cairo_prover/crates/prover/src/input/builtins_segments.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
use std::collections::HashMap; | ||
|
||
use cairo_vm::air_public_input::MemorySegmentAddresses; | ||
|
||
// TODO(STAV): Understand if the adapter should pass builtins that won't be supported by stwo. | ||
/// This struct holds the builtins used in a Cairo program. | ||
/// Most of them are not implemented yet by Stwo. | ||
#[derive(Debug)] | ||
pub struct BuiltinsSegments { | ||
pub range_check_bits_128_builtin: MemorySegmentAddresses, | ||
pub range_check_bits_96_builtin: MemorySegmentAddresses, | ||
pub bitwise_builtin: MemorySegmentAddresses, | ||
pub add_mod_builtin: MemorySegmentAddresses, | ||
pub ec_op_builtin: MemorySegmentAddresses, | ||
pub ecdsa_builtin: MemorySegmentAddresses, | ||
pub keccak_builtin: MemorySegmentAddresses, | ||
pub mul_mod_builtin: MemorySegmentAddresses, | ||
pub pedersen_builtin: MemorySegmentAddresses, | ||
pub poseidon_builtin: MemorySegmentAddresses, | ||
} | ||
|
||
impl Default for BuiltinsSegments { | ||
fn default() -> Self { | ||
Self { | ||
range_check_bits_128_builtin: MemorySegmentAddresses { | ||
begin_addr: 0, | ||
stop_ptr: 0, | ||
}, | ||
range_check_bits_96_builtin: MemorySegmentAddresses { | ||
begin_addr: 0, | ||
stop_ptr: 0, | ||
}, | ||
bitwise_builtin: MemorySegmentAddresses { | ||
begin_addr: 0, | ||
stop_ptr: 0, | ||
}, | ||
add_mod_builtin: MemorySegmentAddresses { | ||
begin_addr: 0, | ||
stop_ptr: 0, | ||
}, | ||
ec_op_builtin: MemorySegmentAddresses { | ||
begin_addr: 0, | ||
stop_ptr: 0, | ||
}, | ||
ecdsa_builtin: MemorySegmentAddresses { | ||
begin_addr: 0, | ||
stop_ptr: 0, | ||
}, | ||
keccak_builtin: MemorySegmentAddresses { | ||
begin_addr: 0, | ||
stop_ptr: 0, | ||
}, | ||
mul_mod_builtin: MemorySegmentAddresses { | ||
begin_addr: 0, | ||
stop_ptr: 0, | ||
}, | ||
pedersen_builtin: MemorySegmentAddresses { | ||
begin_addr: 0, | ||
stop_ptr: 0, | ||
}, | ||
poseidon_builtin: MemorySegmentAddresses { | ||
begin_addr: 0, | ||
stop_ptr: 0, | ||
}, | ||
} | ||
} | ||
} | ||
impl BuiltinsSegments { | ||
/// Create a new `BuiltinsSegments` struct from a map of memory MemorySegmentAddressess. | ||
pub fn from_memory_segments( | ||
memory_segments: &HashMap<&str, cairo_vm::air_public_input::MemorySegmentAddresses>, | ||
) -> Self { | ||
let mut res = Self::default(); | ||
for (name, value) in memory_segments.iter() { | ||
match *name { | ||
"range_check" => { | ||
res.range_check_bits_128_builtin = MemorySegmentAddresses { | ||
begin_addr: value.begin_addr, | ||
stop_ptr: value.stop_ptr, | ||
} | ||
} | ||
"range_check96" => { | ||
res.range_check_bits_96_builtin = MemorySegmentAddresses { | ||
begin_addr: value.begin_addr, | ||
stop_ptr: value.stop_ptr, | ||
} | ||
} | ||
"bitwise" => { | ||
res.bitwise_builtin = MemorySegmentAddresses { | ||
begin_addr: value.begin_addr, | ||
stop_ptr: value.stop_ptr, | ||
} | ||
} | ||
"add_mod" => { | ||
res.add_mod_builtin = MemorySegmentAddresses { | ||
begin_addr: value.begin_addr, | ||
stop_ptr: value.stop_ptr, | ||
} | ||
} | ||
"ec_op" => { | ||
res.ec_op_builtin = MemorySegmentAddresses { | ||
begin_addr: value.begin_addr, | ||
stop_ptr: value.stop_ptr, | ||
} | ||
} | ||
"ecdsa" => { | ||
res.ecdsa_builtin = MemorySegmentAddresses { | ||
begin_addr: value.begin_addr, | ||
stop_ptr: value.stop_ptr, | ||
} | ||
} | ||
"keccak" => { | ||
res.keccak_builtin = MemorySegmentAddresses { | ||
begin_addr: value.begin_addr, | ||
stop_ptr: value.stop_ptr, | ||
} | ||
} | ||
"mul_mod" => { | ||
res.mul_mod_builtin = MemorySegmentAddresses { | ||
begin_addr: value.begin_addr, | ||
stop_ptr: value.stop_ptr, | ||
} | ||
} | ||
"pedersen" => { | ||
res.pedersen_builtin = MemorySegmentAddresses { | ||
begin_addr: value.begin_addr, | ||
stop_ptr: value.stop_ptr, | ||
} | ||
} | ||
"poseidon" => { | ||
res.poseidon_builtin = MemorySegmentAddresses { | ||
begin_addr: value.begin_addr, | ||
stop_ptr: value.stop_ptr, | ||
} | ||
} | ||
// Output, executaion and program segments are not builtins. | ||
"output" => {} | ||
"execution" => {} | ||
"program" => {} | ||
_ => panic!("Unknown memory segment: {name}"), | ||
} | ||
} | ||
res | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.