Skip to content

Commit

Permalink
Support Cairo 2.5.0 (#898)
Browse files Browse the repository at this point in the history
* fix breaking changes

* fix impls

* fix annotation

* update class hashes

* add item to changelog

* update cairo version in docs

* add PR number in changelog

* bump to scarb 2.5.3

* update hashes
  • Loading branch information
andrew-fleming committed Feb 6, 2024
1 parent a990d3d commit a34025c
Show file tree
Hide file tree
Showing 31 changed files with 85 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
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.3"
- name: Markdown lint
uses: DavidAnson/markdownlint-cli2-action@5b7c9f74fec47e6b15667b2cc23c63dff11e449e # v9
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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.3 (#898)

## 0.8.1 (2024-01-23)

Expand Down
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "openzeppelin"
version = "0.8.1"
edition = "2023_01"
cairo-version = "2.4.4"
cairo-version = "2.5.3"
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.3"

[lib]

Expand Down
10 changes: 5 additions & 5 deletions docs/modules/ROOT/pages/utils/_class_hashes.adoc
Original file line number Diff line number Diff line change
@@ -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.3[cairo 2.5.3]

// Class Hashes
:account-class-hash: 0x0402765bcede84b1267a9d4658a7737c3c41a8caf6201984c3df95577c2298a3
:eth-account-upgradeable-class-hash: 0x03dda9bcfa854795d91d586b1a4275a68ab1ab185b33a5c00ce647c75875b0ff
:erc20-class-hash: 0x03af5816946625d3d2c94ea451225715784762050eba736f0b0ad9186685bced
:erc721-class-hash: 0x045c96d1b24c3dc060680e4bfd4bdc32161aefe8f8939cd4be3954c5d8688d75
:account-class-hash: 0x01148c31dfa5c4708a4e9cf1eb0fd3d4d8ad9ccf09d0232cd6b56bee64a7de9d
:eth-account-upgradeable-class-hash: 0x023e416842ca96b1f7067693892ed00881d97a4b0d9a4c793b75cb887944d98d
:erc20-class-hash: 0x03dcc315f11192ff18648dcd8306f324aa7cf11f2f001ef9fd53afe730efb71b
:erc721-class-hash: 0x06b7c9efc5467c621f58d87995302d940a39b7217b5c5a7a55555c97cabf5cd8

// Presets page
:presets-page: xref:presets.adoc[Sierra class hash]
2 changes: 1 addition & 1 deletion src/account/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,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_syscall()
starknet::call_contract_syscall(to, selector, calldata).unwrap_syscall()
}
2 changes: 1 addition & 1 deletion src/presets/account.cairo
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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();

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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a34025c

Please sign in to comment.