Skip to content

Add sierra for predeployed contracts#4275

Open
franciszekjob wants to merge 202 commits into
masterfrom
3433-add-predeployed-contracts-sierra
Open

Add sierra for predeployed contracts#4275
franciszekjob wants to merge 202 commits into
masterfrom
3433-add-predeployed-contracts-sierra

Conversation

@franciszekjob
Copy link
Copy Markdown
Contributor

@franciszekjob franciszekjob commented Apr 13, 2026

Closes #3433

Introduced changes

This PR adds sierra of predeployed contracts, allowing to properly display these contracts, when used with debugging features (backtrace and traces).

Backtrace

Before
Shown as forked contract

[FAIL] backtrace_panic::Test::test_predeployed_contract_panics

Failure data:
    0x753235365f737562204f766572666c6f77 ('u256_sub Overflow')

error occurred in forked contract with class hash: 0x4ad3c1dc8413453db314497945b6903e1c766495a1e60492d44da9c2a986e4b

After
Properly displayed

[FAIL] backtrace_panic::Test::test_predeployed_contract_panics

Failure data:
    (0x45524332303a20696e73756666696369656e742062616c616e6365 ('ERC20: insufficient balance'), 0x454e545259504f494e545f4641494c4544 ('ENTRYPOINT_FAILED'))

error occurred in contract 'STRK'
stack backtrace:
   0: core::panic_with_const_felt252
       at /Users/franciszekjob/Library/Caches/com.swmansion.scarb/registry/std/v2.15.0/core/src/lib.cairo:364:5
   1: core::panic_with_const_felt252
       at /Users/franciszekjob/Library/Caches/com.swmansion.scarb/registry/std/v2.15.0/core/src/lib.cairo:364:5
   2: (inlined) core::integer::U128PartialOrd::lt
       at /Users/franciszekjob/Library/Caches/com.swmansion.scarb/registry/std/v2.15.0/core/src/integer.cairo:266:9
   3: (inlined) core::integer::U256PartialOrd::lt
       at /Users/franciszekjob/Library/Caches/com.swmansion.scarb/registry/std/v2.15.0/core/src/integer.cairo:1085:12
   4: openzeppelin_token::erc20::erc20::ERC20Component::InternalImpl::update
       at /Users/franciszekjob/Library/Caches/com.swmansion.scarb/registry/std/v2.15.0/core/src/traits.cairo:663:10
   5: (inlined) openzeppelin_token::erc20::erc20::ERC20Component::InternalImpl::_transfer
       at /Users/franciszekjob/Library/Caches/com.swmansion.scarb/registry/src/scarbs.xyz-9djtpev4jug5q/openzeppelin_token-3.0.0/src/erc20/erc20.cairo:522:13
   6: (inlined) openzeppelin_token::erc20::erc20::ERC20Component::ERC20::transfer
       at /Users/franciszekjob/Library/Caches/com.swmansion.scarb/registry/src/scarbs.xyz-9djtpev4jug5q/openzeppelin_token-3.0.0/src/erc20/erc20.cairo:154:13
   7: (inlined) openzeppelin_token::erc20::erc20::ERC20Component::ERC20Impl::transfer
       at /Users/franciszekjob/Library/Caches/com.swmansion.scarb/registry/src/scarbs.xyz-9djtpev4jug5q/openzeppelin_token-3.0.0/src/erc20/erc20.cairo:118:5
   8: openzeppelin_token::erc20::erc20::ERC20Component::__wrapper__ERC20Impl__transfer
       at /Users/franciszekjob/Library/Caches/com.swmansion.scarb/registry/src/scarbs.xyz-9djtpev4jug5q/openzeppelin_token-3.0.0/src/erc20/erc20.cairo:118:5

Traces

Before
It was not even possible to display trace

Collected 1 test(s) from debugging_predeployed_contract package
Running 1 test(s) from tests/

thread 'tokio-runtime-worker' (28504627) panicked at crates/debugging/src/trace/collect.rs:100:14:
`ABI` should be present
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[ERROR] task 13 panicked with message "`ABI` should be present"

After

Collected 1 test(s) from debugging_predeployed_contract package
Running 0 test(s) from src/
Running 1 test(s) from tests/
[PASS] debugging_predeployed_contract_integrationtest::test_trace::test_decimals (l1_gas: ~0, l1_data_gas: ~0, l2_gas: ~129890)
[test name] debugging_predeployed_contract_integrationtest::test_trace::test_decimals
└─ [selector] decimals
   └─ [contract name] STRK

