Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,25 @@ jobs:
*.md
!PULL_REQUEST_TEMPLATE.md

- name: Verify generated Falcon NTT sources
run: |
python3 scripts/falcon_512/generate_ntt.py --write
git diff --exit-code -- packages/account/src/falcon_512/ntt

- name: Cairo lint
run: scarb fmt --check --workspace

- name: Run tests
run: snforge test --workspace --features fuzzing --fuzzer-runs 200

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Severity 2 — Low: CI runs the expensive Falcon suite redundantly.

The 65 dev-profile Falcon tests run twice (here and in the coverage run at line 67), several above 1e9 L2 gas, serial in one job — and the coverage run doesn't enable falcon_presets_tests, so the Falcon presets (SRC9 routing, upgrade's assert_only_self) report as entirely untested in Codecov anyway. Two further cost sinks: test_fast_ntt_matches_generic_reference_for_every_basis_vector alone costs 7.65B gas (~76M steps) and is single-handedly why the 100M step cap is needed (the boundary/pseudorandom test already covers the interesting cases — sample every 16th basis vector or feature-gate it); and the #[cfg(test)] felt wrapper re-inlines the 31k-statement NTT body, making ~26.7% of the test program duplicate code and a 44 MB test artifact (have it call ntt_falcon512_fast_u16_unchecked and convert instead).


- name: Run Falcon release-profile tests
run: |
snforge test -p openzeppelin_account --release --features falcon_fast_tests falcon_512 --max-n-steps 100000000
snforge test -p openzeppelin_presets --release --features falcon_presets_tests falcon_512 --max-n-steps 100000000

- name: Build release-profile presets

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Severity 3 — Medium: CI never compiles the presets to CASM, and the default profile silently produces an undeclarable class.

With casm = false in packages/presets/Scarb.toml, this step only ever produces Sierra — nothing verifies the class lowers to CASM or fits the 81,920-felt bytecode cap. Verified on this branch:

  • release profile: Falcon512ShakeAccountUpgradeable = 57,120 CASM felts (69.7% of the cap), direct = 57,048; 2.16 MB Sierra vs the ~4.09 MB class-size cap.
  • dev profile: plain scarb build -p openzeppelin_presets emits a 32.6 MB contract_class.json (8× over the declare limit, debug info balloons), and with casm = true it hard-fails with OffsetOverflowinlining-strategy = "avoid" still honors #[inline(always)] on the 9,480-line NTT body.

A future regression lands with green CI, and headroom is ~24.8k felts.

Suggested fix: enable CASM for the release target and assert bytecode size < 81,920 in CI; document that these presets are release-profile-only; consider recording them in scripts/benchmarking.

run: scarb --release build -p openzeppelin_presets

- name: Run tests and generate coverage report
run: snforge test --workspace --coverage

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `Falcon512AccountComponent`, SHAKE-256 hint and direct verifier strategies,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Severity 3 — Medium: CHANGELOG omits most of the new public API.

Missing, though all newly public: Falcon512SignatureVerifier, Falcon512ShakeVerifier, Falcon512ShakeDirectVerifier, IFeltArrayDeployable, IFeltArrayPublicKey, IFeltArrayPublicKeyCamel, FeltArrayAccountABI, Falcon512AccountUpgradeableABI + dispatchers, and the new openzeppelin_corelib_imports package (precedent for package entries exists earlier in this file).

