-
Notifications
You must be signed in to change notification settings - Fork 290
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
feat: compute storage root #1294
base: main
Are you sure you want to change the base?
Conversation
5e9917b
to
51532b9
Compare
let base = 0x10; | ||
let bound = 0x10; | ||
let (high, _) = unsigned_div_rem(value, base); | ||
assert [output] = high; | ||
let output = output + 1; | ||
%{ | ||
memory[ids.output] = res = (int(ids.value) % PRIME) % ids.base | ||
assert res < ids.bound, f'split_int(): Limb {res} is out of range.' | ||
%} | ||
let output = output + 1; |
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 ?
let base = 0x10; | |
let bound = 0x10; | |
let (high, _) = unsigned_div_rem(value, base); | |
assert [output] = high; | |
let output = output + 1; | |
%{ | |
memory[ids.output] = res = (int(ids.value) % PRIME) % ids.base | |
assert res < ids.bound, f'split_int(): Limb {res} is out of range.' | |
%} | |
let output = output + 1; | |
let (high, low) = unsigned_div_rem(value, 0x10); | |
assert [output] = high; | |
assert [output + 1] = low; | |
let output = output + 2; |
let nibbles_len = [fp]; | ||
let output_start = cast([fp + 1], felt*); | ||
let count = output - output_start; | ||
let is_done = Helpers.is_zero(nibbles_len - count); | ||
jmp done if is_done != 0; | ||
|
||
let next_byte_index = count / 2; | ||
let bytes = cast([fp - 3], felt*); | ||
tempvar value = bytes[next_byte_index]; | ||
let range_check_ptr = range_check_ptr + 1; | ||
[ap] = range_check_ptr, ap++; | ||
[ap] = output, ap++; | ||
[ap] = value, ap++; | ||
|
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.
this can be simplified to avoid the is_zero
calls especially
let prefix = ((2 * is_leaf) + 1) * 16 + self.nibbles[0]; | ||
assert encoded[0] = prefix; | ||
tempvar to_pack = new Nibbles(self.nibbles_len - 1, self.nibbles + 1); | ||
let bytes_len = NibblesImpl.pack_nibbles(to_pack, encoded + 1); |
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.
let bytes_len = NibblesImpl.pack_nibbles(to_pack, encoded + 1); | |
let bytes_len = pack_nibbles(to_pack, encoded + 1); |
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.
add docstrings
// Case even number of nibbles | ||
let prefix = 2 * is_leaf * 16; | ||
assert encoded[0] = prefix; | ||
let bytes_len = NibblesImpl.pack_nibbles(self, encoded + 1); |
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.
let bytes_len = NibblesImpl.pack_nibbles(self, encoded + 1); | |
let bytes_len = pack_nibbles(self, encoded + 1); |
src/utils/mpt/nibbles.cairo
Outdated
return bytes_len; | ||
} | ||
|
||
func encode_path{range_check_ptr}(self: Nibbles*, is_leaf: felt) -> ( |
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.
so this is mainly packing the nibbles with a prefix. It gives me the impression that we go from bytes* to nibbles* to bytes* again, not sure to understand
let (local output: felt*) = alloc(); | ||
|
||
if (nibbles_len == 0) { | ||
tempvar res = new Nibbles(nibbles_len, output); |
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.
in done label: new Nibbles(nibbles_len, nibbles);
Maybe standardize the naming of what Nibbles
takes by renaming output
to nibbles
or changing the naming in done label?
from utils.mpt.nibbles import Nibbles, NibblesImpl | ||
|
||
func test__from_bytes{range_check_ptr}() -> Nibbles* { | ||
// Given |
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.
to remove if not following given / when / then
c40206a
to
4eda303
Compare
Time spent on this PR: tbd
Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
Resolves #1243
What is the new behavior?
This change is