-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Public inputs refactor #676
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #676 +/- ##
==========================================
- Coverage 96.23% 96.16% -0.07%
==========================================
Files 133 133
Lines 29801 29678 -123
==========================================
- Hits 28678 28541 -137
- Misses 1123 1137 +14 ☔ View full report in Codecov by Sentry. |
Initial implementation, the struct
|
Should we implement |
@juan518munoz I think it is not necessary right now, is there any benefit on doing so? |
Not really, it would only save us from doing two |
1d6a713
to
4284f8a
Compare
provers/cairo/src/runner/run.rs
Outdated
let codelen = runner.get_program().data_len(); | ||
|
||
let public_memory = (1..=codelen as u64) | ||
.map(|i| (Felt252::from(i), *cairo_mem.get(&i).unwrap())) | ||
.collect::<HashMap<Felt252, Felt252>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have the public inputs directly from the cairo vm, there is no need to ask for the codelen, and the public memory should be obtained from the public inputs, this was just a hacky solution until we had access to them.
The approach should be similar to the one you did with the memory segments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a result of this, the PublicInputs
field codelen
could be removed, since it can be deduced with the length of the Program
memory segment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only function that makes use of the codelen
field is get_memory_holes
which itself is only called inside build_main_trace
. How should we handle this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach should be similar to the one you did with the memory segments
I'm having trouble doing an iteration over the vm public memory, doing something like this:
let mut public_memory: HashMap<Felt252, Felt252> = HashMap::new();
vm_public_inputs.public_memory.iter().for_each(|e| {
let v = e.value.clone().unwrap().to_str_radix(16);
public_memory.insert(
Felt252::from((e.address + e.page) as u64),
Felt252::from_hex_unchecked(&v),
);
});
Breaks some of our tests
Maybe I'm missing something?
provers/cairo/src/air.rs
Outdated
let mut pub_addrs = public_input.public_memory.keys(); | ||
|
||
// Iterate over addresses | ||
for (i, a) in a_aux.iter_mut().enumerate() { | ||
// When address `0` is found, it means it corresponds to a dummy access. | ||
if a == &Felt252::zero() { | ||
// While there are public memory addresses left, overwrite the dummy | ||
// (addr, value) accesses with the real public memory pairs. | ||
if let Some(pub_addr) = pub_addrs_iter.next() { | ||
if let Some(pub_addr) = pub_addrs.next() { | ||
*a = *pub_addr; | ||
v_aux[i] = *public_input.public_memory.get(pub_addr).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just public_input.public_memory.iter()
and then get the value and key together? It saves an unwrap
.
Related question, is this logic dependent on the order of elements? Because public_memory
seems to be a HashMap
. Maybe a BTreeMap
is more appropriate here?
Refactor Public Inputs
Description
Modify the
MemorySegmentMap
field ofPublicInputs
to be a HashMap with values of typeSegment
instead ofRange
.This pr also updates the cairo-vm crate to it's latest
main
revision.Type of change