-
Notifications
You must be signed in to change notification settings - Fork 61
blockifier: unify from felts and from bytecode to counts #8716
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
base: main-v0.14.1
Are you sure you want to change the base?
blockifier: unify from felts and from bytecode to counts #8716
Conversation
Artifacts upload workflows: |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
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.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion
crates/blockifier/src/execution/contract_class.rs
line 99 at r1 (raw file):
impl From<&[BigUintAsHex]> for FeltSizeCount { fn from(bytecode: &[BigUintAsHex]) -> Self { count_felts_by_size(bytecode, |x| Felt::from(&x.value) < SMALL_THRESHOLD)
Alternative
Suggestion (i):
x.value.bits() <= SMALL_THRESHOLD_BITS
Code snippet (ii):
const SMALL_THRESHOLD_BITS: u32 = 63;
#[test]
fn small_threshold_consistency() {
let reconstructed = Felt::from(1u128 << SMALL_THRESHOLD_BITS);
assert_eq!(reconstructed, SMALL_THRESHOLD);
}
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.
@AvivYossef-starkware reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @noaov1)
crates/blockifier/src/execution/contract_class.rs
line 108 at r1 (raw file):
count_felts_by_size(bytecode, |felt| *felt < SMALL_THRESHOLD) } }
You need to impl from only once,
from <T> for FeltSizeCount where T impl is small
you can fo it,
but I prefer new function that get T as an input
Code quote:
/// Counts elements into “small” vs “large” buckets using the provided predicate.
#[inline]
fn count_felts_by_size<T>(slice: &[T], mut is_small: impl FnMut(&T) -> bool) -> FeltSizeCount {
let mut small = 0;
let mut large = 0;
for it in slice {
if is_small(it) { small += 1 } else { large += 1 }
}
FeltSizeCount { small, large }
}
/// Classifies bytecode words by felt size using `SMALL_THRESHOLD = 2^63`.
impl From<&[BigUintAsHex]> for FeltSizeCount {
fn from(bytecode: &[BigUintAsHex]) -> Self {
count_felts_by_size(bytecode, |x| Felt::from(&x.value) < SMALL_THRESHOLD)
}
}
/// Classifies felts by size using `SMALL_THRESHOLD = 2^63`.
impl From<&[Felt]> for FeltSizeCount {
fn from(bytecode: &[Felt]) -> Self {
count_felts_by_size(bytecode, |felt| *felt < SMALL_THRESHOLD)
}
}
374bdf5
to
ac9a589
Compare
2866cb0
to
604aef8
Compare
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.
Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @AvivYossef-starkware and @noaov1)
crates/blockifier/src/execution/contract_class.rs
line 108 at r1 (raw file):
Previously, AvivYossef-starkware wrote…
You need to impl from only once,
from <T> for FeltSizeCount where T impl is small
you can fo it,
but I prefer new function that get T as an input
WDYT?
ac9a589
to
9551bd0
Compare
604aef8
to
a567966
Compare
No description provided.