Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump cairo to 2.7.0-rc.1 #1025

Merged
merged 8 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.14.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
11 changes: 6 additions & 5 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>,
pub struct Storage {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this public?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had an issue using the Storage in a preset in the migration to the new edition IIRC, but it seems it works without it at least now. I will remove the public key from the components storage struct.

Copy link
Member Author

Choose a reason for hiding this comment

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

They moved it into an edition it seems.

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
2 changes: 1 addition & 1 deletion src/access/ownable/ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod OwnableComponent {
use starknet::get_caller_address;

#[storage]
struct Storage {
pub struct Storage {
Ownable_owner: ContractAddress,
Ownable_pending_owner: ContractAddress
}
Expand Down
6 changes: 3 additions & 3 deletions src/account/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub mod AccountComponent {
use starknet::get_tx_info;

#[storage]
struct Storage {
pub struct Storage {
Account_public_key: felt252
}

Expand Down 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.
Comment on lines -330 to +331
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do like that the formatter enforces this

///
/// 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.14.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
8 changes: 4 additions & 4 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 All @@ -25,7 +25,7 @@ pub mod EthAccountComponent {
use starknet::get_tx_info;

#[storage]
struct Storage {
pub struct Storage {
EthAccount_public_key: EthPublicKey
}

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.14.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
5 changes: 3 additions & 2 deletions 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>
pub struct Storage {
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
2 changes: 1 addition & 1 deletion src/security/initializable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod InitializableComponent {
use openzeppelin::security::interface::IInitializable;

#[storage]
struct Storage {
pub struct Storage {
Initializable_initialized: bool
}

Expand Down
2 changes: 1 addition & 1 deletion src/security/pausable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod PausableComponent {
use starknet::get_caller_address;

#[storage]
struct Storage {
pub struct Storage {
Pausable_paused: bool
}

Expand Down
5 changes: 3 additions & 2 deletions src/security/reentrancyguard.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod ReentrancyGuardComponent {
use starknet::get_caller_address;

#[storage]
struct Storage {
pub struct Storage {
ReentrancyGuard_entered: bool
}

Expand All @@ -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
10 changes: 6 additions & 4 deletions src/tests/access.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
pub(crate) mod common;

mod test_accesscontrol;
mod test_dual_accesscontrol;
mod test_dual_ownable;
// mod test_accesscontrol;
// mod test_dual_accesscontrol;
// mod test_dual_ownable;
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
mod test_ownable;
mod test_ownable_twostep;
// mod test_ownable_twostep;

ericnordelo marked this conversation as resolved.
Show resolved Hide resolved

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
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
7 changes: 3 additions & 4 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 @@ -97,7 +96,7 @@ fn test_secp256k1_deserialization() {

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();
let deserialized_point = Serde::deserialize(ref expected_serialization).unwrap();
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved

assert_eq!(big_point_1, deserialized_point);

Expand All @@ -107,7 +106,7 @@ fn test_secp256k1_deserialization() {

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();
let deserialized_point = Serde::deserialize(ref expected_serialization).unwrap();

assert_eq!(big_point_2, deserialized_point);
}
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
Loading