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

Support Cairo 2.5.0 #898

Merged
merged 10 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.4.4"
scarb-version: "2.5.0"
- name: Markdown lint
uses: DavidAnson/markdownlint-cli2-action@5b7c9f74fec47e6b15667b2cc23c63dff11e449e # v9
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Bump scarb to v2.4.4 (#853)
- Bump scarb to v2.5.0 (#898)

## 0.8.1 (2024-01-23)

Expand Down
4 changes: 2 additions & 2 deletions Scarb.toml
Expand Up @@ -2,7 +2,7 @@
name = "openzeppelin"
version = "0.8.1"
edition = "2023_01"
cairo-version = "2.4.4"
cairo-version = "2.5.0"
authors = ["OpenZeppelin Community <maintainers@openzeppelin.org>"]
description = "OpenZeppelin Contracts written in Cairo for StarkNet, a decentralized ZK Rollup"
documentation = "https://docs.openzeppelin.com/contracts-cairo"
Expand All @@ -12,7 +12,7 @@ license-file = "LICENSE"
keywords = ["openzeppelin", "starknet", "cairo", "contracts", "security", "standards"]

[dependencies]
starknet = "2.4.4"
starknet = "2.5.0"

[lib]

Expand Down
10 changes: 5 additions & 5 deletions docs/modules/ROOT/pages/utils/_class_hashes.adoc
@@ -1,11 +1,11 @@
// Version
:class-hash-cairo-version: https://crates.io/crates/cairo-lang-compiler/2.4.4[cairo 2.4.4]
:class-hash-cairo-version: https://crates.io/crates/cairo-lang-compiler/2.5.0[cairo 2.5.0]

// Class Hashes
:account-class-hash: 0x0402765bcede84b1267a9d4658a7737c3c41a8caf6201984c3df95577c2298a3
:eth-account-upgradeable-class-hash: 0x03dda9bcfa854795d91d586b1a4275a68ab1ab185b33a5c00ce647c75875b0ff
:erc20-class-hash: 0x03af5816946625d3d2c94ea451225715784762050eba736f0b0ad9186685bced
:erc721-class-hash: 0x045c96d1b24c3dc060680e4bfd4bdc32161aefe8f8939cd4be3954c5d8688d75
:account-class-hash: 0x07bb7a849957e721ee9e87e9844cba8ba139e87e671d4c34b17e09829b65134c
Copy link
Member

Choose a reason for hiding this comment

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

After merging main the Account hashes changes from using unwrap_syscall instead of unwrap.

I wonder if we shouldn't directly use 2.5.3 in this bump. That would also affect the class hashes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm yeah, might as well use 2.5.3. Will update

:eth-account-upgradeable-class-hash: 0x02f69cdaf102fe171e57d61e290d37da2098c416bcbb4234abe54d6a330a1a93
:erc20-class-hash: 0x05f4f6cf4ddd3ad9f6bb57c74f57c225573a669d6c8e1a5c2b3ba29938df44ab
:erc721-class-hash: 0x0715e41c4869448193a910e74f56b3e7535d2c3ce1849bd5fca2ad411c710bd6

// Presets page
:presets-page: xref:presets.adoc[Sierra class hash]
2 changes: 1 addition & 1 deletion src/account/utils.cairo
Expand Up @@ -28,5 +28,5 @@ fn execute_calls(mut calls: Array<Call>) -> Array<Span<felt252>> {

fn execute_single_call(call: Call) -> Span<felt252> {
let Call{to, selector, calldata } = call;
starknet::call_contract_syscall(to, selector, calldata.span()).unwrap()
starknet::call_contract_syscall(to, selector, calldata).unwrap()
}
2 changes: 1 addition & 1 deletion src/presets/account.cairo
Expand Up @@ -4,7 +4,7 @@
/// # Account Preset
///
/// OpenZeppelin's basic account which can change its public key and declare, deploy, or call contracts.
#[starknet::contract]
#[starknet::contract(account)]
mod Account {
use openzeppelin::account::AccountComponent;
use openzeppelin::introspection::src5::SRC5Component;
Expand Down
4 changes: 2 additions & 2 deletions src/presets/eth_account.cairo
Expand Up @@ -5,7 +5,7 @@
///
/// OpenZeppelin's account which can change its public key and declare,
/// deploy, or call contracts, using Ethereum signing keys.
#[starknet::contract]
#[starknet::contract(account)]
mod EthAccountUpgradeable {
use openzeppelin::account::EthAccountComponent;
use openzeppelin::account::interface::EthPublicKey;
Expand Down Expand Up @@ -68,7 +68,7 @@ mod EthAccountUpgradeable {
self.eth_account.initializer(public_key);
}

#[external(v0)]
#[abi(embed_v0)]
impl UpgradeableImpl of IUpgradeable<ContractState> {
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.eth_account.assert_only_self();
Expand Down
1 change: 0 additions & 1 deletion src/tests/access/test_accesscontrol.cairo
Expand Up @@ -11,7 +11,6 @@ use openzeppelin::tests::mocks::accesscontrol_mocks::DualCaseAccessControlMock;
use openzeppelin::tests::utils::constants::{
ADMIN, AUTHORIZED, OTHER, OTHER_ADMIN, ROLE, OTHER_ROLE, ZERO
};
use openzeppelin::tests::utils::debug::DebugContractAddress;
use openzeppelin::tests::utils;
use starknet::ContractAddress;
use starknet::testing;
Expand Down
1 change: 0 additions & 1 deletion src/tests/access/test_dual_ownable.cairo
Expand Up @@ -8,7 +8,6 @@ use openzeppelin::tests::mocks::ownable_mocks::{
CamelOwnableMock, CamelOwnablePanicMock, SnakeOwnableMock, SnakeOwnablePanicMock
};
use openzeppelin::tests::utils::constants::{OWNER, NEW_OWNER};
use openzeppelin::tests::utils::debug::DebugContractAddress;
use openzeppelin::tests::utils;
use openzeppelin::utils::serde::SerializedAppend;
use starknet::testing::set_contract_address;
Expand Down
1 change: 0 additions & 1 deletion src/tests/access/test_ownable.cairo
Expand Up @@ -4,7 +4,6 @@ use openzeppelin::access::ownable::OwnableComponent;
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::debug::DebugContractAddress;
use openzeppelin::tests::utils;
use starknet::ContractAddress;
use starknet::storage::StorageMemberAccessTrait;
Expand Down
6 changes: 3 additions & 3 deletions src/tests/account/test_account.cairo
Expand Up @@ -245,7 +245,7 @@ fn test_execute_with_version(version: Option<felt252>) {
calldata.append_serde(recipient);
calldata.append_serde(amount);
let call = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata.span()
};
let mut calls = array![];
calls.append(call);
Expand Down Expand Up @@ -334,7 +334,7 @@ fn test_multicall() {
calldata1.append_serde(recipient1);
calldata1.append_serde(amount1);
let call1 = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1.span()
};

// Craft call2
Expand All @@ -343,7 +343,7 @@ fn test_multicall() {
calldata2.append_serde(recipient2);
calldata2.append_serde(amount2);
let call2 = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2.span()
};

// Bundle calls and exeute
Expand Down
2 changes: 1 addition & 1 deletion src/tests/account/test_dual_account.cairo
Expand Up @@ -135,7 +135,7 @@ fn test_dual_is_valid_signature_exists_and_panics() {

#[test]
fn test_dual_supports_interface() {
let (snake_dispatcher, target) = setup_snake();
let (snake_dispatcher, _) = setup_snake();
let supports_isrc5 = snake_dispatcher.supports_interface(ISRC5_ID);
assert!(supports_isrc5);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/account/test_dual_eth_account.cairo
Expand Up @@ -143,7 +143,7 @@ fn test_dual_is_valid_signature_exists_and_panics() {

#[test]
fn test_dual_supports_interface() {
let (snake_dispatcher, target) = setup_snake();
let (snake_dispatcher, _) = setup_snake();
assert!(snake_dispatcher.supports_interface(ISRC5_ID), "Should implement ISRC5");
}

Expand Down
6 changes: 3 additions & 3 deletions src/tests/account/test_eth_account.cairo
Expand Up @@ -276,7 +276,7 @@ fn test_execute_with_version(version: Option<felt252>) {
calldata.append_serde(recipient);
calldata.append_serde(amount);
let call = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata.span()
};
let mut calls = array![];
calls.append(call);
Expand Down Expand Up @@ -349,7 +349,7 @@ fn test_multicall() {
calldata1.append_serde(recipient1);
calldata1.append_serde(amount1);
let call1 = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1.span()
};

// Craft call2
Expand All @@ -358,7 +358,7 @@ fn test_multicall() {
calldata2.append_serde(recipient2);
calldata2.append_serde(amount2);
let call2 = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2.span()
};

// Bundle calls and exeute
Expand Down
7 changes: 2 additions & 5 deletions src/tests/account/test_secp256k1.cairo
Expand Up @@ -40,7 +40,6 @@ fn test_pack_big_secp256k1_points() {
#[test]
fn test_unpack_big_secp256k1_points() {
let (big_point_1, big_point_2) = get_points();
let curve_size = Secp256k1Impl::get_curve_size();

// Check point 1

Expand All @@ -54,18 +53,17 @@ fn test_unpack_big_secp256k1_points() {

// Check point 2

let (expected_x, expected_y) = big_point_2.get_coordinates().unwrap();
let (expected_x, _) = big_point_2.get_coordinates().unwrap();

let (xlow, xhigh_and_parity) = StorePacking::pack(big_point_2);
let (x, y) = StorePacking::unpack((xlow, xhigh_and_parity)).get_coordinates().unwrap();
let (x, _) = StorePacking::unpack((xlow, xhigh_and_parity)).get_coordinates().unwrap();

assert_eq!(x, expected_x);
}

#[test]
fn test_secp256k1_serialization() {
let (big_point_1, big_point_2) = get_points();
let curve_size = Secp256k1Impl::get_curve_size();
Copy link
Contributor

Choose a reason for hiding this comment

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

huh

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

2.5 issues warnings for unused variables

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, i was a bit more surprised of the unused line, which i believe made it through the audit


let mut serialized_point = array![];
let mut expected_serialization = array![];
Expand All @@ -88,7 +86,6 @@ fn test_secp256k1_serialization() {
#[test]
fn test_secp256k1_deserialization() {
let (big_point_1, big_point_2) = get_points();
let curve_size = Secp256k1Impl::get_curve_size();

// Check point 1

Expand Down
10 changes: 6 additions & 4 deletions src/tests/mocks/account_mocks.cairo
@@ -1,4 +1,4 @@
#[starknet::contract]
#[starknet::contract(account)]
mod DualCaseAccountMock {
use openzeppelin::account::AccountComponent;
use openzeppelin::introspection::src5::SRC5Component;
Expand Down Expand Up @@ -45,7 +45,7 @@ mod DualCaseAccountMock {
}
}

#[starknet::contract]
#[starknet::contract(account)]
mod SnakeAccountMock {
use openzeppelin::account::AccountComponent;
use openzeppelin::introspection::src5::SRC5Component;
Expand Down Expand Up @@ -88,7 +88,7 @@ mod SnakeAccountMock {
}
}

#[starknet::contract]
#[starknet::contract(account)]
mod CamelAccountMock {
use openzeppelin::account::AccountComponent;
use openzeppelin::introspection::src5::SRC5Component;
Expand Down Expand Up @@ -132,13 +132,15 @@ mod CamelAccountMock {
self.account.initializer(publicKey);
}

#[external(v0)]
#[abi(per_item)]
#[generate_trait]
impl ExternalImpl of ExternalTrait {
#[external(v0)]
fn __execute__(self: @ContractState, mut calls: Array<Call>) -> Array<Span<felt252>> {
self.account.__execute__(calls)
}

#[external(v0)]
fn __validate__(self: @ContractState, mut calls: Array<Call>) -> felt252 {
self.account.__validate__(calls)
}
Expand Down