`Falcon512ShakeAccountUpgradeable` and `Falcon512ShakeDirectAccountUpgradeable` presets with SRC9
and class upgrades, and felt-array deployment and public-key interfaces for Falcon-512 accounts
(#1730)
- `SafeERC20DispatcherTrait` in `openzeppelin_token::erc20::utils` with `assert_transfer`, `assert_transfer_from`, `assert_increase_allowance`, and `assert_decrease_allowance` (#1683)

### Changed (Breaking)
Expand Down
5 changes: 5 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies = [
name = "openzeppelin_account"
version = "4.0.0-alpha.1"
dependencies = [
"openzeppelin_corelib_imports",
"openzeppelin_interfaces",
"openzeppelin_introspection",
"openzeppelin_test_common",
Expand All @@ -47,6 +48,10 @@ dependencies = [
"snforge_std",
]

[[package]]
name = "openzeppelin_corelib_imports"
version = "4.0.0-alpha.1"

[[package]]
name = "openzeppelin_finance"
version = "4.0.0-alpha.1"
Expand Down
1 change: 1 addition & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"packages/access",
"packages/account",
"packages/corelib_imports",
"packages/finance",
"packages/interfaces",
"packages/governance",
Expand Down
60 changes: 55 additions & 5 deletions packages/account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,71 @@

> **NOTE:** This document is better viewed at [https://docs.openzeppelin.com/contracts-cairo/api/account](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account)

This crate provides components to implement account contracts that can be used for interacting with the network.
This crate provides components for building account contracts that interact with the network.

- `Account` validates transactions from signatures over the
[STARK Curve](https://docs.starknet.io/architecture-and-concepts/cryptography/#the_stark_curve).
- `AccountComponent` validates transactions from signatures over the
[STARK Curve](https://docs.starknet.io/architecture-and-concepts/cryptography/#the_stark_curve).

- `EthAccount` validates transactions from signatures over the
[Secp256k1 curve](https://en.bitcoin.it/wiki/Secp256k1).
- `EthAccountComponent` validates transactions from signatures over the
[Secp256k1 curve](https://en.bitcoin.it/wiki/Secp256k1).

- `Falcon512AccountComponent` provides felt-array public-key management and account behavior for
canonical Falcon-512 public keys. It is generic over `Falcon512SignatureVerifier` and supports
two supplied SHAKE-256 strategies:

- `Falcon512ShakeVerifier` validates a 60-felt signature containing a verifier-checked
polynomial-product hint to reduce on-chain execution cost.

- `Falcon512ShakeDirectVerifier` validates a 31-felt signature and recomputes the polynomial
product on-chain.

> **WARNING:** The supplied Falcon verifiers target the verification relation and SHAKE-256
> hash-to-point from the FALCON submission selected by NIST. Their public-key and signature
> encodings are contract-specific, and they are not FN-DSA (FIPS 206) implementations.

The Falcon component implements invoke, declare, and deploy-account validation,
signature validation, and owner-authorized felt-array public-key management. Contracts embed it
with `SRC5Component` and one of the supplied verifier strategies. Ready-to-deploy variants with
SRC9 outside execution and class upgrades are provided by the `openzeppelin_presets` package.

Falcon accounts support owner-authorized key rotation by executing a self-call to
`set_public_key` or `setPublicKey`. As with the STARK-curve and Secp256k1 accounts, the
current key authorizes the outer account transaction and the new key signs a
domain-separated ownership-acceptance message. Rotation keeps the same account address.
Because the current key authorizes the outer transaction, rotating a lost or unavailable key
requires an independent recovery mechanism. The upgradeable presets can adopt verifier changes at
the same account address through a self-authorized class upgrade.

### Build profile

Build deployable Falcon preset artifacts from this repository with
`scarb --release build -p openzeppelin_presets`. The workspace dev profile produces Falcon Sierra
artifacts that cannot be lowered to CASM. Only the workspace's `target/release` Falcon preset
artifacts are suitable for declaration. A consuming project that embeds the component must
likewise use a declaration profile with inlining enabled.

### Maintainer workflow: generated Falcon NTT sources

The Falcon root tables, bit-reversal table, and unrolled production transform are derived and
checked by `scripts/falcon_512/generate_ntt.py`. Regenerate them from the repository root and verify
the checked-in output with:

```sh
python3 scripts/falcon_512/generate_ntt.py --write
git diff --exit-code -- packages/account/src/falcon_512/ntt
```

### Interfaces

- [`ISRC6`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#ISRC6)
- [`IFeltArrayDeployable`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#IFeltArrayDeployable)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Severity 2 — Low: broken doc links and misplaced maintainer content.

  • The anchors here (#Falcon512AccountComponent, #IFeltArrayDeployable, …, and #Falcon512ShakeAccountUpgradeable in packages/presets/README.md) target adoc pages that were added in 96110a6 and deleted in 53aa1ee — they resolve nowhere. The URLs also hardcode /contracts-cairo/3.x/ while the package is 4.0.0-alpha.1.
  • The "regenerate the NTT sources" section (lines 48–57) is maintainer-only and references scripts/falcon_512/, which isn't in the published package — better in CONTRIBUTING.md.
  • Also missing from any README: the new presets aren't in sncast_scripts/src/declare_presets.cairo / its build-external-contracts, so they won't be pre-declared on Sepolia as the presets docs promise.

- [`IFeltArrayPublicKey`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#IFeltArrayPublicKey)
- [`IFeltArrayPublicKeyCamel`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#IFeltArrayPublicKeyCamel)
- [`ISRC9_V2`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#ISRC9_V2)

### Components

- [`AccountComponent`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#AccountComponent)
- [`EthAccountComponent`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#EthAccountComponent)
- [`Falcon512AccountComponent`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#Falcon512AccountComponent)
- [`SRC9Component`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#SRC9Component)
3 changes: 3 additions & 0 deletions packages/account/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ scarb.workspace = true

[dependencies]
starknet.workspace = true
openzeppelin_corelib_imports = { path = "../corelib_imports" }
openzeppelin_introspection = { path = "../introspection" }
openzeppelin_interfaces = { path = "../interfaces" }
openzeppelin_utils = { path = "../utils" }
Expand All @@ -36,6 +37,8 @@ openzeppelin_test_common = { path = "../test_common" }

[features]
fuzzing = []
# Enables tests for the generated production NTT path; requires the release compiler profile.
falcon_fast_tests = []

[lib]

Expand Down
26 changes: 26 additions & 0 deletions packages/account/src/falcon_512.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v4.0.0-alpha.1 (account/src/falcon_512.cairo)

//! Falcon-512 SHAKE account component and verifier strategies.
//!
//! `Falcon512ShakeVerifier` validates the FALCON submission relation with a verifier-checked
//! polynomial-product hint that reduces on-chain execution cost. `Falcon512ShakeDirectVerifier`
//! recomputes the product on-chain. Both strategies use SHAKE-256 hash-to-point and
//! contract-specific felt encodings; they are not FN-DSA (FIPS 206) implementations.
//!
//! `Falcon512AccountComponent` provides SRC6 account behavior and owner-authorized key rotation
//! for canonical packed Falcon-512 public keys. Ready-to-deploy compositions are provided by the
//! `openzeppelin_presets` package.

pub mod account;
pub(crate) mod falcon;
pub(crate) mod hashing;
pub(crate) mod ntt;
pub(crate) mod packing;
pub mod verifier;
pub mod verifier_impls;
pub(crate) mod zq;

pub use account::Falcon512AccountComponent;
pub use verifier::Falcon512SignatureVerifier;
pub use verifier_impls::{Falcon512ShakeDirectVerifier, Falcon512ShakeVerifier};
Loading
Loading