Skip to content

feat(accounts): support SNIP-9 outside execution - #188

Merged
snickerdoodle2 merged 16 commits into
software-mansion:masterfrom
adrienlacombe:feat/snip9-outside-execution
Nov 27, 2026
Merged

snickerdoodle2 merged 16 commits into
software-mansion:masterfrom
adrienlacombe:feat/snip9-outside-execution

Conversation

@adrienlacombe

@adrienlacombe adrienlacombe commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Introduced changes

Adds SNIP-9 v1/v2 outside execution in starknet_rust_accounts::outside_execution.

API

  • OutsideExecution::new(provider, account, block, caller, execute_after, execute_before, calls) validates the exclusive timestamp interval, then gets a nonce the account confirms is unused (up to NEW_NONCE_ATTEMPTS).
  • OutsideExecutionNonce is a newtype that can only be obtained through OutsideExecutionNonce::fresh(provider, account, block, max_attempts). It checks random candidates with is_valid_outside_execution_nonce; provider errors count as failed attempts, and the last one is kept in FreshNonceError. OutsideExecution::with_nonce accepts one.
  • OutsideExecution::sign signs the SNIP-12 message (revision 0 for v1, revision 1 for v2), bound to the account and chain, with any Signer. It is the only way to get a SignedOutsideExecution.
  • SignedOutsideExecution::into_call encodes the execute_from_outside / execute_from_outside_v2 call. Relayers submit it through the normal execute_v3 builder, keeping fee, nonce and simulation options.
  • supported_version detects v2/v1 support through SRC-5 supports_interface, preferring v2, and tells unsupported accounts apart from RPC errors.
  • Docs cover ANY_CALLER, timestamp bounds and the fact that checking a nonce does not reserve it.

The module is split into errors, nonce, typed_data, execution and signed. Selectors are computed at runtime with get_selector_from_name.

Core change: the typed-data selector encoder now keeps precomputed hexadecimal felts (SNIP-9 v2 passes call selectors this way) and still hashes entrypoint names. Malformed hex and values at or above the field modulus are rejected instead of being reduced.

Reference vectors: the v1/v2 message hashes for a two-call authorization are checked against fixtures generated with the published Starknet.js 11.5.1. starknet-rust-core/test-data/typed-data/snip9/ is a small npm project (pinned package.json, committed package-lock.json, local .gitignore); npm ci --ignore-scripts && npm run generate reproduces the committed fixture byte for byte.

No compatibility with a live account contract is claimed yet.

Validation

  • 24 core typed-data tests, including the selector boundary/malformed cases.
  • 5 accounts unit tests: Starknet.js reference hashes, account/chain/call binding, Stark signature verification, exact calldata and selectors per version, time-bound validation.
  • 10 integration tests in starknet-rust-accounts/tests/outside_execution.rs with a mocked JSON-RPC transport: SRC-5 version selection and fallback, RPC-error propagation, nonce attempt limits, retry after RPC errors, and new with a checked nonce.
  • cargo clippy --all-targets -D warnings, strict rustdoc, wasm32 check, cargo fmt and jq JSON checks pass locally.

Checklist

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

🤖 Generated with Claude Code

@adrienlacombe
adrienlacombe requested a review from a team as a code owner November 6, 2026 12:13
Comment thread starknet-rust-accounts/src/lib.rs Resolved
Comment thread starknet-rust-accounts/README.md Resolved
@adrienlacombe
adrienlacombe requested a review from a team as a code owner November 16, 2026 11:58
Comment thread starknet-rust-macros/src/lib.rs Resolved
- Split outside_execution into errors, nonce, typed_data, execution and
  signed submodules.
- Add OutsideExecutionNonce newtype, obtainable only via
  OutsideExecutionNonce::fresh; OutsideExecution::new now picks a random
  nonce and with_nonce accepts a checked one.
- Retry nonce checks on provider errors, keeping the last error.
- Make SignedOutsideExecution constructible only through sign().
- Build typed data with separate type, domain and message matches.
- Revert the selector!/short_string! type-path extension; compute
  selectors at runtime instead.
- Revert unrelated contract_deployment test change.
- Move provider-mock tests to tests/outside_execution.rs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- OutsideExecution::new now obtains a checked nonce through
  OutsideExecutionNonce::fresh (NEW_NONCE_ATTEMPTS attempts) and validates
  time bounds before querying the provider.
- Drop OutsideExecutionNonce::random and ::get; use From<..> for Felt.
- Rename SignedOutsideExecution::call to into_call.
- Turn the Starknet.js vector generator into a small npm project with a
  lockfile and local .gitignore; the fixture is reproduced unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Validate time bounds only in `OutsideExecution::with_nonce` and inline
  the helper.
- Rework `OutsideExecutionNonce`: add `OutsideExecutionNonceError`
  (provider or invalid), a `new` constructor that validates a given nonce
  with the account, and make `fresh` generate one random nonce and
  validate it without retries. Remove `FreshNonceError` and
  `NEW_NONCE_ATTEMPTS`.
- Drop a redundant test binding in typed_data.rs.
- snip9 fixture project: add license, drop unused provenance string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@snickerdoodle2

Copy link
Copy Markdown
Contributor

Thanks for the contribution!

@snickerdoodle2
snickerdoodle2 merged commit b3e55da into software-mansion:master Nov 27, 2026
28 checks passed
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.

2 participants