-
Notifications
You must be signed in to change notification settings - Fork 194
Resolve constants by full path #2192
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: 2.x.y
Are you sure you want to change the base?
Conversation
Benchmark Results for unmodified programs 🚀
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 2.x.y #2192 +/- ##
==========================================
+ Coverage 96.66% 96.68% +0.01%
==========================================
Files 103 103
Lines 43646 43986 +340
==========================================
+ Hits 42191 42528 +337
- Misses 1455 1458 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
587f490
to
e1f7c8a
Compare
// The code gets the value from `ids.SHA256_INPUT_CHUNK_SIZE_FELTS` in both | ||
// constant and arbitrary input length cases. | ||
let input_chunk_size_felts = get_constant_from_scoped_name( | ||
"SHA256_INPUT_CHUNK_SIZE_FELTS", | ||
identifiers, | ||
accessible_scopes, | ||
)?; | ||
|
||
// The input chunk size must be less than 100. | ||
let input_chunk_size_felts = match input_chunk_size_felts.to_usize() { | ||
Some(size) if size < 100 => size, | ||
_ => { | ||
return Err(HintError::AssertionFailed( | ||
"assert 0 <= _sha256_input_chunk_size_felts < 100" | ||
.to_string() | ||
.into_boxed_str(), | ||
)); | ||
} | ||
}; |
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 addition to updating the function to use accessible scopes, I also slightly changed the implementation to make it easier to understand.
#[cfg(not(feature = "mod_builtin"))] | ||
const LARGE_BATCH_SIZE_PATH: &str = | ||
"starkware.cairo.common.modulo.run_mod_p_circuit_with_large_batch_size.BATCH_SIZE"; | ||
#[cfg(not(feature = "mod_builtin"))] | ||
let batch_size = constants | ||
.get(LARGE_BATCH_SIZE_PATH) | ||
.ok_or_else(|| HintError::MissingConstant(Box::new(LARGE_BATCH_SIZE_PATH)))?; | ||
#[cfg(not(feature = "mod_builtin"))] | ||
let batch_size = get_constant_from_scoped_name("BATCH_SIZE", identifiers, accessible_scopes)?; | ||
let batch_size = batch_size | ||
.to_usize() | ||
.ok_or_else(|| MathError::Felt252ToUsizeConversion(Box::new(*batch_size)))?; | ||
#[cfg(feature = "mod_builtin")] | ||
let batch_size = 8; // Hardcoded here as we are not importing from the common lib yet |
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.
I believe this was outdated, as the constants are part of the common library now. There is no need to have the value hardcoded anymore.
Co-authored-by: Mathieu <[email protected]>
The python implementation takes the references, while our implementation doesn't allow taking references when it expects a constants. For this reason, the example doesn't work as is in our current implementation. To fix this, I changed the example to not receive the values as parameters.
7a1e6ee
to
04524d0
Compare
Depends on #2191
Resolves constants by full path, instead of only constant name. Currently, we are matching the first constant that shares the name, ignoring the full path to the constant. This has undefined behaviour if multiple constants have the same name.
To properly implement the lookup of constants, we need access two new elements:
This implied changing the signature of the hint processor.
The other big change in this PR is in the implementation of
get_constant_from_var_name
. This function finds the correct identifier by looking at the full path, and the accessible scopes.I've added a test that fails with the current implementation. This PR solves it.
Checklist