Skip to content

Commit

Permalink
Bump cairo to 2.7.0-rc.1 (OpenZeppelin#1025)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ericnordelo authored Jul 11, 2024
1 parent 6869190 commit 232c673
Show file tree
Hide file tree
Showing 36 changed files with 178 additions and 207 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
description = "OpenZeppelin Contracts written in Cairo for StarkNet, a decentralized ZK Rollup"
documentation = "https://docs.openzeppelin.com/contracts-cairo"
Expand All @@ -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]

Expand Down
9 changes: 5 additions & 4 deletions src/access/accesscontrol/accesscontrol.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<felt252, felt252>,
AccessControl_role_member: LegacyMap<(felt252, ContractAddress), bool>,
AccessControl_role_admin: Map<felt252, felt252>,
AccessControl_role_member: Map<(felt252, ContractAddress), bool>,
}

#[event]
Expand Down Expand Up @@ -96,7 +97,7 @@ pub mod AccessControlComponent {
fn grant_role(
ref self: ComponentState<TContractState>, 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);
}
Expand All @@ -111,7 +112,7 @@ pub mod AccessControlComponent {
fn revoke_role(
ref self: ComponentState<TContractState>, 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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/account/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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:
///
Expand Down
1 change: 0 additions & 1 deletion src/account/dual_eth_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/account/eth_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
///
Expand Down
1 change: 0 additions & 1 deletion src/account/interface.cairo
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
14 changes: 2 additions & 12 deletions src/account/utils/secp256k1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<Secp256k1Point, (felt252, felt252)> {
fn pack(value: Secp256k1Point) -> (felt252, felt252) {
let (x, y) = value.get_coordinates().unwrap_syscall();
Expand All @@ -38,17 +39,6 @@ pub impl Secp256k1PointStorePacking of StorePacking<Secp256k1Point, (felt252, fe
}
}

pub impl Secp256k1PointSerde of Serde<Secp256k1Point> {
fn serialize(self: @Secp256k1Point, ref output: Array<felt252>) {
let point = (*self).get_coordinates().unwrap_syscall();
point.serialize(ref output)
}
fn deserialize(ref serialized: Span<felt252>) -> Option<Secp256k1Point> {
let (x, y) = Serde::<(u256, u256)>::deserialize(ref serialized)?;
Secp256Trait::secp256_ec_new_syscall(x, y).unwrap_syscall()
}
}

pub(crate) impl Secp256k1PointPartialEq of PartialEq<Secp256k1Point> {
#[inline(always)]
fn eq(lhs: @Secp256k1Point, rhs: @Secp256k1Point) -> bool {
Expand Down
2 changes: 0 additions & 2 deletions src/cairo_project.toml

This file was deleted.

7 changes: 4 additions & 3 deletions src/governance/utils/interfaces/votes.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ pub trait IVotes<TState> {

/// 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.
Expand Down
3 changes: 2 additions & 1 deletion src/introspection/src5.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#[starknet::component]
pub mod SRC5Component {
use openzeppelin::introspection::interface;
use starknet::storage::Map;

#[storage]
struct Storage {
SRC5_supported_interfaces: LegacyMap<felt252, bool>
SRC5_supported_interfaces: Map<felt252, bool>
}

pub mod Errors {
Expand Down
3 changes: 2 additions & 1 deletion src/presets/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/presets/eth_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/presets/interfaces/eth_account.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use openzeppelin::account::interface::EthPublicKey;
use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde;
use starknet::account::Call;
use starknet::{ContractAddress, ClassHash};

Expand Down
3 changes: 2 additions & 1 deletion src/security/reentrancyguard.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ pub mod ReentrancyGuardComponent {
pub impl InternalImpl<
TContractState, +HasComponent<TContractState>
> of InternalTrait<TContractState> {
/// 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<TContractState>) {
assert(!self.ReentrancyGuard_entered.read(), Errors::REENTRANT_CALL);
self.ReentrancyGuard_entered.write(true);
Expand Down
1 change: 0 additions & 1 deletion src/tests/access/test_ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/tests/access/test_ownable_twostep.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 9 additions & 11 deletions src/tests/account/ethereum/test_dual_eth_account.cairo
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -230,7 +228,7 @@ fn test_dual_isValidSignature_exists_and_panics() {
fn get_accept_ownership_signature_snake() -> Span<felt252> {
let mut output = array![];

// 0x03e8d3aa715dc5fc3b93c7572df7d6f227a6aad93a77873db3308b30897eee53 =
// 0x061bf2fc78c9b412089e2833cc7a503be80949195280623eb73aa50a8321bb30 =
// PoseidonTrait::new()
// .update_with('StarkNet Message')
// .update_with('accept_ownership')
Expand All @@ -243,10 +241,10 @@ fn get_accept_ownership_signature_snake() -> Span<felt252> {
// - public_key:
// r: 0x829307f82a1883c2414503ba85fc85037f22c6fc6f80910801f6b01a4131da1e
// s: 0x2a23f7bddf3715d11767b1247eccc68c89e11b926e2615268db6ad1af8d8da96
// - msg_hash: 0x03e8d3aa715dc5fc3b93c7572df7d6f227a6aad93a77873db3308b30897eee53
// - msg_hash: 0x061bf2fc78c9b412089e2833cc7a503be80949195280623eb73aa50a8321bb30
EthSignature {
r: 0x7e1ff13cbdf03e92125a69cb1e4ad94f2178720d156df3827c8d3172484fbfd8,
s: 0x0def4eb71f21bc623c0ca896cb3356cee12504da7b19021d3253d433366e0a3e,
r: 0x09128734fb9b787e4c512798dd4c1ead152f390d02f5859a5274298a050e5f7c,
s: 0x2b4ce3c0c5b7f3d8e3954254131593f0b3c1ace654d36ec9a90338cfc3d7cabb,
}
.serialize(ref output);

Expand All @@ -256,7 +254,7 @@ fn get_accept_ownership_signature_snake() -> Span<felt252> {
fn get_accept_ownership_signature_camel() -> Span<felt252> {
let mut output = array![];

// 0x048d4c831924c90963645d7473e0954d2ac37c1f20e201ed7c1778942df5d58d =
// 0x071fd050d0433b0301af96d4878de600248060d300f4fc715e57e2cc5739eda7 =
// PoseidonTrait::new()
// .update_with('StarkNet Message')
// .update_with('accept_ownership')
Expand All @@ -269,10 +267,10 @@ fn get_accept_ownership_signature_camel() -> Span<felt252> {
// - public_key:
// r: 0x829307f82a1883c2414503ba85fc85037f22c6fc6f80910801f6b01a4131da1e
// s: 0x2a23f7bddf3715d11767b1247eccc68c89e11b926e2615268db6ad1af8d8da96
// - msg_hash: 0x048d4c831924c90963645d7473e0954d2ac37c1f20e201ed7c1778942df5d58d
// - msg_hash: 0x071fd050d0433b0301af96d4878de600248060d300f4fc715e57e2cc5739eda7
EthSignature {
r: 0x7a0fa1e6bfc6a0b86cdbb9877551a108d42d3de50cb7a516e63fe5a26e5a9c52,
s: 0x3cc64ca8bf6963ae01125f0d932b8780ca0ed1612fb74a84d4f76593e6687b74,
r: 0xcc988a5f4ac1a98a8418b06ce4bf4eeac3fb37aef73fd7a349ea3e8389f030ef,
s: 0x56391a25f7f4c196307d910f72eb4ae62d7976fcdb70ddad9de7bf3e0fcf944a,
}
.serialize(ref output);

Expand Down
4 changes: 1 addition & 3 deletions src/tests/account/ethereum/test_eth_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
50 changes: 1 addition & 49 deletions src/tests/account/test_secp256k1.cairo
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/tests/mocks/erc721_receiver_mocks.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub(crate) mod DualCaseERC721ReceiverMock {
tokenId: u256,
data: Span<felt252>
) -> felt252 {
ExternalTrait::on_erc721_received(self, operator, from, tokenId, data)
Self::on_erc721_received(self, operator, from, tokenId, data)
}
}
}
Expand Down
Loading

0 comments on commit 232c673

Please sign in to comment.