diff --git a/content/contracts-compact/access.mdx b/content/contracts-compact/accessControl.mdx similarity index 88% rename from content/contracts-compact/access.mdx rename to content/contracts-compact/accessControl.mdx index 66f54a4a..b7f4275f 100644 --- a/content/contracts-compact/access.mdx +++ b/content/contracts-compact/accessControl.mdx @@ -1,5 +1,5 @@ --- -title: Access Control +title: AccessControl --- {/* links */} @@ -9,14 +9,14 @@ title: Access Control [FungibleToken]: ./fungibleToken.mdx [Ownable]: ./ownable.mdx [Initializable]: ./security#initializable -[AccessControl]: api/accessControl.mdx#accessControl +[AccessControl]: api/accessControl -[assertOnlyRole]: api/access#AccessControl-assertOnlyRole -[grantRole]: api/access#AccessControl-grantRole -[_grantRole]: api/access#AccessControl-_grantRole -[_unsafeGrantRole]: api/access#AccessControl-_unsafeGrantRole -[revokeRole]: api/access#AccessControl-revokeRole -[_setRoleAdmin]: api/access#AccessControl-_setRoleAdmin +[assertOnlyRole]: api/accessControl#AccessControl-assertOnlyRole +[grantRole]: api/accessControl#AccessControl-grantRole +[_grantRole]: api/accessControl#AccessControl-_grantRole +[_unsafeGrantRole]: api/accessControl#AccessControl-_unsafeGrantRole +[revokeRole]: api/accessControl#AccessControl-revokeRole +[_setRoleAdmin]: api/accessControl#AccessControl-_setRoleAdmin This module provides a role-based access control mechanism, where roles can be used to represent a set of permissions providing the flexibility to create different levels of account authorization. @@ -50,12 +50,12 @@ Here’s a simple example of using `AccessControl` with [FungibleToken] to defin which allows accounts that have this role to create new tokens: ```ts -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/access-control/src/AccessControl" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/AccessControl" prefix AccessControl_; -import "./node_modules/@openzeppelin-compact/fungible-token/src/FungibleToken" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/FungibleToken" prefix FungibleToken_; export sealed ledger MINTER_ROLE: Bytes<32>; @@ -93,12 +93,12 @@ which can be implemented by defining _multiple_ roles. Let's augment our FungibleToken example by also defining a 'burner' role, which lets accounts destroy tokens. ```ts -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/access-control/src/AccessControl" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/AccessControl" prefix AccessControl_; -import "./node_modules/@openzeppelin-compact/fungible-token/src/FungibleToken" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/FungibleToken" prefix FungibleToken_; export sealed ledger MINTER_ROLE: Bytes<32>; @@ -169,12 +169,12 @@ and in fact it is also its own admin, this role carries significant risk. Let’s take a look at the FungibleToken example, this time taking advantage of the default admin role: ```ts -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/access-control/src/AccessControl" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/AccessControl" prefix AccessControl_; -import "./node_modules/@openzeppelin-compact/fungible-token/src/FungibleToken" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/FungibleToken" prefix FungibleToken_; export sealed ledger MINTER_ROLE: Bytes<32>; diff --git a/content/contracts-compact/api/access.mdx b/content/contracts-compact/api/accessControl.mdx similarity index 93% rename from content/contracts-compact/api/access.mdx rename to content/contracts-compact/api/accessControl.mdx index 8d7b9708..37d55a26 100644 --- a/content/contracts-compact/api/access.mdx +++ b/content/contracts-compact/api/accessControl.mdx @@ -10,7 +10,7 @@ The best way to achieve this is by using `export sealed ledger` hash digests tha ```typescript import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/contracts/src/access/AccessControl" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/AccessControl" prefix AccessControl_; export sealed ledger MY_ROLE: Bytes<32>; @@ -45,21 +45,22 @@ implement the `Initializable` module and set `DEFAULT_ADMIN_ROLE` in the `initia - For an overview of the module, read the [Access Control guide](../access). + For an overview of the module, read the [AccessControl guide](../accessControl). -## Core - -### AccessControl - -[View on GitHub](https://github.com/OpenZeppelin/compact-contracts/blob/main/contracts/src/access/AccessControl.compact) +## AccessControl [toc] [#AccessControl] + ```ts -import "./node_modules/@openzeppelin-compact/contracts/src/access/AccessControl"; +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/AccessControl"; ``` --- +### Ledger [toc] [#AccessControl-Ledger] ### Ledger [!toc] [#AccessControl-Ledger] #### _operatorRoles [toc] [#AccessControl-_operatorRoles] @@ -92,10 +93,12 @@ import "./node_modules/@openzeppelin-compact/contracts/src/access/AccessControl" The default `Bytes<32>` value mimicking a constant. +### Witnesses [toc] [#AccessControl-Witnesses] ### Witnesses [!toc] [#AccessControl-Witnesses] None. +### Circuits [toc] [#AccessControl-Circuits] ### Circuits [!toc] [#AccessControl-Circuits] #### hasRole [toc] [#AccessControl-hasRole] diff --git a/content/contracts-compact/api/fungibleToken.mdx b/content/contracts-compact/api/fungibleToken.mdx index f40b7eb2..3778a0c0 100644 --- a/content/contracts-compact/api/fungibleToken.mdx +++ b/content/contracts-compact/api/fungibleToken.mdx @@ -8,18 +8,19 @@ This module provides the full FungibleToken module API. For an overview of the module, read the [FungibleToken guide](../fungibleToken). -## Core - -### FungibleToken - -[View on GitHub](https://github.com/OpenZeppelin/compact-contracts/blob/main/contracts/src/token/FungibleToken.compact) +## FungibleToken [toc] [#FungibleToken] + ```ts -import "./node-modules/@openzeppelin-compact/contracts/src/token/FungibleToken"; +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/FungibleToken"; ``` --- +### Ledger [toc] [#FungibleToken-Ledger] ### Ledger [!toc] [#FungibleToken-Ledger] #### _balances [toc] [#FungibleToken-_balances] @@ -39,7 +40,7 @@ import "./node-modules/@openzeppelin-compact/contracts/src/token/FungibleToken"; kind="ledger" id="FungibleToken-_allowances" > - Mapping from owner accounts to spender accounts and their allowances. + Mapping from owner accounts to spender accounts to their allowances. #### _totalSupply [toc] [#FungibleToken-_totalSupply] @@ -82,10 +83,12 @@ import "./node-modules/@openzeppelin-compact/contracts/src/token/FungibleToken"; The immutable token decimals. +### Witnesses [toc] [#FungibleToken-Witnesses] ### Witnesses [!toc] [#FungibleToken-Witnesses] None. +### Circuits [toc] [#FungibleToken-Circuits] ### Circuits [!toc] [#FungibleToken-Circuits] #### initialize [toc] [#FungibleToken-initialize] diff --git a/content/contracts-compact/api/multitoken.mdx b/content/contracts-compact/api/multitoken.mdx index 37381a2d..3f0cc9e6 100644 --- a/content/contracts-compact/api/multitoken.mdx +++ b/content/contracts-compact/api/multitoken.mdx @@ -8,18 +8,19 @@ This module provides the full MultiToken module API. For an overview of the module, read the [MultiToken guide](../multitoken). -## Core - -### MultiToken - -[View on GitHub](https://github.com/OpenZeppelin/compact-contracts/blob/main/contracts/src/token/MultiToken.compact) +## MultiToken [toc] [#MultiToken] + ```ts -import "./node-modules/@openzeppelin-compact/contracts/src/token/MultiToken"; +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/MultiToken"; ``` --- +### Ledger [toc] [#MultiToken-Ledger] ### Ledger [!toc] [#MultiToken-Ledger] #### _balances [toc] [#MultiToken-_balances] @@ -52,10 +53,12 @@ import "./node-modules/@openzeppelin-compact/contracts/src/token/MultiToken"; Base URI for computing token URIs. +### Witnesses [toc] [#MultiToken-Witnesses] ### Witnesses [!toc] [#MultiToken-Witnesses] None. +### Circuits [toc] [#MultiToken-Circuits] ### Circuits [!toc] [#MultiToken-Circuits] #### initialize [toc] [#MultiToken-initialize] diff --git a/content/contracts-compact/api/nonFungibleToken.mdx b/content/contracts-compact/api/nonFungibleToken.mdx index d9901005..ad6e7724 100644 --- a/content/contracts-compact/api/nonFungibleToken.mdx +++ b/content/contracts-compact/api/nonFungibleToken.mdx @@ -8,18 +8,19 @@ This module provides the full NonFungibleToken module API. For an overview of the module, read the [NonFungibleToken guide](../nonFungibleToken). -## Core - -### NonFungibleToken - -[View on GitHub](https://github.com/OpenZeppelin/compact-contracts/blob/main/contracts/src/token/NonFungibleToken.compact) +## NonFungibleToken [toc] [#NonFungibleToken] + ```ts -import "./node-modules/@openzeppelin-compact/contracts/src/token/NonFungibleToken"; +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/NonFungibleToken"; ``` --- +### Ledger [toc] [#NonFungibleToken-Ledger] ### Ledger [!toc] [#NonFungibleToken-Ledger] #### _name [toc] [#NonFungibleToken-_name] @@ -92,10 +93,12 @@ import "./node-modules/@openzeppelin-compact/contracts/src/token/NonFungibleToke Mapping from token IDs to their metadata URIs. +### Witnesses [toc] [#NonFungibleToken-Witnesses] ### Witnesses [!toc] [#NonFungibleToken-Witnesses] None. +### Circuits [toc] [#NonFungibleToken-Circuits] ### Circuits [!toc] [#NonFungibleToken-Circuits] #### initialize [toc] [#NonFungibleToken-initialize] diff --git a/content/contracts-compact/api/ownable.mdx b/content/contracts-compact/api/ownable.mdx index 35398152..ab892383 100644 --- a/content/contracts-compact/api/ownable.mdx +++ b/content/contracts-compact/api/ownable.mdx @@ -8,18 +8,19 @@ This module provides the full Ownable module API. For an overview of the module, read the [Ownable guide](../ownable). -## Core - -### Ownable - -[View on GitHub](https://github.com/OpenZeppelin/compact-contracts/blob/main/contracts/src/access/Ownable.compact) +## Ownable [toc] [#Ownable] + ```ts -import "./node-modules/@openzeppelin-compact/contracts/src/access/Ownable"; +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/Ownable"; ``` --- +### Ledger [toc] [#Ownable-Ledger] ### Ledger [!toc] [#Ownable-Ledger] #### _owner [toc] [#Ownable-_owner] @@ -32,10 +33,12 @@ import "./node-modules/@openzeppelin-compact/contracts/src/access/Ownable"; Either a `ZswapCoinPublicKey` or `ContractAddress` representing the owner. +### Witnesses [toc] [#Ownable-Witnesses] ### Witnesses [!toc] [#Ownable-Witnesses] None. +### Circuits [toc] [#Ownable-Circuits] ### Circuits [!toc] [#Ownable-Circuits] #### initialize [toc] [#Ownable-initialize] @@ -194,14 +197,21 @@ None. * Contract is initialized. -### ZOwnablePK [#ZOwnablePK] +--- -[View on GitHub](https://github.com/OpenZeppelin/compact-contracts/blob/main/contracts/src/access/ZOwnablePK.compact) +## ZOwnablePK [toc] [#ZOwnablePK] + ```ts -import "./node-modules/@openzeppelin-compact/contracts/src/access/ZOwnablePK"; +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/ZOwnablePK"; ``` +--- + +### Ledger [toc] [#ZOwnablePK-ledger] ### Ledger [!toc] [#ZOwnablePK-ledger] #### _ownerCommitment [toc] [#ZOwnablePK-_ownerCommitment] @@ -244,6 +254,7 @@ import "./node-modules/@openzeppelin-compact/contracts/src/access/ZOwnablePK"; It is immutable after initialization. +### Witnesses [toc] [#ZOwnablePK-witnesses] ### Witnesses [!toc] [#ZOwnablePK-witnesses] #### wit_secretNonce [toc] [#ZOwnablePK-wit_secretNonce] @@ -259,6 +270,7 @@ import "./node-modules/@openzeppelin-compact/contracts/src/access/ZOwnablePK"; Users are encouraged to rotate this value on ownership changes. +### Circuits [toc] [#ZOwnablePK-circuits] ### Circuits [!toc] [#ZOwnablePK-circuits] #### initialize [toc] [#ZOwnablePK-initialize] diff --git a/content/contracts-compact/api/security.mdx b/content/contracts-compact/api/security.mdx index 3452cd62..e6f4dcd3 100644 --- a/content/contracts-compact/api/security.mdx +++ b/content/contracts-compact/api/security.mdx @@ -8,18 +8,19 @@ This package provides the API for all Security modules. For an overview of the module, read the [Security guide](../security). -## Initializable - -### Initializable - -[View on GitHub](https://github.com/OpenZeppelin/compact-contracts/blob/main/contracts/src/security/Initializable.compact) +## Initializable [toc] [#Initializable] + ```ts -import "./node-modules/@openzeppelin-compact/contracts/src/security/Initializable"; +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/security/Initializable"; ``` --- +### Ledger [toc] [#Initializable-Ledger] ### Ledger [!toc] [#Initializable-Ledger] #### _isInitialized [toc] [#Initializable-_isInitialized] @@ -32,10 +33,12 @@ import "./node-modules/@openzeppelin-compact/contracts/src/security/Initializabl Boolean indicating if initialized. +### Witnesses [toc] [#Initializable-Witnesses] ### Witnesses [!toc] [#Initializable-Witnesses] None. +### Circuits [toc] [#Initializable-Circuits] ### Circuits [!toc] [#Initializable-Circuits] #### initialize [toc] [#Initializable-initialize] @@ -83,16 +86,21 @@ None. * Contract must not be initialized. -## Pausable - -### Pausable +--- -[View on GitHub](https://github.com/OpenZeppelin/compact-contracts/blob/main/contracts/src/security/Pausable.compact) +## Pausable [toc] [#Pausable] + ```ts -import "./node-modules/@openzeppelin-compact/contracts/src/security/Pausable"; +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/security/Pausable"; ``` +--- + +### Ledger [toc] [#Pausable-Ledger] ### Ledger [!toc] [#Pausable-Ledger] #### _isPaused [toc] [#Pausable-_isPaused] @@ -105,10 +113,12 @@ import "./node-modules/@openzeppelin-compact/contracts/src/security/Pausable"; Boolean indicating if paused. +### Witnesses [toc] [#Pausable-Witnesses] ### Witnesses [!toc] [#Pausable-Witnesses] None. +### Circuits [toc] [#Pausable-Circuits] ### Circuits [!toc] [#Pausable-Circuits] #### isPaused [toc] [#Pausable-isPaused] diff --git a/content/contracts-compact/api/utils.mdx b/content/contracts-compact/api/utils.mdx index 7faca070..81a36c96 100644 --- a/content/contracts-compact/api/utils.mdx +++ b/content/contracts-compact/api/utils.mdx @@ -8,28 +8,33 @@ This package provides the API for all Utils modules. For an overview of the module, read the [Utils guide](/contracts-compact/utils). -## Utils - -### Utils - -[View on GitHub](https://github.com/OpenZeppelin/compact-contracts/blob/main/contracts/src/utils/Utils.compact) +## Utils [toc] [#Utils] + ```ts -import "./node-modules/@openzeppelin-compact/contracts/src/security/Initializable"; +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/security/Initializable"; ``` +--- + There’s no easy way to get the constraints of circuits at this time so the constraints of the circuits listed below have been omitted. +### Ledger [toc] [#Utils-Ledger] ### Ledger [!toc] [#Utils-Ledger] None. +### Witnesses [toc] [#Utils-Witnesses] ### Witnesses [!toc] [#Utils-Witnesses] None. +### Circuits [toc] [#Utils-Circuits] ### Circuits [!toc] [#Utils-Circuits] #### isKeyOrAddressZero [toc] [#Utils-isKeyOrAddressZero] diff --git a/content/contracts-compact/extensibility.mdx b/content/contracts-compact/extensibility.mdx index 00f3f3e5..b8673cfe 100644 --- a/content/contracts-compact/extensibility.mdx +++ b/content/contracts-compact/extensibility.mdx @@ -51,14 +51,14 @@ As Compact matures, this pattern will likely evolve as well. ```ts // FungibleTokenMintablePausableOwnableContract -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/contracts/src/access/Ownable" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/Ownable" prefix Ownable_; -import "./node_modules/@openzeppelin-compact/contracts/src/security/Pausable" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/security/Pausable" prefix Pausable_; -import "./node_modules/@openzeppelin-compact/contracts/src/token/FungibleToken" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/FungibleToken" prefix FungibleToken_; constructor( diff --git a/content/contracts-compact/fungibleToken.mdx b/content/contracts-compact/fungibleToken.mdx index 5934a0f4..134a5e24 100644 --- a/content/contracts-compact/fungibleToken.mdx +++ b/content/contracts-compact/fungibleToken.mdx @@ -3,7 +3,7 @@ title: FungibleToken --- {/* links */} -[fungible tokens]: https://docs.openzeppelin.com/contracts/5.x/tokens#different-kinds-of-tokens +[fungible tokens]: ../contracts/5.x/tokens.mdx#different-kinds-of-tokens [EIP-20]: https://eips.ethereum.org/EIPS/eip-20 [Module/Contract Pattern]: ./extensibility.mdx#the_module_contract_pattern [_mint]: api/fungibleToken#FungibleToken-_mint @@ -49,10 +49,10 @@ Import the FungibleToken module into the implementing contract. It’s recommended to prefix the module with `FungibleToken_` to avoid circuit signature clashes. ```typescript -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/contracts/src/token/FungibleToken" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/FungibleToken" prefix FungibleToken_; constructor( @@ -90,10 +90,10 @@ export circuit decimals(): Uint<8> { The following example is a simple token contract with a fixed supply that’s minted to the passed recipient upon construction. ```typescript -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/contracts/src/token/FungibleToken" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/FungibleToken" prefix FungibleToken_; constructor( diff --git a/content/contracts-compact/index.mdx b/content/contracts-compact/index.mdx index 3747f0cf..e13d0664 100644 --- a/content/contracts-compact/index.mdx +++ b/content/contracts-compact/index.mdx @@ -8,7 +8,7 @@ title: Contracts for Compact [yarn]: https://yarnpkg.com/getting-started/install [compact-dev-tools]: https://docs.midnight.network/blog/compact-developer-tools -*A library for secure smart contract development* written in Compact for [Midnight]. +**A library for secure smart contract development** written in Compact for [Midnight]. This library consists of modules to build custom smart contracts. @@ -20,13 +20,13 @@ Expect rapid iteration. **Use at your own risk.** Make sure you have [nvm] and [yarn] installed on your machine. -Follow Midnight's [compact-dev-tools] installation guide and confirm that `compact` is in the `PATH` env variable. +Follow Midnight's [Compact Developer Tools][compact-dev-tools] installation guide and confirm that `compact` is in the `PATH` env variable. ```bash $ compact compile --version -Compactc version: 0.24.0 -0.24.0 +Compactc version: {{compact_compiler_version}} +{{compact_compiler_version}} ``` ### Installation @@ -66,7 +66,7 @@ Installing the library will be easier once it's available as an NPM package. ```typescript // MyContract.compact -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/Ownable" diff --git a/content/contracts-compact/multitoken.mdx b/content/contracts-compact/multitoken.mdx index 7346487d..c55bef7b 100644 --- a/content/contracts-compact/multitoken.mdx +++ b/content/contracts-compact/multitoken.mdx @@ -17,23 +17,23 @@ Even though Midnight is not EVM-compatible, this implementation attempts to be a Some features and behaviors are either not possible, not possible yet, or changed because of the vastly different tech stack and Compact language constraints. -***Notable changes*** +**Notable changes** -* ***`Uint<128>` as value and id type*** - Since 256-bit unsigned integers are not supported, +* **`Uint<128>` as value and id type** - Since 256-bit unsigned integers are not supported, the library uses the Compact type `Uint<128>`. -***Features and specifications NOT supported*** +**Features and specifications NOT supported** -* ***Events*** - Midnight does not currently support events, but this is planned on being supported in the future. -* ***Uint256 type*** - There’s ongoing research on ways to support uint256 in the future. -* ***Interface*** - Compact currently does not have a way to define a contract interface. +* **Events** - Midnight does not currently support events, but this is planned on being supported in the future. +* **Uint256 type** - There’s ongoing research on ways to support uint256 in the future. +* **Interface** - Compact currently does not have a way to define a contract interface. This library offers modules of contracts with free floating circuits; nevertheless, there’s no means of enforcing that all circuits are provided. -* ***Batch mint, burn, transfer*** - Without support for dynamic arrays, +* **Batch mint, burn, transfer** - Without support for dynamic arrays, batching transfers is difficult to do without a hacky solution. For instance, we could change the `to` and `from` parameters to be vectors. This would change the signature and would be both difficult to use and easy to misuse. -* ***Querying batched balances*** - This can be somewhat supported. +* **Querying batched balances** - This can be somewhat supported. The issue, without dynamic arrays, is that the module circuit must use `Vector` for accounts and ids; therefore, the implementing contract must explicitly define the number of balances to query in the circuit i.e. @@ -46,9 +46,9 @@ balanceOfBatch_10( Since this module does not offer mint or transfer batching, balance batching is also not included at this time. -* ***Introspection*** - Compact currently cannot support contract-to-contract queries for introspection. +* **Introspection** - Compact currently cannot support contract-to-contract queries for introspection. [ERC165] (or an equivalent thereof) is NOT included in the contract. -* ***Safe transfers*** - The lack of an introspection mechanism means safe transfers of any kind can not be supported. +* **Safe transfers** - The lack of an introspection mechanism means safe transfers of any kind can not be supported. ## Contract-to-contract calls @@ -68,10 +68,10 @@ Import the MultiToken module into the implementing contract. It’s recommended to prefix the module with `MultiToken_` to avoid circuit signature clashes. ```typescript -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/multi-token/src/MultiToken" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/MultiToken" prefix MultiToken_; constructor( @@ -105,10 +105,10 @@ The following example is a simple multi-token contract that creates both a fixed ```typescript // MultiTokenTwoTokenTypes.compact -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/multi-token/src/MultiToken" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/MultiToken" prefix MultiToken_; constructor( diff --git a/content/contracts-compact/nonFungibleToken.mdx b/content/contracts-compact/nonFungibleToken.mdx index 7543d0bd..50c2f031 100644 --- a/content/contracts-compact/nonFungibleToken.mdx +++ b/content/contracts-compact/nonFungibleToken.mdx @@ -3,7 +3,7 @@ title: NonFungibleToken --- {/* links */} -[non-fungible tokens]: https://docs.openzeppelin.com/contracts/5.x/tokens#different-kinds-of-tokens +[non-fungible tokens]: ../contracts/5.x/tokens.mdx#different-kinds-of-tokens [EIP-721]: https://eips.ethereum.org/EIPS/eip-721 [ERC-165]: https://eips.ethereum.org/EIPS/eip-165 [Module/Contract Pattern]: ./extensibility#the-modulecontract-pattern @@ -58,10 +58,10 @@ Import the NonFungibleToken module into the implementing contract. It’s recommended to prefix the module with `NonFungibleToken_` to avoid circuit signature clashes. ```typescript -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/non-fungible-token/src/NonFungibleToken" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/NonFungibleToken" prefix NonFungibleToken_; constructor(name: Opaque<"string">, symbol: Opaque<"string">) { @@ -93,10 +93,10 @@ The following example is a simple non-fungible token contract that mints an NFT ```typescript // SimpleNonFungibleToken.compact -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/non-fungible-token/src/NonFungibleToken" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/token/NonFungibleToken" prefix NonFungibleToken_; constructor( diff --git a/content/contracts-compact/ownable.mdx b/content/contracts-compact/ownable.mdx index 6bc3c16b..d441f96d 100644 --- a/content/contracts-compact/ownable.mdx +++ b/content/contracts-compact/ownable.mdx @@ -3,16 +3,24 @@ title: Ownable --- {/* links */} -[initialize]: api/ownable#initialize +[initialize]: api/ownable#Ownable-initialize [transferOwnership]: api/ownable#Ownable-transferOwnership [_transferOwnership]: api/ownable#Ownable-_transferOwnership [_unsafeTransferOwnership]: api/ownable#Ownable-_unsafeTransferOwnership [_unsafeUncheckedTransferOwnership]: api/ownable#Ownable-_unsafeUncheckedTransferOwnership [_computeOwnerId]: api/ownable#ZOwnablePK-_computeOwnerId +[assertOnlyOwner]: api/ownable#ZOwnablePK-assertOnlyOwner [ed25519]: https://ed25519.cr.yp.to/ [rfc6979]: https://datatracker.ietf.org/doc/html/rfc6979 +## Access Control Defined + +Access control—that is, "who is allowed to do this thing"—is incredibly important in the world of smart contracts. +The access control of your contract may govern who can mint tokens, vote on proposals, freeze transfers, and many other things. +It is therefore critical to understand how you implement it, lest someone else steals your whole system. +OpenZeppelin Contracts for Compact provides a variety of access control modules to suit your application and privacy needs. + ## Ownership and `Ownable` The most common and basic form of access control is the concept of ownership: @@ -20,7 +28,7 @@ there’s an account that is the owner of a contract and can do administrative t This approach is perfectly reasonable for contracts that have a single administrative user. OpenZeppelin Contracts for Compact provides an Ownable module for implementing ownership in your contracts. -The initial owner must be set by using the initialize circuit during construction. +The initial owner must be set by using the [initialize] circuit during construction. This can later be changed with [transferOwnership]. ### Ownership transfers @@ -49,10 +57,10 @@ Import the Ownable module into the implementing contract. It’s recommended to prefix the module with `Ownable_` to avoid circuit signature clashes. ```ts -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/ownable/src/Ownable" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/Ownable" prefix Ownable_; constructor( @@ -86,10 +94,10 @@ Here’s a complete contract showcasing how to integrate the Ownable module and ```ts // SimpleOwnable.compact -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/ownable/src/Ownable" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/Ownable" prefix Ownable_; /** @@ -263,7 +271,7 @@ const recoverableOwnerId = ZOwnablePK._computeOwnerId(publicKey, deterministicNo **Security Considerations** -The ZOwnablePK module remains agnostic to nonce generation methods, +The `ZOwnablePK` module remains agnostic to nonce generation methods, placing the security/convenience decision entirely with the user. Key considerations include: @@ -284,7 +292,7 @@ similar to how air-gapped systems are isolated from networks to prevent data lea #### The Privacy Enhancement -While ZOwnablePK provides cryptographic privacy through its commitment scheme, +While `ZOwnablePK` provides cryptographic privacy through its commitment scheme, operational security practices like using an AGPK provide an additional layer of protection against correlation attacks. Even with the strongest cryptographic commitments, reusing a public key across different on-chain activities can potentially compromise privacy through transaction pattern analysis. @@ -297,7 +305,7 @@ An Air-Gapped Public Key must adhere to strict isolation principles: has never generated any public key that appears in any on-chain transaction, across any blockchain network. The key material must be cryptographically pure. * **Never used elsewhere**: From the moment of AGPK generation until its destruction, -the private key material is used exclusively for this contract’s administrative functions (i.e. assertOnlyOwner). +the private key material is used exclusively for this contract’s administrative functions (i.e. [assertOnlyOwner]). No other public keys may ever be derived from or generated with the same key material. * **Never used again**: Users commit to destroying all copies of the private key material upon ownership renunciation or transfer. This relies entirely on user discipline and cannot be externally verified or enforced. @@ -321,10 +329,10 @@ It’s recommended to prefix the module with `ZOwnablePK_` to avoid circuit sign ```typescript // MyZOwnablePKContract.compact -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import "./node_modules/@openzeppelin-compact/contracts/src/access/ZOwnablePK" +import "./compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/ZOwnablePK" prefix ZOwnablePK_; constructor( @@ -347,7 +355,7 @@ export circuit renounceOwnership(): [] { } ``` -Similar to the Ownable module, +Similar to the [Ownable](#usage) module, circuits can be protected so that only the contract owner may them by adding `assertOnlyOwner` as the first line in the circuit body like this: ```typescript diff --git a/content/contracts-compact/security.mdx b/content/contracts-compact/security.mdx index 612d90f1..af857de7 100644 --- a/content/contracts-compact/security.mdx +++ b/content/contracts-compact/security.mdx @@ -21,10 +21,10 @@ Many modules also use the initializable pattern which ensures that implementing ```ts // CustomContractStateSetup.compact -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import './node_modules/@openzeppelin-compact/contracts/src/security/Initializable'; +import './compact-contracts/node_modules/@openzeppelin-compact/contracts/src/security/Initializable'; export ledger _fieldAfterDeployment: Field; @@ -68,12 +68,12 @@ For example (using the [Ownable] module for access control): ```ts // OwnablePausable.compact -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import './node_modules/@openzeppelin-compact/contracts/src/security/Initializable' +import './compact-contracts/node_modules/@openzeppelin-compact/contracts/src/security/Initializable' prefix Initializable_; -import './node_modules/@openzeppelin-compact/contracts/src/access/Ownable' +import './compact-contracts/node_modules/@openzeppelin-compact/contracts/src/access/Ownable' prefix Ownable_; constructor(initOwner: Either) { diff --git a/content/contracts-compact/utils.mdx b/content/contracts-compact/utils.mdx index 2593e7b1..66b41195 100644 --- a/content/contracts-compact/utils.mdx +++ b/content/contracts-compact/utils.mdx @@ -7,10 +7,10 @@ The Utils module provides miscellaneous circuits and common utilities for Compac ### Usage ```typescript -pragma language_version >= 0.16.0; +pragma language_version >= {{compact_language_version}}; import CompactStandardLibrary; -import './node_modules/@openzeppelin-compact/utils/src/Utils' +import './compact-contracts/node_modules/@openzeppelin-compact/contracts/src/utils/Utils' prefix Utils_; export circuit performActionWhenEqual( diff --git a/content/contracts-compact/utils/constants.js b/content/contracts-compact/utils/constants.js new file mode 100644 index 00000000..a204daa8 --- /dev/null +++ b/content/contracts-compact/utils/constants.js @@ -0,0 +1,2 @@ +export const COMPACT_COMPILER_VERSION = "0.24.0"; +export const COMPACT_LANGUAGE_VERSION = "0.16.0"; diff --git a/content/contracts-compact/utils/replacements.ts b/content/contracts-compact/utils/replacements.ts new file mode 100644 index 00000000..6072127f --- /dev/null +++ b/content/contracts-compact/utils/replacements.ts @@ -0,0 +1,9 @@ +import { COMPACT_COMPILER_VERSION, COMPACT_LANGUAGE_VERSION } from "./constants"; + +export const REPLACEMENTS = { + include: ['**/content/contracts-compact/**/*.mdx'], + replacements: { + compact_compiler_version: COMPACT_COMPILER_VERSION, + compact_language_version: COMPACT_LANGUAGE_VERSION + } +} diff --git a/source.config.ts b/source.config.ts index a1a011b8..5c556bd2 100644 --- a/source.config.ts +++ b/source.config.ts @@ -4,37 +4,39 @@ import rehypeKatex from "rehype-katex"; import { remarkMdxMermaid } from "fumadocs-core/mdx-plugins"; import remarkReplace from "@/lib/remark-replace"; import { REPLACEMENTS as cairoContractReplacements } from "content/contracts-cairo/utils/replacements"; +import { REPLACEMENTS as compactContractReplacements } from "content/contracts-compact/utils/replacements"; // You can customise Zod schemas for frontmatter and `meta.json` here // see https://fumadocs.vercel.app/docs/mdx/collections#define-docs export const docs = defineDocs({ - dir: "content", - // Async mode - enables runtime compilation for faster dev server startup - docs: { - async: true, - }, - // To switch back to sync mode (pre-compilation), comment out the docs config above and uncomment below: - // (sync mode - pre-compiles all content at build time) - // No additional config needed for sync mode - just remove the docs config + dir: "content", + // Async mode - enables runtime compilation for faster dev server startup + docs: { + async: true, + }, + // To switch back to sync mode (pre-compilation), comment out the docs config above and uncomment below: + // (sync mode - pre-compiles all content at build time) + // No additional config needed for sync mode - just remove the docs config }); export default defineConfig({ - mdxOptions: { - rehypeCodeOptions: { - fallbackLanguage: "plaintext", - themes: { - light: "github-light", - dark: "github-dark", - }, - }, - remarkPlugins: [remarkMath, remarkMdxMermaid, + mdxOptions: { + rehypeCodeOptions: { + fallbackLanguage: "plaintext", + themes: { + light: "github-light", + dark: "github-dark", + }, + }, + remarkPlugins: [remarkMath, remarkMdxMermaid, [ - remarkReplace, - [ - cairoContractReplacements, - ] - ], - ], - rehypePlugins: (v) => [rehypeKatex, ...v], - }, + remarkReplace, + [ + cairoContractReplacements, + compactContractReplacements + ] + ], + ], + rehypePlugins: (v) => [rehypeKatex, ...v], + }, }); diff --git a/src/components/ui/api-reference/api-github-link-header.tsx b/src/components/ui/api-reference/api-github-link-header.tsx index cde8684f..f0fb31a7 100644 --- a/src/components/ui/api-reference/api-github-link-header.tsx +++ b/src/components/ui/api-reference/api-github-link-header.tsx @@ -24,9 +24,9 @@ export function APIGithubLinkHeader({ viewBox="0 0 24 24" fill="none" stroke="currentColor" - stroke-width="2" - stroke-linecap="round" - stroke-linejoin="round" + strokeWidth="2" + strokeLinecap="round" + strokeLinejoin="round" className="lucide lucide-github-icon lucide-github" > GitHub icon diff --git a/src/navigation/midnight.json b/src/navigation/midnight.json index ef4f18c8..d1411012 100644 --- a/src/navigation/midnight.json +++ b/src/navigation/midnight.json @@ -35,13 +35,13 @@ "children": [ { "type": "page", - "name": "Access Control", - "url": "/contracts-compact/access" + "name": "Ownable", + "url": "/contracts-compact/ownable" }, { "type": "page", - "name": "Ownable", - "url": "/contracts-compact/ownable" + "name": "AccessControl", + "url": "/contracts-compact/accessControl" } ] }, @@ -84,8 +84,8 @@ "children": [ { "type": "page", - "name": "Access API", - "url": "/contracts-compact/api/access" + "name": "AccessControl API", + "url": "/contracts-compact/api/accessControl" }, { "type": "page",