Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `MultisigAccountComponent`, its signer-management interfaces, and the SRC9-enabled
`MultisigAccountUpgradeable` preset for quorum-based STARK-curve account authorization
- `SafeERC20DispatcherTrait` in `openzeppelin_token::erc20::utils` with `assert_transfer`, `assert_transfer_from`, `assert_increase_allowance`, and `assert_decrease_allowance` (#1683)

### Changed (Breaking)
Expand Down
522 changes: 522 additions & 0 deletions docs/modules/ROOT/pages/api/account.adoc

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions docs/modules/ROOT/pages/presets.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:erc721-upgradeable: xref:/api/erc721.adoc#ERC721Upgradeable[ERC721Upgradeable]
:erc1155-upgradeable: xref:/api/erc1155.adoc#ERC1155Upgradeable[ERC1155Upgradeable]
:eth-account-upgradeable: xref:/api/account.adoc#EthAccountUpgradeable[EthAccountUpgradeable]
:multisig-account-upgradeable: xref:/api/account.adoc#MultisigAccountUpgradeable[MultisigAccountUpgradeable]
:udc: xref:/api/udc.adoc#UniversalDeployer[UniversalDeployer]
:vesting-wallet: xref:/api/finance.adoc#VestingWallet[VestingWallet]
:sierra-class-hashes: https://docs.starknet.io/architecture-and-concepts/smart-contracts/class-hash/[Sierra class hashes]
Expand All @@ -14,10 +15,10 @@

include::utils/_class_hashes.adoc[]

Presets are ready-to-deploy contracts provided by the library. Since presets are intended to be very simple
and as generic as possible, there's no support for custom or complex contracts such as `ERC20Pausable` or `ERC721Mintable`.
Presets are ready-to-deploy contracts that combine widely used components into simple,
general-purpose configurations.

TIP: For contract customization and combination of modules you can use {wizard}, our code-generation tool.
TIP: Use {wizard}, our code-generation tool, to build custom combinations of components.


== Available presets
Expand All @@ -36,6 +37,9 @@ CAUTION: Before version 4.0.0-alpha.1, class hashes were computed using the `sca
| `{account-upgradeable}`
| `{AccountUpgradeable-class-hash}`

| `{multisig-account-upgradeable}`
| `{MultisigAccountUpgradeable-class-hash}`

| `{erc20-upgradeable}`
| `{ERC20Upgradeable-class-hash}`

Expand All @@ -55,6 +59,12 @@ CAUTION: Before version 4.0.0-alpha.1, class hashes were computed using the `sca
| `{VestingWallet-class-hash}`
|===

The {multisig-account-upgradeable} preset provides quorum-based STARK-curve authorization through
SRC6, outside execution through SRC9, and self-authorized class upgrades. Its constructor accepts
a quorum and a signer span, and account signatures use the canonical
`[1, n, public_key_1, r_1, s_1, ..., public_key_n, r_n, s_n]` encoding documented by
xref:/api/account.adoc#MultisigAccountComponent[MultisigAccountComponent].

TIP: {starkli} class-hash command can be used to compute the class hash from a Sierra artifact.

== Usage
Expand Down
19 changes: 10 additions & 9 deletions docs/modules/ROOT/pages/utils/_class_hashes.adoc
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Version
:class-hash-cairo-version: https://crates.io/crates/cairo-lang-compiler/2.17.0[cairo 2.17.0]
:class-hash-cairo-version: https://crates.io/crates/cairo-lang-compiler/2.18.0[cairo 2.18.0]

// Class Hashes
:ERC20Upgradeable-class-hash: 0x02306d411d9061591d2a661f177ea92e53918a474803c33a901bace86dfaea6c
:ERC721Upgradeable-class-hash: 0x0735400adfb617a215a0eadd009e84ecebf10b258b7ce7583d4131f7fa793bf1
:ERC1155Upgradeable-class-hash: 0x02f81498862c308981a544e7da3e65c715c375c97a881da2d157b2f3a3dcdd93
:AccountUpgradeable-class-hash: 0x0342f3c683f708fd920e625e425b77726aa4c834da47ec92b4da5c207f025207
:EthAccountUpgradeable-class-hash: 0x0216f6773aef13b25e5f8ecc989c4a4668d45ba118b41bbdca10d08fc6fda878
:UniversalDeployer-class-hash: 0x00ce766f9026176e6796a13720059301c4caa1b24cc55d964afb62bed07b0158
:MetaTransactionV0-class-hash: 0x051d6576154ab74933e521cd0d8e3367d14ff1713fd2b2ce982af1f555564134
:VestingWallet-class-hash: 0x051be0e6c0a6904b496c77f991f423e766ff465752cb18e93b6eb5ca525cf219
:ERC20Upgradeable-class-hash: 0x06d081c70145f14c3e0d05eacbfaa01620a27fde89430e6c227a8f4a573e3727
:ERC721Upgradeable-class-hash: 0x05f3d201fc5c9de757ca6c42ec753d514ab1ea011b60bd139b6167cd069109d2
:ERC1155Upgradeable-class-hash: 0x075829cba5eea49a998988967e6a97de68824830118f7f008f3ac07d407cb99a
:AccountUpgradeable-class-hash: 0x03013bf2edcf93ac575367eee41cd07bb50e809c78925817b61878db29826144
:MultisigAccountUpgradeable-class-hash: 0x05e016dd4ace8b826345a13d90929f149658b7562373c86397c4af3c1cc7bc61
:EthAccountUpgradeable-class-hash: 0x000be1cf8839442d664572712fd36554c4d259f86549ad02e22353d10729b900
:UniversalDeployer-class-hash: 0x05412c7a3e145fdc79862e65df612324d83b0169c071dd564021155bd8cfd29e
:MetaTransactionV0-class-hash: 0x059b5a7a062db4a9fa1ec4b96ea74cac3d55477971d68ac9fba877c087e59808
:VestingWallet-class-hash: 0x05613fb6c8f729fdcbef50d25c9dd72260762543d48254c59e6851dd3d46595a

// Presets page
:presets-page: xref:presets.adoc[Sierra class hash]
Expand Down
40 changes: 35 additions & 5 deletions packages/account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,51 @@

> **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).

- `MultisigAccountComponent` validates transactions when a configured quorum of registered
STARK-curve signers authorizes the same hash.

### Multisig signatures

`MultisigAccountComponent` accepts the canonical felt-array encoding
`[1, n, public_key_1, r_1, s_1, ..., public_key_n, r_n, s_n]`. The first felt is the signature
format version, and `n` is the number of signer records that follow. Signer public keys must be
strictly increasing, which makes every signer distinct, and every `(r, s)` pair must be a valid
STARK-curve signature for the same hash from its associated registered signer.

A signature is valid when its header matches the encoded records, `n` is at least the account
quorum and no greater than the registered signer count, and every supplied record is valid.
`is_valid_signature` returns `starknet::VALIDATED` for a valid signature and `0` otherwise. The
`invoke`, `declare`, and `deploy_account` validation entry points return `starknet::VALIDATED` for
a valid signature and revert when validation fails.

Signature validation verifies every supplied signer record, so its execution cost grows linearly
with `n`. Callers can minimize validation work by supplying the smallest valid signer quorum.
Configure a quorum that fits within Starknet account-validation resource limits: an impractically
high required quorum can prevent the account from authorizing a configuration recovery.

Signer additions, removals, replacements, and quorum changes accept calls only from the account
itself. The current quorum can therefore manage the account configuration through an authorized
account transaction. The governance multisig coordinates proposals and confirmations, while
`MultisigAccountComponent` authenticates account transactions during SRC6 validation.

### Interfaces

- [`ISRC6`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#ISRC6)
- [`IMultisigAccount`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#IMultisigAccount)
- [`IMultisigDeployable`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#IMultisigDeployable)
- [`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)
- [`MultisigAccountComponent`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#MultisigAccountComponent)
- [`SRC9Component`](https://docs.openzeppelin.com/contracts-cairo/3.x/api/account#SRC9Component)
2 changes: 2 additions & 0 deletions packages/account/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ name = "openzeppelin_account_unittest"
build-external-contracts = [
"openzeppelin_test_common::mocks::account::DualCaseAccountMock",
"openzeppelin_test_common::mocks::account::DualCaseEthAccountMock",
"openzeppelin_test_common::mocks::multisig_account::MultisigAccountMock",
"openzeppelin_test_common::mocks::multisig_account::SignatureCallerMock",
"openzeppelin_test_common::mocks::src9::SRC9AccountMock",
"openzeppelin_test_common::mocks::simple::SimpleMock",
]
2 changes: 2 additions & 0 deletions packages/account/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub mod account;
pub mod eth_account;
pub mod extensions;
pub mod multisig_account;

#[cfg(test)]
mod tests;
pub mod utils;

pub use account::AccountComponent;
pub use eth_account::EthAccountComponent;
pub use multisig_account::MultisigAccountComponent;
4 changes: 4 additions & 0 deletions packages/account/src/multisig_account.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod multisig_account;
pub mod storage_utils;

pub use multisig_account::MultisigAccountComponent;
Loading
Loading