Tests: 1 passed, 0 failed, 0 ignored, 0 filtered out

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Performed self-review of the code
  • Added changes to CHANGELOG.md

@franciszekjob franciszekjob requested review from a team, DelevoXDG and ddoktorski and removed request for a team April 13, 2026 20:50
@franciszekjob
Copy link
Copy Markdown
Contributor Author

franciszekjob commented Apr 13, 2026

This change is part of the following stack:

Change managed by git-spice.

@franciszekjob franciszekjob marked this pull request as draft April 13, 2026 20:52
@franciszekjob franciszekjob changed the title Add sierra for predeployed contractss Add sierra for predeployed contracts Apr 13, 2026
@franciszekjob franciszekjob force-pushed the 3433-add-predeployed-contracts-sierra branch 2 times, most recently from 0b069ee to 26eb6c2 Compare April 13, 2026 22:03
@franciszekjob franciszekjob force-pushed the update-predeployed-contracts-casm branch from 4fca40d to c10bf19 Compare April 16, 2026 14:45
@franciszekjob franciszekjob force-pushed the 3433-add-predeployed-contracts-sierra branch from b9514d7 to ea8f43a Compare April 16, 2026 14:45
@franciszekjob franciszekjob force-pushed the 3433-add-predeployed-contracts-sierra branch from 5ed9c9d to cb454a8 Compare April 16, 2026 19:04
@franciszekjob franciszekjob force-pushed the 3433-add-predeployed-contracts-sierra branch from cb454a8 to 7b1d9b2 Compare April 16, 2026 19:06
name: ${{ inputs.artifact-name }}
path: crates/cheatnet/src/data/predeployed_contracts
if-no-files-found: error
compression-level: 0
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Intentional, because files are already stored as *.json.gz.

@franciszekjob
Copy link
Copy Markdown
Contributor Author

franciszekjob commented Apr 27, 2026

@franciszekjob franciszekjob requested a review from DelevoXDG April 27, 2026 15:56
Comment thread .github/workflows/ci.yml Outdated
Comment thread crates/cheatnet/build.rs
Comment on lines +11 to +12
println!("cargo:rerun-if-changed=build.rs");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide some context this?

It could be reasonable to add a comment explaining this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is here so Cargo reruns the build script when the validation logic in build.rs changes, even if the generated artifacts themselves did not. I added a short comment to make that intent explicit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, makes sense.

I wonder though if we should also track the build script that emits the artifacts.

Since this does not currently catch the case where artifacts may become stale relative to the updated script logic (e.g. swapped ref)

Copy link
Copy Markdown
Contributor Author

@franciszekjob franciszekjob May 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but the thing is that tracking the generator script here would only rerun this validation, but it still would not detect stale artifacts because the build script currently checks only for file presence. To actually cover cases like a swapped ref, we would need to persist some metadata/stamp from the generation step and validate it here as well.

Copy link
Copy Markdown
Contributor

@DelevoXDG DelevoXDG May 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, should we then perhaps make build.rs actually run the script itself?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is tricky to set up though - it's fine as is, considering we don't envision often bumps

Comment thread docs/src/development/predeployed-contracts.md Outdated
Comment thread scripts/setup_predeployed_contracts.sh
Comment thread scripts/setup_predeployed_contracts.sh
Comment thread scripts/setup_predeployed_contracts.sh Outdated
Comment thread scripts/setup_predeployed_contracts.sh
@franciszekjob franciszekjob requested a review from a team as a code owner May 8, 2026 10:17
@franciszekjob franciszekjob requested a review from MKowalski8 May 8, 2026 10:17
@franciszekjob franciszekjob removed the request for review from MKowalski8 May 8, 2026 10:53
Comment thread crates/cheatnet/build.rs
Comment on lines +11 to +12
println!("cargo:rerun-if-changed=build.rs");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, makes sense.

I wonder though if we should also track the build script that emits the artifacts.

Since this does not currently catch the case where artifacts may become stale relative to the updated script logic (e.g. swapped ref)

Comment thread scripts/setup_predeployed_contracts.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add sierra for predeployed token contracts

3 participants