Skip to content

Conversation

JulianGCalderon
Copy link
Contributor

@JulianGCalderon JulianGCalderon commented Sep 2, 2025

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:

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

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.
    • CHANGELOG has been updated.

Copy link

github-actions bot commented Sep 2, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.150 ± 0.028 2.129 2.226 1.00
head big_factorial 2.153 ± 0.027 2.134 2.229 1.00 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.073 ± 0.018 2.057 2.122 1.00
head big_fibonacci 2.082 ± 0.008 2.061 2.090 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.692 ± 0.027 7.636 7.723 1.00
head blake2s_integration_benchmark 7.875 ± 0.063 7.764 7.965 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.219 ± 0.012 2.201 2.237 1.00
head compare_arrays_200000 2.229 ± 0.021 2.193 2.273 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.434 ± 0.013 1.419 1.460 1.00
head dict_integration_benchmark 1.445 ± 0.007 1.431 1.454 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.233 ± 0.014 1.220 1.270 1.00
head field_arithmetic_get_square_benchmark 1.253 ± 0.009 1.241 1.269 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.820 ± 0.038 7.770 7.896 1.00
head integration_builtins 7.951 ± 0.075 7.869 8.068 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 8.035 ± 0.127 7.930 8.246 1.00
head keccak_integration_benchmark 8.146 ± 0.117 8.035 8.375 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.186 ± 0.014 2.169 2.219 1.00 ± 0.01
head linear_search 2.180 ± 0.015 2.161 2.201 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.522 ± 0.014 1.501 1.553 1.00
head math_cmp_and_pow_integration_benchmark 1.541 ± 0.028 1.523 1.620 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.468 ± 0.006 1.461 1.479 1.00
head math_integration_benchmark 1.478 ± 0.004 1.473 1.483 1.01 ± 0.00
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.228 ± 0.004 1.222 1.234 1.00 ± 0.01
head memory_integration_benchmark 1.223 ± 0.011 1.211 1.252 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.581 ± 0.004 1.573 1.587 1.00
head operations_with_data_structures_benchmarks 1.584 ± 0.008 1.566 1.591 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 532.4 ± 3.3 528.4 538.4 1.00
head pedersen 534.4 ± 2.4 531.4 538.8 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 636.8 ± 4.9 630.9 649.1 1.01 ± 0.01
head poseidon_integration_benchmark 630.2 ± 4.5 623.2 637.6 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.839 ± 0.005 1.832 1.847 1.00
head secp_integration_benchmark 1.844 ± 0.009 1.832 1.862 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 633.4 ± 3.0 629.1 640.8 1.00
head set_integration_benchmark 654.6 ± 9.0 642.6 671.0 1.03 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.266 ± 0.020 4.242 4.304 1.00
head uint256_integration_benchmark 4.328 ± 0.031 4.287 4.371 1.01 ± 0.01

Copy link

codecov bot commented Sep 2, 2025

Codecov Report

❌ Patch coverage is 99.40828% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.68%. Comparing base (3af7999) to head (93be705).

Files with missing lines Patch % Lines
...int_processor/builtin_hint_processor_definition.rs 98.42% 2 Missing ⚠️
...int_processor/builtin_hint_processor/hint_utils.rs 97.80% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gabrielbosio gabrielbosio added this to the 2.5.0 milestone Sep 9, 2025
@gabrielbosio gabrielbosio moved this to In Progress in Starknet Sep 9, 2025
@JulianGCalderon JulianGCalderon force-pushed the resolve-constants-by-full-path branch from 587f490 to e1f7c8a Compare September 9, 2025 20:33
Base automatically changed from store-idents-in-hints to 2.x.y September 10, 2025 21:36
Comment on lines 63 to 81
// 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(),
));
}
};
Copy link
Contributor Author

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.

Comment on lines 55 to 67
#[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
Copy link
Contributor Author

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.

@JulianGCalderon JulianGCalderon force-pushed the resolve-constants-by-full-path branch from 7a1e6ee to 04524d0 Compare September 11, 2025 19:13
@gabrielbosio gabrielbosio removed this from the 2.5.0 milestone Sep 12, 2025
@JulianGCalderon JulianGCalderon moved this from In Progress to In Review in Starknet Sep 12, 2025
@gabrielbosio gabrielbosio moved this from In Review to In Progress in Starknet Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants