From 232c673ed5a5ceda6457e8b9d60932d908b7b127 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Thu, 11 Jul 2024 14:10:04 +0200 Subject: [PATCH] Bump cairo to 2.7.0-rc.1 (#1025) * feat: migrate modules * feat: delete cairo_project.toml * feat: update tests * feat: apply review updates * fix: remove extra line * feat: add CHANGELOG entry * fix: CHANGELOG --- CHANGELOG.md | 8 +- Scarb.toml | 9 ++- src/access/accesscontrol/accesscontrol.cairo | 9 ++- src/account/account.cairo | 4 +- src/account/dual_eth_account.cairo | 1 - src/account/eth_account.cairo | 6 +- src/account/interface.cairo | 1 - src/account/utils/secp256k1.cairo | 14 +--- src/cairo_project.toml | 2 - src/governance/utils/interfaces/votes.cairo | 7 +- src/introspection/src5.cairo | 3 +- src/presets/account.cairo | 3 +- src/presets/eth_account.cairo | 1 - src/presets/interfaces/eth_account.cairo | 1 - src/security/reentrancyguard.cairo | 3 +- src/tests/access/test_ownable.cairo | 1 - src/tests/access/test_ownable_twostep.cairo | 1 - .../ethereum/test_dual_eth_account.cairo | 20 +++-- .../account/ethereum/test_eth_account.cairo | 4 +- src/tests/account/test_secp256k1.cairo | 50 +----------- src/tests/mocks/erc721_receiver_mocks.cairo | 2 +- src/tests/mocks/eth_account_mocks.cairo | 5 -- src/tests/presets/test_eth_account.cairo | 14 ++-- src/tests/security/test_reentrancyguard.cairo | 1 - src/tests/token/erc1155/test_dual1155.cairo | 8 +- src/tests/token/erc1155/test_erc1155.cairo | 1 - src/tests/token/erc20/test_erc20_votes.cairo | 5 +- src/tests/token/erc721/test_erc721.cairo | 1 - src/token/erc1155/erc1155.cairo | 51 ++++++++----- src/token/erc20/erc20.cairo | 15 ++-- src/token/erc20/extensions/erc20_votes.cairo | 26 ++++--- src/token/erc721/erc721.cairo | 76 +++++++++++-------- src/upgrades/upgradeable.cairo | 2 +- src/utils/cryptography/nonces.cairo | 10 ++- src/utils/deployments.cairo | 10 ++- src/utils/structs/checkpoint.cairo | 10 +-- 36 files changed, 178 insertions(+), 207 deletions(-) delete mode 100644 src/cairo_project.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index ff13ab1ea..76f22a2b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Bump scarb to v2.7.0-rc.1 (#1025) + ## 0.15.0-rc.0 (2024-07-8) ### Changed @@ -101,10 +105,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - ERC1155Component and ERC1155ReceiverComponent mixins (#941) - ERC721ReceiverComponent documentation (#945) -### Changed - -- Bump scarb to v2.6.3 (#946) - ### Fixed - ERC721ReceiverComponent mixin embeddable implementation name (#945) diff --git a/Scarb.toml b/Scarb.toml index b697f2cc3..1b79be6b4 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -2,8 +2,8 @@ name = "openzeppelin" version = "0.15.0-rc.0" edition = "2023_11" -cairo-version = "2.6.4" -scarb-version = "2.6.5" +cairo-version = "2.7.0-rc.1" +scarb-version = "2.7.0-rc.1" authors = ["OpenZeppelin Community "] description = "OpenZeppelin Contracts written in Cairo for StarkNet, a decentralized ZK Rollup" documentation = "https://docs.openzeppelin.com/contracts-cairo" @@ -13,7 +13,10 @@ license-file = "LICENSE" keywords = ["openzeppelin", "starknet", "cairo", "contracts", "security", "standards"] [dependencies] -starknet = "2.6.4" +starknet = "2.7.0-rc.1" + +[dev-dependencies] +cairo_test = "2.7.0-rc.1" [lib] diff --git a/src/access/accesscontrol/accesscontrol.cairo b/src/access/accesscontrol/accesscontrol.cairo index 3f320d988..891b3a270 100644 --- a/src/access/accesscontrol/accesscontrol.cairo +++ b/src/access/accesscontrol/accesscontrol.cairo @@ -13,11 +13,12 @@ pub mod AccessControlComponent { use openzeppelin::introspection::src5::SRC5Component; use starknet::ContractAddress; use starknet::get_caller_address; + use starknet::storage::Map; #[storage] struct Storage { - AccessControl_role_admin: LegacyMap, - AccessControl_role_member: LegacyMap<(felt252, ContractAddress), bool>, + AccessControl_role_admin: Map, + AccessControl_role_member: Map<(felt252, ContractAddress), bool>, } #[event] @@ -96,7 +97,7 @@ pub mod AccessControlComponent { fn grant_role( ref self: ComponentState, role: felt252, account: ContractAddress ) { - let admin = AccessControl::get_role_admin(@self, role); + let admin = Self::get_role_admin(@self, role); self.assert_only_role(admin); self._grant_role(role, account); } @@ -111,7 +112,7 @@ pub mod AccessControlComponent { fn revoke_role( ref self: ComponentState, role: felt252, account: ContractAddress ) { - let admin = AccessControl::get_role_admin(@self, role); + let admin = Self::get_role_admin(@self, role); self.assert_only_role(admin); self._revoke_role(role, account); } diff --git a/src/account/account.cairo b/src/account/account.cairo index 1dbf6ad56..b63d756d4 100644 --- a/src/account/account.cairo +++ b/src/account/account.cairo @@ -327,8 +327,8 @@ pub mod AccountComponent { /// Validates that `new_owner` accepted the ownership of the contract. /// - /// WARNING: This function assumes that `current_owner` is the current owner of the contract, and - /// does not validate this assumption. + /// WARNING: This function assumes that `current_owner` is the current owner of the + /// contract, and does not validate this assumption. /// /// Requirements: /// diff --git a/src/account/dual_eth_account.cairo b/src/account/dual_eth_account.cairo index 0f2bef2ff..22cd39f9e 100644 --- a/src/account/dual_eth_account.cairo +++ b/src/account/dual_eth_account.cairo @@ -2,7 +2,6 @@ // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (account/dual_eth_account.cairo) use openzeppelin::account::interface::EthPublicKey; -use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde; use openzeppelin::utils::UnwrapAndCast; use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; diff --git a/src/account/eth_account.cairo b/src/account/eth_account.cairo index 65dbb4b7b..61eb038af 100644 --- a/src/account/eth_account.cairo +++ b/src/account/eth_account.cairo @@ -12,7 +12,7 @@ pub mod EthAccountComponent { use core::starknet::secp256_trait::Secp256PointTrait; use openzeppelin::account::interface::EthPublicKey; use openzeppelin::account::interface; - use openzeppelin::account::utils::secp256k1::{Secp256k1PointSerde, Secp256k1PointStorePacking}; + use openzeppelin::account::utils::secp256k1::Secp256k1PointStorePacking; use openzeppelin::account::utils::{MIN_TRANSACTION_VERSION, QUERY_VERSION, QUERY_OFFSET}; use openzeppelin::account::utils::{execute_calls, is_valid_eth_signature}; use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; @@ -333,8 +333,8 @@ pub mod EthAccountComponent { /// Validates that `new_owner` accepted the ownership of the contract. /// - /// WARNING: This function assumes that `current_owner` is the current owner of the contract, and - /// does not validate this assumption. + /// WARNING: This function assumes that `current_owner` is the current owner of the + /// contract, and does not validate this assumption. /// /// Requirements: /// diff --git a/src/account/interface.cairo b/src/account/interface.cairo index b6cd9e320..3b7e8f69d 100644 --- a/src/account/interface.cairo +++ b/src/account/interface.cairo @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts for Cairo v0.15.0-rc.0 (account/interface.cairo) -use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde; use starknet::ContractAddress; use starknet::account::Call; diff --git a/src/account/utils/secp256k1.cairo b/src/account/utils/secp256k1.cairo index 61c93d0b4..fe4f00695 100644 --- a/src/account/utils/secp256k1.cairo +++ b/src/account/utils/secp256k1.cairo @@ -11,7 +11,8 @@ use starknet::storage_access::StorePacking; /// /// The packing is done as follows: /// - First felt contains x.low (x being the x-coordinate of the point). -/// - Second felt contains x.high and the parity bit, at the least significant bits (2 * x.high + parity). +/// - Second felt contains x.high and the parity bit, at the least significant bits (2 * x.high + +/// parity). pub impl Secp256k1PointStorePacking of StorePacking { fn pack(value: Secp256k1Point) -> (felt252, felt252) { let (x, y) = value.get_coordinates().unwrap_syscall(); @@ -38,17 +39,6 @@ pub impl Secp256k1PointStorePacking of StorePacking { - fn serialize(self: @Secp256k1Point, ref output: Array) { - let point = (*self).get_coordinates().unwrap_syscall(); - point.serialize(ref output) - } - fn deserialize(ref serialized: Span) -> Option { - let (x, y) = Serde::<(u256, u256)>::deserialize(ref serialized)?; - Secp256Trait::secp256_ec_new_syscall(x, y).unwrap_syscall() - } -} - pub(crate) impl Secp256k1PointPartialEq of PartialEq { #[inline(always)] fn eq(lhs: @Secp256k1Point, rhs: @Secp256k1Point) -> bool { diff --git a/src/cairo_project.toml b/src/cairo_project.toml deleted file mode 100644 index badca57cd..000000000 --- a/src/cairo_project.toml +++ /dev/null @@ -1,2 +0,0 @@ -[crate_roots] -openzeppelin = "." diff --git a/src/governance/utils/interfaces/votes.cairo b/src/governance/utils/interfaces/votes.cairo index 44188130a..d55c481c2 100644 --- a/src/governance/utils/interfaces/votes.cairo +++ b/src/governance/utils/interfaces/votes.cairo @@ -11,9 +11,10 @@ pub trait IVotes { /// Returns the total supply of votes available at a specific moment in the past. /// - /// NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes. - /// Votes that have not been delegated are still part of total supply, even though they would not participate in a - /// vote. + /// NOTE: This value is the sum of all available votes, which is not necessarily the sum of all + /// delegated votes. + /// Votes that have not been delegated are still part of total supply, even though they would + /// not participate in a vote. fn get_past_total_supply(self: @TState, timepoint: u64) -> u256; /// Returns the delegate that `account` has chosen. diff --git a/src/introspection/src5.cairo b/src/introspection/src5.cairo index f550feb9c..530fb73b2 100644 --- a/src/introspection/src5.cairo +++ b/src/introspection/src5.cairo @@ -7,10 +7,11 @@ #[starknet::component] pub mod SRC5Component { use openzeppelin::introspection::interface; + use starknet::storage::Map; #[storage] struct Storage { - SRC5_supported_interfaces: LegacyMap + SRC5_supported_interfaces: Map } pub mod Errors { diff --git a/src/presets/account.cairo b/src/presets/account.cairo index 05b5bc2da..93cb2b5ef 100644 --- a/src/presets/account.cairo +++ b/src/presets/account.cairo @@ -3,7 +3,8 @@ /// # Account Preset /// -/// OpenZeppelin's upgradeable account which can change its public key and declare, deploy, or call contracts. +/// OpenZeppelin's upgradeable account which can change its public key and declare, deploy, or call +/// contracts. #[starknet::contract(account)] pub(crate) mod AccountUpgradeable { use openzeppelin::account::AccountComponent; diff --git a/src/presets/eth_account.cairo b/src/presets/eth_account.cairo index 2c1e8ea3c..97bdbc8b4 100644 --- a/src/presets/eth_account.cairo +++ b/src/presets/eth_account.cairo @@ -9,7 +9,6 @@ pub(crate) mod EthAccountUpgradeable { use openzeppelin::account::EthAccountComponent; use openzeppelin::account::interface::EthPublicKey; - use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde; use openzeppelin::introspection::src5::SRC5Component; use openzeppelin::upgrades::UpgradeableComponent; use openzeppelin::upgrades::interface::IUpgradeable; diff --git a/src/presets/interfaces/eth_account.cairo b/src/presets/interfaces/eth_account.cairo index 9ee9ad22c..ab9af2f69 100644 --- a/src/presets/interfaces/eth_account.cairo +++ b/src/presets/interfaces/eth_account.cairo @@ -1,5 +1,4 @@ use openzeppelin::account::interface::EthPublicKey; -use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde; use starknet::account::Call; use starknet::{ContractAddress, ClassHash}; diff --git a/src/security/reentrancyguard.cairo b/src/security/reentrancyguard.cairo index 31ff47d32..994e71762 100644 --- a/src/security/reentrancyguard.cairo +++ b/src/security/reentrancyguard.cairo @@ -22,7 +22,8 @@ pub mod ReentrancyGuardComponent { pub impl InternalImpl< TContractState, +HasComponent > of InternalTrait { - /// Prevents a contract's function from calling itself or another protected function, directly or indirectly. + /// Prevents a contract's function from calling itself or another protected function, + /// directly or indirectly. fn start(ref self: ComponentState) { assert(!self.ReentrancyGuard_entered.read(), Errors::REENTRANT_CALL); self.ReentrancyGuard_entered.write(true); diff --git a/src/tests/access/test_ownable.cairo b/src/tests/access/test_ownable.cairo index ea4b97c74..354c96fc4 100644 --- a/src/tests/access/test_ownable.cairo +++ b/src/tests/access/test_ownable.cairo @@ -5,7 +5,6 @@ use openzeppelin::access::ownable::interface::{IOwnable, IOwnableCamelOnly}; use openzeppelin::tests::mocks::ownable_mocks::DualCaseOwnableMock; use openzeppelin::tests::utils::constants::{ZERO, OTHER, OWNER}; use openzeppelin::tests::utils; -use starknet::storage::StorageMemberAccessTrait; use starknet::testing; use super::common::assert_only_event_ownership_transferred; diff --git a/src/tests/access/test_ownable_twostep.cairo b/src/tests/access/test_ownable_twostep.cairo index 0b300ddc4..86a3120a6 100644 --- a/src/tests/access/test_ownable_twostep.cairo +++ b/src/tests/access/test_ownable_twostep.cairo @@ -8,7 +8,6 @@ use openzeppelin::tests::utils::constants::{ZERO, OWNER, OTHER, NEW_OWNER}; use openzeppelin::tests::utils; use openzeppelin::utils::serde::SerializedAppend; use starknet::ContractAddress; -use starknet::storage::StorageMemberAccessTrait; use starknet::testing; use super::common::assert_only_event_ownership_transferred; diff --git a/src/tests/account/ethereum/test_dual_eth_account.cairo b/src/tests/account/ethereum/test_dual_eth_account.cairo index b627724d5..6307f1781 100644 --- a/src/tests/account/ethereum/test_dual_eth_account.cairo +++ b/src/tests/account/ethereum/test_dual_eth_account.cairo @@ -1,8 +1,6 @@ use openzeppelin::account::dual_eth_account::{DualCaseEthAccountABI, DualCaseEthAccount}; use openzeppelin::account::interface::{EthAccountABIDispatcherTrait, EthAccountABIDispatcher}; -use openzeppelin::account::utils::secp256k1::{ - DebugSecp256k1Point, Secp256k1PointPartialEq, Secp256k1PointSerde -}; +use openzeppelin::account::utils::secp256k1::{DebugSecp256k1Point, Secp256k1PointPartialEq}; use openzeppelin::account::utils::signature::EthSignature; use openzeppelin::introspection::interface::ISRC5_ID; use openzeppelin::tests::mocks::eth_account_mocks::{ @@ -230,7 +228,7 @@ fn test_dual_isValidSignature_exists_and_panics() { fn get_accept_ownership_signature_snake() -> Span { let mut output = array![]; - // 0x03e8d3aa715dc5fc3b93c7572df7d6f227a6aad93a77873db3308b30897eee53 = + // 0x061bf2fc78c9b412089e2833cc7a503be80949195280623eb73aa50a8321bb30 = // PoseidonTrait::new() // .update_with('StarkNet Message') // .update_with('accept_ownership') @@ -243,10 +241,10 @@ fn get_accept_ownership_signature_snake() -> Span { // - public_key: // r: 0x829307f82a1883c2414503ba85fc85037f22c6fc6f80910801f6b01a4131da1e // s: 0x2a23f7bddf3715d11767b1247eccc68c89e11b926e2615268db6ad1af8d8da96 - // - msg_hash: 0x03e8d3aa715dc5fc3b93c7572df7d6f227a6aad93a77873db3308b30897eee53 + // - msg_hash: 0x061bf2fc78c9b412089e2833cc7a503be80949195280623eb73aa50a8321bb30 EthSignature { - r: 0x7e1ff13cbdf03e92125a69cb1e4ad94f2178720d156df3827c8d3172484fbfd8, - s: 0x0def4eb71f21bc623c0ca896cb3356cee12504da7b19021d3253d433366e0a3e, + r: 0x09128734fb9b787e4c512798dd4c1ead152f390d02f5859a5274298a050e5f7c, + s: 0x2b4ce3c0c5b7f3d8e3954254131593f0b3c1ace654d36ec9a90338cfc3d7cabb, } .serialize(ref output); @@ -256,7 +254,7 @@ fn get_accept_ownership_signature_snake() -> Span { fn get_accept_ownership_signature_camel() -> Span { let mut output = array![]; - // 0x048d4c831924c90963645d7473e0954d2ac37c1f20e201ed7c1778942df5d58d = + // 0x071fd050d0433b0301af96d4878de600248060d300f4fc715e57e2cc5739eda7 = // PoseidonTrait::new() // .update_with('StarkNet Message') // .update_with('accept_ownership') @@ -269,10 +267,10 @@ fn get_accept_ownership_signature_camel() -> Span { // - public_key: // r: 0x829307f82a1883c2414503ba85fc85037f22c6fc6f80910801f6b01a4131da1e // s: 0x2a23f7bddf3715d11767b1247eccc68c89e11b926e2615268db6ad1af8d8da96 - // - msg_hash: 0x048d4c831924c90963645d7473e0954d2ac37c1f20e201ed7c1778942df5d58d + // - msg_hash: 0x071fd050d0433b0301af96d4878de600248060d300f4fc715e57e2cc5739eda7 EthSignature { - r: 0x7a0fa1e6bfc6a0b86cdbb9877551a108d42d3de50cb7a516e63fe5a26e5a9c52, - s: 0x3cc64ca8bf6963ae01125f0d932b8780ca0ed1612fb74a84d4f76593e6687b74, + r: 0xcc988a5f4ac1a98a8418b06ce4bf4eeac3fb37aef73fd7a349ea3e8389f030ef, + s: 0x56391a25f7f4c196307d910f72eb4ae62d7976fcdb70ddad9de7bf3e0fcf944a, } .serialize(ref output); diff --git a/src/tests/account/ethereum/test_eth_account.cairo b/src/tests/account/ethereum/test_eth_account.cairo index 8c1a8e8d6..37b77ad87 100644 --- a/src/tests/account/ethereum/test_eth_account.cairo +++ b/src/tests/account/ethereum/test_eth_account.cairo @@ -4,9 +4,7 @@ use openzeppelin::account::EthAccountComponent; use openzeppelin::account::interface::EthPublicKey; use openzeppelin::account::interface::{EthAccountABIDispatcherTrait, EthAccountABIDispatcher}; use openzeppelin::account::interface::{ISRC6, ISRC6_ID}; -use openzeppelin::account::utils::secp256k1::{ - DebugSecp256k1Point, Secp256k1PointPartialEq, Secp256k1PointSerde -}; +use openzeppelin::account::utils::secp256k1::{DebugSecp256k1Point, Secp256k1PointPartialEq}; use openzeppelin::account::utils::signature::EthSignature; use openzeppelin::introspection::interface::{ISRC5, ISRC5_ID}; use openzeppelin::tests::mocks::eth_account_mocks::DualCaseEthAccountMock; diff --git a/src/tests/account/test_secp256k1.cairo b/src/tests/account/test_secp256k1.cairo index 5466eee55..8c7b8117b 100644 --- a/src/tests/account/test_secp256k1.cairo +++ b/src/tests/account/test_secp256k1.cairo @@ -1,6 +1,5 @@ use openzeppelin::account::utils::secp256k1::{ - DebugSecp256k1Point, Secp256k1PointSerde, Secp256k1PointPartialEq, - Secp256k1PointStorePacking as StorePacking + DebugSecp256k1Point, Secp256k1PointPartialEq, Secp256k1PointStorePacking as StorePacking }; use starknet::SyscallResultTrait; use starknet::secp256_trait::{Secp256Trait, Secp256PointTrait}; @@ -65,53 +64,6 @@ fn test_unpack_big_secp256k1_points() { assert_eq!(y, expected_y); } -#[test] -fn test_secp256k1_serialization() { - let (big_point_1, big_point_2) = get_points(); - - let mut serialized_point = array![]; - let mut expected_serialization = array![]; - - // Check point 1 - - big_point_1.serialize(ref serialized_point); - big_point_1.get_coordinates().unwrap_syscall().serialize(ref expected_serialization); - - assert!(serialized_point == expected_serialization); - - // Check point 2 - - big_point_2.serialize(ref serialized_point); - big_point_2.get_coordinates().unwrap_syscall().serialize(ref expected_serialization); - - assert!(serialized_point == expected_serialization); -} - -#[test] -fn test_secp256k1_deserialization() { - let (big_point_1, big_point_2) = get_points(); - - // Check point 1 - - let mut expected_serialization = array![]; - - big_point_1.get_coordinates().unwrap_syscall().serialize(ref expected_serialization); - let mut expected_serialization = expected_serialization.span(); - let deserialized_point = Secp256k1PointSerde::deserialize(ref expected_serialization).unwrap(); - - assert_eq!(big_point_1, deserialized_point); - - // Check point 2 - - let mut expected_serialization = array![]; - - big_point_2.get_coordinates().unwrap_syscall().serialize(ref expected_serialization); - let mut expected_serialization = expected_serialization.span(); - let deserialized_point = Secp256k1PointSerde::deserialize(ref expected_serialization).unwrap(); - - assert_eq!(big_point_2, deserialized_point); -} - #[test] fn test_partial_eq() { let (big_point_1, big_point_2) = get_points(); diff --git a/src/tests/mocks/erc721_receiver_mocks.cairo b/src/tests/mocks/erc721_receiver_mocks.cairo index f496d0a9c..55ca3aebf 100644 --- a/src/tests/mocks/erc721_receiver_mocks.cairo +++ b/src/tests/mocks/erc721_receiver_mocks.cairo @@ -65,7 +65,7 @@ pub(crate) mod DualCaseERC721ReceiverMock { tokenId: u256, data: Span ) -> felt252 { - ExternalTrait::on_erc721_received(self, operator, from, tokenId, data) + Self::on_erc721_received(self, operator, from, tokenId, data) } } } diff --git a/src/tests/mocks/eth_account_mocks.cairo b/src/tests/mocks/eth_account_mocks.cairo index 687e5d68f..24161d3ba 100644 --- a/src/tests/mocks/eth_account_mocks.cairo +++ b/src/tests/mocks/eth_account_mocks.cairo @@ -2,7 +2,6 @@ pub(crate) mod DualCaseEthAccountMock { use openzeppelin::account::EthAccountComponent; use openzeppelin::account::interface::EthPublicKey; - use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde; use openzeppelin::introspection::src5::SRC5Component; component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent); @@ -47,7 +46,6 @@ pub(crate) mod DualCaseEthAccountMock { pub(crate) mod SnakeEthAccountMock { use openzeppelin::account::EthAccountComponent; use openzeppelin::account::interface::EthPublicKey; - use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde; use openzeppelin::introspection::src5::SRC5Component; component!(path: EthAccountComponent, storage: eth_account, event: EthAccountEvent); @@ -88,7 +86,6 @@ pub(crate) mod SnakeEthAccountMock { pub(crate) mod CamelEthAccountMock { use openzeppelin::account::EthAccountComponent; use openzeppelin::account::interface::EthPublicKey; - use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde; use openzeppelin::introspection::src5::SRC5Component; use starknet::account::Call; @@ -151,7 +148,6 @@ pub(crate) mod CamelEthAccountMock { #[starknet::contract] pub(crate) mod SnakeEthAccountPanicMock { use openzeppelin::account::interface::EthPublicKey; - use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde; use starknet::SyscallResultTrait; use starknet::secp256_trait::Secp256Trait; @@ -193,7 +189,6 @@ pub(crate) mod SnakeEthAccountPanicMock { #[starknet::contract] pub(crate) mod CamelEthAccountPanicMock { use openzeppelin::account::interface::EthPublicKey; - use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde; use starknet::SyscallResultTrait; use starknet::secp256_trait::Secp256Trait; diff --git a/src/tests/presets/test_eth_account.cairo b/src/tests/presets/test_eth_account.cairo index b8510958a..4b4633ca7 100644 --- a/src/tests/presets/test_eth_account.cairo +++ b/src/tests/presets/test_eth_account.cairo @@ -1,8 +1,6 @@ use core::num::traits::Zero; use openzeppelin::account::interface::ISRC6_ID; -use openzeppelin::account::utils::secp256k1::{ - DebugSecp256k1Point, Secp256k1PointSerde, Secp256k1PointPartialEq -}; +use openzeppelin::account::utils::secp256k1::{DebugSecp256k1Point, Secp256k1PointPartialEq}; use openzeppelin::account::utils::signature::EthSignature; use openzeppelin::introspection::interface::ISRC5_ID; use openzeppelin::presets::EthAccountUpgradeable; @@ -104,7 +102,7 @@ fn test_constructor() { // #[test] -fn test_public_key_setter_and_getter_2() { +fn test_public_key_setter_and_getter() { let dispatcher = setup_dispatcher(); let new_public_key = NEW_ETH_PUBKEY(); @@ -505,7 +503,7 @@ fn set_contract_and_caller(address: ContractAddress) { fn get_accept_ownership_signature() -> Span { let mut output = array![]; - // 0x054308383e1c733aa36ccf3cc62e3107b6bcb10bafcab39912108c6b52655b4c = + // 0x077ab2f889d044a0a23f30c86151d7b5c6d2adc91fb603b16bb32fd35d3ac07d = // PoseidonTrait::new() // .update_with('StarkNet Message') // .update_with('accept_ownership') @@ -518,10 +516,10 @@ fn get_accept_ownership_signature() -> Span { // - public_key: // r: 0x829307f82a1883c2414503ba85fc85037f22c6fc6f80910801f6b01a4131da1e // s: 0x2a23f7bddf3715d11767b1247eccc68c89e11b926e2615268db6ad1af8d8da96 - // - msg_hash: 0x054308383e1c733aa36ccf3cc62e3107b6bcb10bafcab39912108c6b52655b4c + // - msg_hash: 0x077ab2f889d044a0a23f30c86151d7b5c6d2adc91fb603b16bb32fd35d3ac07d EthSignature { - r: 0xc4de7637e4206e64ddae9261782dad6d3c99eaaede20ff3fb183f751b94ee9ff, - s: 0x77c24e1ad34f5ba0627048f6a11c1e7ee1ddd3b5d518ee4c71ebd5725390f860, + r: 0x518caf844e08000c67ef7f9f56105ae52b9f7532baac1561bbfb4a8fb691ba80, + s: 0x559ce65943263032ff0b5906466cd67fd15f7965c8befc162a276abcd63f7c2c, } .serialize(ref output); diff --git a/src/tests/security/test_reentrancyguard.cairo b/src/tests/security/test_reentrancyguard.cairo index b243b4aa4..02add1645 100644 --- a/src/tests/security/test_reentrancyguard.cairo +++ b/src/tests/security/test_reentrancyguard.cairo @@ -4,7 +4,6 @@ use openzeppelin::tests::mocks::reentrancy_mocks::{ Attacker, ReentrancyMock, IReentrancyMockDispatcher, IReentrancyMockDispatcherTrait }; use openzeppelin::tests::utils; -use starknet::storage::StorageMemberAccessTrait; type ComponentState = ReentrancyGuardComponent::ComponentState; diff --git a/src/tests/token/erc1155/test_dual1155.cairo b/src/tests/token/erc1155/test_dual1155.cairo index 16bfe4bfa..f4c598046 100644 --- a/src/tests/token/erc1155/test_dual1155.cairo +++ b/src/tests/token/erc1155/test_dual1155.cairo @@ -74,10 +74,14 @@ fn setup_erc1155_panic() -> (DualCaseERC1155, DualCaseERC1155) { // #[test] -fn test_dual_uri() { +fn test_snake_target_uri() { let (snake_dispatcher, _, _) = setup_snake(); - let (camel_dispatcher, _, _) = setup_camel(); assert_eq!(snake_dispatcher.uri(TOKEN_ID), "URI"); +} + +#[test] +fn test_camel_target_uri() { + let (camel_dispatcher, _, _) = setup_camel(); assert_eq!(camel_dispatcher.uri(TOKEN_ID), "URI"); } diff --git a/src/tests/token/erc1155/test_erc1155.cairo b/src/tests/token/erc1155/test_erc1155.cairo index 978bc1634..57d2fb3f3 100644 --- a/src/tests/token/erc1155/test_erc1155.cairo +++ b/src/tests/token/erc1155/test_erc1155.cairo @@ -1,5 +1,4 @@ use core::num::traits::Zero; -use core::starknet::storage::StorageMemberAccessTrait; use openzeppelin::introspection::src5::SRC5Component::SRC5Impl; use openzeppelin::introspection; use openzeppelin::tests::mocks::erc1155_mocks::DualCaseERC1155Mock; diff --git a/src/tests/token/erc20/test_erc20_votes.cairo b/src/tests/token/erc20/test_erc20_votes.cairo index e241e891c..907a2c1c2 100644 --- a/src/tests/token/erc20/test_erc20_votes.cairo +++ b/src/tests/token/erc20/test_erc20_votes.cairo @@ -17,7 +17,6 @@ use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::utils::structs::checkpoint::{Checkpoint, Trace, TraceTrait}; use starknet::ContractAddress; use starknet::contract_address_const; -use starknet::storage::{StorageMapMemberAccessTrait, StorageMemberAccessTrait}; use starknet::testing; use super::common::{assert_event_approval, assert_only_event_approval, assert_only_event_transfer}; @@ -298,7 +297,7 @@ fn test_delegate_by_sig_invalid_signature() { #[test] fn test_num_checkpoints() { - let state = setup(); + let state = @setup(); let mut trace = state.ERC20Votes_delegate_checkpoints.read(OWNER()); trace.push('ts1', 0x111); @@ -316,7 +315,7 @@ fn test_num_checkpoints() { #[test] fn test_checkpoints() { - let state = setup(); + let state = @setup(); let mut trace = state.ERC20Votes_delegate_checkpoints.read(OWNER()); trace.push('ts1', 0x111); diff --git a/src/tests/token/erc721/test_erc721.cairo b/src/tests/token/erc721/test_erc721.cairo index 7dd5ae1bf..93cab1e1c 100644 --- a/src/tests/token/erc721/test_erc721.cairo +++ b/src/tests/token/erc721/test_erc721.cairo @@ -23,7 +23,6 @@ use openzeppelin::token::erc721::interface::IERC721; use openzeppelin::token::erc721; use starknet::ContractAddress; use starknet::contract_address_const; -use starknet::storage::StorageMapMemberAccessTrait; use starknet::testing; use super::common::{ diff --git a/src/token/erc1155/erc1155.cairo b/src/token/erc1155/erc1155.cairo index dbbf3b777..f852af2a0 100644 --- a/src/token/erc1155/erc1155.cairo +++ b/src/token/erc1155/erc1155.cairo @@ -21,11 +21,12 @@ pub mod ERC1155Component { use openzeppelin::token::erc1155::interface; use starknet::ContractAddress; use starknet::get_caller_address; + use starknet::storage::Map; #[storage] struct Storage { - ERC1155_balances: LegacyMap<(u256, ContractAddress), u256>, - ERC1155_operator_approvals: LegacyMap<(ContractAddress, ContractAddress), bool>, + ERC1155_balances: Map<(u256, ContractAddress), u256>, + ERC1155_operator_approvals: Map<(ContractAddress, ContractAddress), bool>, ERC1155_uri: ByteArray, } @@ -75,10 +76,11 @@ pub mod ERC1155Component { pub approved: bool } - /// Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI. + /// Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic + /// URI. /// - /// If an `URI` event was emitted for `id`, the standard guarantees that `value` will equal the value - /// returned by `IERC1155MetadataURI::uri`. + /// If an `URI` event was emitted for `id`, the standard guarantees that `value` will equal the + /// value returned by `IERC1155MetadataURI::uri`. /// https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions #[derive(Drop, PartialEq, starknet::Event)] pub struct URI { @@ -158,19 +160,20 @@ pub mod ERC1155Component { break; } batch_balances - .append(ERC1155::balance_of(self, *accounts.at(index), *token_ids.at(index))); + .append(Self::balance_of(self, *accounts.at(index), *token_ids.at(index))); index += 1; }; batch_balances.span() } - /// Transfers ownership of `value` amount of `token_id` from `from` if `to` is either an account or `IERC1155Receiver`. + /// Transfers ownership of `value` amount of `token_id` from `from` if `to` is either an + /// account or `IERC1155Receiver`. /// /// `data` is additional data, it has no specified format and it is passed to `to`. /// - /// WARNING: This function can potentially allow a reentrancy attack when transferring tokens - /// to an untrusted contract, when invoking `on_ERC1155_received` on the receiver. + /// WARNING: This function can potentially allow a reentrancy attack when transferring + /// tokens to an untrusted contract, when invoking `on_ERC1155_received` on the receiver. /// Ensure to follow the checks-effects-interactions pattern and consider employing /// reentrancy guards when interacting with untrusted contracts. /// @@ -179,7 +182,8 @@ pub mod ERC1155Component { /// - Caller is either approved or the `token_id` owner. /// - `from` is not the zero address. /// - `to` is not the zero address. - /// - If `to` refers to a non-account contract, it must implement `IERC1155Receiver::on_ERC1155_received` + /// - If `to` refers to a non-account contract, it must implement + /// `IERC1155Receiver::on_ERC1155_received` /// and return the required magic value. /// /// Emits a `TransferSingle` event. @@ -193,13 +197,14 @@ pub mod ERC1155Component { ) { let token_ids = array![token_id].span(); let values = array![value].span(); - ERC1155::safe_batch_transfer_from(ref self, from, to, token_ids, values, data) + Self::safe_batch_transfer_from(ref self, from, to, token_ids, values, data) } /// Batched version of `safe_transfer_from`. /// - /// WARNING: This function can potentially allow a reentrancy attack when transferring tokens - /// to an untrusted contract, when invoking `on_ERC1155_batch_received` on the receiver. + /// WARNING: This function can potentially allow a reentrancy attack when transferring + /// tokens to an untrusted contract, when invoking `on_ERC1155_batch_received` on the + /// receiver. /// Ensure to follow the checks-effects-interactions pattern and consider employing /// reentrancy guards when interacting with untrusted contracts. /// @@ -209,10 +214,12 @@ pub mod ERC1155Component { /// - `from` is not the zero address. /// - `to` is not the zero address. /// - `token_ids` and `values` must have the same length. - /// - If `to` refers to a non-account contract, it must implement `IERC1155Receiver::on_ERC1155_batch_received` + /// - If `to` refers to a non-account contract, it must implement + /// `IERC1155Receiver::on_ERC1155_batch_received` /// and return the acceptance magic value. /// - /// Emits either a `TransferSingle` or a `TransferBatch` event, depending on the length of the array arguments. + /// Emits either a `TransferSingle` or a `TransferBatch` event, depending on the length of + /// the array arguments. fn safe_batch_transfer_from( ref self: ComponentState, from: starknet::ContractAddress, @@ -226,7 +233,7 @@ pub mod ERC1155Component { let operator = get_caller_address(); if from != operator { - assert(ERC1155::is_approved_for_all(@self, from, operator), Errors::UNAUTHORIZED); + assert(Self::is_approved_for_all(@self, from, operator), Errors::UNAUTHORIZED); } self.update_with_acceptance_check(from, to, token_ids, values, data); @@ -483,7 +490,8 @@ pub mod ERC1155Component { /// Requirements: /// /// - `to` cannot be the zero address. - /// - If `to` refers to a smart contract, it must implement `IERC1155Receiver::on_ERC1155_received` + /// - If `to` refers to a smart contract, it must implement + /// `IERC1155Receiver::on_ERC1155_received` /// and return the acceptance magic value. /// /// Emits a `TransferSingle` event. @@ -507,7 +515,8 @@ pub mod ERC1155Component { /// /// - `to` cannot be the zero address. /// - `token_ids` and `values` must have the same length. - /// - If `to` refers to a smart contract, it must implement `IERC1155Receiver::on_ERC1155_batch_received` + /// - If `to` refers to a smart contract, it must implement + /// `IERC1155Receiver::on_ERC1155_batch_received` /// and return the acceptance magic value. /// /// Emits a `TransferBatch` event. @@ -571,7 +580,8 @@ pub mod ERC1155Component { /// - `to` is either an account contract or supports the `IERC1155Receiver` interface. /// - `token_ids` and `values` must have the same length. /// - /// Emits a `TransferSingle` event if the arrays contain one element, and `TransferBatch` otherwise. + /// Emits a `TransferSingle` event if the arrays contain one element, and `TransferBatch` + /// otherwise. fn update_with_acceptance_check( ref self: ComponentState, from: ContractAddress, @@ -596,7 +606,8 @@ pub mod ERC1155Component { /// /// - `token_ids` and `values` must have the same length. /// - /// Emits a `TransferSingle` event if the arrays contain one element, and `TransferBatch` otherwise. + /// Emits a `TransferSingle` event if the arrays contain one element, and `TransferBatch` + /// otherwise. /// /// NOTE: This function can be extended using the `ERC1155HooksTrait`, to add /// functionality before and/or after the transfer, mint, or burn. diff --git a/src/token/erc20/erc20.cairo b/src/token/erc20/erc20.cairo index b295ea9fe..6d8e0f3cf 100644 --- a/src/token/erc20/erc20.cairo +++ b/src/token/erc20/erc20.cairo @@ -9,7 +9,8 @@ use starknet::ContractAddress; /// non-standard implementations that can be used to create an ERC20 contract. This /// component is agnostic regarding how tokens are created, which means that developers /// must create their own token distribution mechanism. -/// See [the documentation](https://docs.openzeppelin.com/contracts-cairo/0.15.0-rc.0/guides/erc20-supply) +/// See [the documentation] +/// (https://docs.openzeppelin.com/contracts-cairo/0.15.0-rc.0/guides/erc20-supply) /// for examples. #[starknet::component] pub mod ERC20Component { @@ -18,14 +19,15 @@ pub mod ERC20Component { use openzeppelin::token::erc20::interface; use starknet::ContractAddress; use starknet::get_caller_address; + use starknet::storage::Map; #[storage] struct Storage { ERC20_name: ByteArray, ERC20_symbol: ByteArray, ERC20_total_supply: u256, - ERC20_balances: LegacyMap, - ERC20_allowances: LegacyMap<(ContractAddress, ContractAddress), u256>, + ERC20_balances: Map, + ERC20_allowances: Map<(ContractAddress, ContractAddress), u256>, } #[event] @@ -294,7 +296,8 @@ pub mod ERC20Component { TContractState, +HasComponent, impl Hooks: ERC20HooksTrait > of InternalTrait { /// Initializes the contract by setting the token name and symbol. - /// To prevent reinitialization, this should only be used inside of a contract's constructor. + /// To prevent reinitialization, this should only be used inside of a contract's + /// constructor. fn initializer( ref self: ComponentState, name: ByteArray, symbol: ByteArray ) { @@ -330,8 +333,8 @@ pub mod ERC20Component { } - /// Transfers an `amount` of tokens from `from` to `to`, or alternatively mints (or burns) if `from` (or `to`) is - /// the zero address. + /// Transfers an `amount` of tokens from `from` to `to`, or alternatively mints (or burns) + /// if `from` (or `to`) is the zero address. /// /// NOTE: This function can be extended using the `ERC20HooksTrait`, to add /// functionality before and/or after the transfer, mint, or burn. diff --git a/src/token/erc20/extensions/erc20_votes.cairo b/src/token/erc20/extensions/erc20_votes.cairo index b507fe5a3..0a9d2f50b 100644 --- a/src/token/erc20/extensions/erc20_votes.cairo +++ b/src/token/erc20/extensions/erc20_votes.cairo @@ -8,11 +8,12 @@ use starknet::ContractAddress; /// # ERC20Votes Component /// -/// The ERC20Votes component tracks voting units from ERC20 balances, which are a measure of voting power that can be -/// transferred, and provides a system of vote delegation, where an account can delegate its voting units to a sort of -/// "representative" that will pool delegated voting units from different accounts and can then use it to vote in -/// decisions. In fact, voting units MUST be delegated in order to count as actual votes, and an account has to -/// delegate those votes to itself if it wishes to participate in decisions and does not have a trusted representative. +/// The ERC20Votes component tracks voting units from ERC20 balances, which are a measure of voting +/// power that can be transferred, and provides a system of vote delegation, where an account can +/// delegate its voting units to a sort of "representative" that will pool delegated voting units +/// from different accounts and can then use it to vote in decisions. In fact, voting units MUST be +/// delegated in order to count as actual votes, and an account has to delegate those votes to +/// itself if it wishes to participate in decisions and does not have a trusted representative. #[starknet::component] pub mod ERC20VotesComponent { use core::num::traits::Zero; @@ -24,12 +25,13 @@ pub mod ERC20VotesComponent { use openzeppelin::utils::nonces::NoncesComponent; use openzeppelin::utils::structs::checkpoint::{Checkpoint, Trace, TraceTrait}; use starknet::ContractAddress; + use starknet::storage::Map; use super::{Delegation, OffchainMessageHash, SNIP12Metadata}; #[storage] struct Storage { - ERC20Votes_delegatee: LegacyMap, - ERC20Votes_delegate_checkpoints: LegacyMap, + ERC20Votes_delegatee: Map, + ERC20Votes_delegate_checkpoints: Map, ERC20Votes_total_checkpoints: Trace } @@ -101,9 +103,10 @@ pub mod ERC20VotesComponent { /// /// - `timepoint` must be in the past. /// - /// NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes. - /// Votes that have not been delegated are still part of total supply, even though they would not participate in a - /// vote. + /// NOTE: This value is the sum of all available votes, which is not necessarily the sum of + /// all delegated votes. + /// Votes that have not been delegated are still part of total supply, even though they + /// would not participate in a vote. fn get_past_total_supply(self: @ComponentState, timepoint: u64) -> u256 { let current_timepoint = starknet::get_block_timestamp(); assert(timepoint < current_timepoint, Errors::FUTURE_LOOKUP); @@ -127,7 +130,8 @@ pub mod ERC20VotesComponent { self._delegate(sender, delegatee); } - /// Delegates votes from the sender to `delegatee` through a SNIP12 message signature validation. + /// Delegates votes from the sender to `delegatee` through a SNIP12 message signature + /// validation. /// /// Requirements: /// diff --git a/src/token/erc721/erc721.cairo b/src/token/erc721/erc721.cairo index 0ad907cda..476ac76ee 100644 --- a/src/token/erc721/erc721.cairo +++ b/src/token/erc721/erc721.cairo @@ -21,15 +21,16 @@ pub mod ERC721Component { use openzeppelin::token::erc721::interface; use starknet::ContractAddress; use starknet::get_caller_address; + use starknet::storage::Map; #[storage] struct Storage { ERC721_name: ByteArray, ERC721_symbol: ByteArray, - ERC721_owners: LegacyMap, - ERC721_balances: LegacyMap, - ERC721_token_approvals: LegacyMap, - ERC721_operator_approvals: LegacyMap<(ContractAddress, ContractAddress), bool>, + ERC721_owners: Map, + ERC721_balances: Map, + ERC721_token_approvals: Map, + ERC721_operator_approvals: Map<(ContractAddress, ContractAddress), bool>, ERC721_base_uri: ByteArray } @@ -133,11 +134,13 @@ pub mod ERC721Component { self._require_owned(token_id) } - /// Transfers ownership of `token_id` from `from` if `to` is either an account or `IERC721Receiver`. + /// Transfers ownership of `token_id` from `from` if `to` is either an account or + /// `IERC721Receiver`. /// /// `data` is additional data, it has no specified format and it is sent in call to `to`. /// - /// WARNING: This method makes an external call to the recipient contract, which can lead to reentrancy vulnerabilities. + /// WARNING: This method makes an external call to the recipient contract, which can lead to + /// reentrancy vulnerabilities. /// /// Requirements: /// @@ -155,7 +158,7 @@ pub mod ERC721Component { token_id: u256, data: Span ) { - ERC721::transfer_from(ref self, from, to, token_id); + Self::transfer_from(ref self, from, to, token_id); assert( _check_on_erc721_received(from, to, token_id, data), Errors::SAFE_TRANSFER_FAILED ); @@ -163,7 +166,8 @@ pub mod ERC721Component { /// Transfers ownership of `token_id` from `from` to `to`. /// - /// WARNING: This method may lead to the loss of tokens if `to` is not aware of the ERC721 protocol. + /// WARNING: This method may lead to the loss of tokens if `to` is not aware of the ERC721 + /// protocol. /// /// Requirements: /// @@ -181,8 +185,9 @@ pub mod ERC721Component { ) { assert(!to.is_zero(), Errors::INVALID_RECEIVER); - // Setting an "auth" arguments enables the `_is_authorized` check which verifies that the token exists - // (from != 0). Therefore, it is not needed to verify that the return value is not 0 here. + // Setting an "auth" arguments enables the `_is_authorized` check which verifies that + // the token exists (from != 0). Therefore, it is not needed to verify that the return + // value is not 0 here. let previous_owner = self.update(to, token_id, get_caller_address()); assert(from == previous_owner, Errors::INVALID_SENDER); @@ -499,7 +504,8 @@ pub mod ERC721Component { /// /// Internal function without access restriction. /// - /// WARNING: This method may lead to the loss of tokens if `to` is not aware of the ERC721 protocol. + /// WARNING: This method may lead to the loss of tokens if `to` is not aware of the ERC721 + /// protocol. /// /// Requirements: /// @@ -525,7 +531,8 @@ pub mod ERC721Component { /// Mints `token_id` and transfers it to `to`. /// Internal function without access restriction. /// - /// WARNING: This method may lead to the loss of tokens if `to` is not aware of the ERC721 protocol. + /// WARNING: This method may lead to the loss of tokens if `to` is not aware of the ERC721 + /// protocol. /// /// Requirements: /// @@ -541,11 +548,13 @@ pub mod ERC721Component { assert(previous_owner.is_zero(), Errors::ALREADY_MINTED); } - /// Transfers ownership of `token_id` from `from` if `to` is either an account or `IERC721Receiver`. + /// Transfers ownership of `token_id` from `from` if `to` is either an account or + /// `IERC721Receiver`. /// /// `data` is additional data, it has no specified format and it is sent in call to `to`. /// - /// WARNING: This method makes an external call to the recipient contract, which can lead to reentrancy vulnerabilities. + /// WARNING: This method makes an external call to the recipient contract, which can lead to + /// reentrancy vulnerabilities. /// /// Requirements: /// @@ -572,7 +581,8 @@ pub mod ERC721Component { /// /// `data` is additional data, it has no specified format and it is sent in call to `to`. /// - /// WARNING: This method makes an external call to the recipient contract, which can lead to reentrancy vulnerabilities. + /// WARNING: This method makes an external call to the recipient contract, which can lead to + /// reentrancy vulnerabilities. /// /// Requirements: /// @@ -608,11 +618,13 @@ pub mod ERC721Component { assert(!previous_owner.is_zero(), Errors::INVALID_TOKEN_ID); } - /// Transfers `token_id` from its current owner to `to`, or alternatively mints (or burns) if the current owner - /// (or `to`) is the zero address. Returns the owner of the `token_id` before the update. + /// Transfers `token_id` from its current owner to `to`, or alternatively mints (or burns) + /// if the current owner (or `to`) is the zero address. Returns the owner of the `token_id` + /// before the update. /// - /// The `auth` argument is optional. If the value passed is non-zero, then this function will check that - /// `auth` is either the owner of the token, or approved to operate on the token (by the owner). + /// The `auth` argument is optional. If the value passed is non-zero, then this function + /// will check that `auth` is either the owner of the token, or approved to operate on the + /// token (by the owner). /// /// Emits a `Transfer` event. /// @@ -671,8 +683,9 @@ pub mod ERC721Component { /// Approve `to` to operate on `token_id` /// - /// The `auth` argument is optional. If the value passed is non-zero, then this function will check that `auth` is - /// either the owner of the token, or approved to operate on all tokens held by this owner. + /// The `auth` argument is optional. If the value passed is non-zero, then this function + /// will check that `auth` is either the owner of the token, or approved to operate on all + /// tokens held by this owner. /// /// Emits an `Approval` event. fn _approve( @@ -684,10 +697,11 @@ pub mod ERC721Component { self._approve_with_optional_event(to, token_id, auth, true); } - /// Variant of `_approve` with an optional flag to enable or disable the `Approval` event. The event is not - /// emitted in the context of transfers. + /// Variant of `_approve` with an optional flag to enable or disable the `Approval` event. + /// The event is not emitted in the context of transfers. /// - /// WARNING: If `auth` is zero and `emit_event` is false, this function will not check that the token exists. + /// WARNING: If `auth` is zero and `emit_event` is false, this function will not check that + /// the token exists. /// /// Requirements: /// @@ -744,7 +758,8 @@ pub mod ERC721Component { /// Base URI for computing `token_uri`. /// - /// If set, the resulting URI for each token will be the concatenation of the base URI and the token ID. + /// If set, the resulting URI for each token will be the concatenation of the base URI and + /// the token ID. /// Returns an empty `ByteArray` if not set. fn _base_uri(self: @ComponentState) -> ByteArray { self.ERC721_base_uri.read() @@ -753,8 +768,8 @@ pub mod ERC721Component { /// Returns whether `spender` is allowed to manage `owner`'s tokens, or `token_id` in /// particular (ignoring whether it is owned by `owner`). /// - /// WARNING: This function assumes that `owner` is the actual owner of `token_id` and does not verify this - /// assumption. + /// WARNING: This function assumes that `owner` is the actual owner of `token_id` and does + /// not verify this assumption. fn _is_authorized( self: @ComponentState, owner: ContractAddress, @@ -769,7 +784,8 @@ pub mod ERC721Component { || spender == ERC721::get_approved(self, token_id)) } - /// Checks if `spender` can operate on `token_id`, assuming the provided `owner` is the actual owner. + /// Checks if `spender` can operate on `token_id`, assuming the provided `owner` is the + /// actual owner. /// /// Requirements: /// @@ -777,8 +793,8 @@ pub mod ERC721Component { /// - `spender` cannot be the zero address. /// - `spender` must be the owner of `token_id` or be approved to operate on it. /// - /// WARNING: This function assumes that `owner` is the actual owner of `token_id` and does not verify this - /// assumption. + /// WARNING: This function assumes that `owner` is the actual owner of `token_id` and does + /// not verify this assumption. fn _check_authorized( self: @ComponentState, owner: ContractAddress, diff --git a/src/upgrades/upgradeable.cairo b/src/upgrades/upgradeable.cairo index e8d436998..c78d25476 100644 --- a/src/upgrades/upgradeable.cairo +++ b/src/upgrades/upgradeable.cairo @@ -25,7 +25,7 @@ pub mod UpgradeableComponent { pub class_hash: ClassHash } - mod Errors { + pub mod Errors { pub const INVALID_CLASS: felt252 = 'Class hash cannot be zero'; } diff --git a/src/utils/cryptography/nonces.cairo b/src/utils/cryptography/nonces.cairo index cf85c3970..40089d76a 100644 --- a/src/utils/cryptography/nonces.cairo +++ b/src/utils/cryptography/nonces.cairo @@ -5,13 +5,14 @@ pub mod NoncesComponent { use openzeppelin::utils::interfaces::INonces; use starknet::ContractAddress; + use starknet::storage::Map; #[storage] struct Storage { - Nonces_nonces: LegacyMap + Nonces_nonces: Map } - mod Errors { + pub mod Errors { pub const INVALID_NONCE: felt252 = 'Nonces: invalid nonce'; } @@ -31,8 +32,9 @@ pub mod NoncesComponent { > of InternalTrait { /// Consumes a nonce, returns the current value, and increments nonce. fn use_nonce(ref self: ComponentState, owner: ContractAddress) -> felt252 { - // For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be - // decremented or reset. This guarantees that the nonce never overflows. + // For each account, the nonce has an initial value of 0, can only be incremented by + // one, and cannot be decremented or reset. This guarantees that the nonce never + // overflows. let nonce = self.Nonces_nonces.read(owner); self.Nonces_nonces.write(owner, nonce + 1); nonce diff --git a/src/utils/deployments.cairo b/src/utils/deployments.cairo index 16a1f0519..0ca55135c 100644 --- a/src/utils/deployments.cairo +++ b/src/utils/deployments.cairo @@ -15,8 +15,11 @@ const L2_ADDRESS_UPPER_BOUND: felt252 = const CONTRACT_ADDRESS_PREFIX: felt252 = 'STARKNET_CONTRACT_ADDRESS'; /// Returns the contract address from a `deploy_syscall`. -/// `deployer_address` should be the zero address if the deployment is origin-independent (deployed from zero). -/// For more information, see https://docs.starknet.io/documentation/architecture_and_concepts/Smart_Contracts/contract-address/ +/// `deployer_address` should be the zero address if the deployment is origin-independent (deployed +/// from zero). +/// For more information, see +/// +/// https://docs.starknet.io/documentation/architecture_and_concepts/Smart_Contracts/contract-address/ pub fn calculate_contract_address_from_deploy_syscall( salt: felt252, class_hash: ClassHash, @@ -65,7 +68,8 @@ pub struct DeployerInfo { } /// Returns the calculated contract address for contracts deployed through the UDC. -/// Origin-independent deployments (deployed from zero) should pass `Option::None` as `deployer_info`. +/// Origin-independent deployments (deployed from zero) should pass `Option::None` as +/// `deployer_info`. pub fn calculate_contract_address_from_udc( salt: felt252, class_hash: ClassHash, diff --git a/src/utils/structs/checkpoint.cairo b/src/utils/structs/checkpoint.cairo index de07f5d84..c26938dd8 100644 --- a/src/utils/structs/checkpoint.cairo +++ b/src/utils/structs/checkpoint.cairo @@ -112,8 +112,8 @@ pub impl TraceImpl of TraceTrait { #[generate_trait] impl CheckpointImpl of CheckpointTrait { - /// Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint, - /// or by updating the last one. + /// Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a + /// new checkpoint, or by updating the last one. fn _insert(ref self: StorageArray, key: u64, value: u256) -> (u256, u256) { let pos = self.len(); @@ -138,9 +138,9 @@ impl CheckpointImpl of CheckpointTrait { } } - /// Returns the index of the last (most recent) checkpoint with the key lower than or equal to the search key, - /// or `high` if there is none. `low` and `high` define a section where to do the search, with - /// inclusive `low` and exclusive `high`. + /// Returns the index of the last (most recent) checkpoint with the key lower than or equal to + /// the search key, or `high` if there is none. `low` and `high` define a section where to do + /// the search, with inclusive `low` and exclusive `high`. fn _upper_binary_lookup(self: @StorageArray, key: u64, low: u32, high: u32) -> u32 { let mut _low = low; let mut _high = high;