Skip to content

Commit

Permalink
Sanitizing for release. (#736)
Browse files Browse the repository at this point in the history
* refactor: sanitizing

* feat: sanitizing

* feat: apply review updates

* feat: apply review updates
  • Loading branch information
ericnordelo authored Sep 27, 2023
1 parent 74eb4e8 commit 420f320
Show file tree
Hide file tree
Showing 38 changed files with 51 additions and 231 deletions.
9 changes: 4 additions & 5 deletions src/access/accesscontrol/accesscontrol.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod AccessControl {
use openzeppelin::introspection::interface::ISRC5;
use openzeppelin::introspection::interface::ISRC5Camel;
use openzeppelin::introspection::src5::SRC5;
use openzeppelin::introspection::src5::unsafe_state as src5_state;
use starknet::ContractAddress;
use starknet::get_caller_address;

Expand Down Expand Up @@ -66,16 +67,14 @@ mod AccessControl {
#[external(v0)]
impl SRC5Impl of ISRC5<ContractState> {
fn supports_interface(self: @ContractState, interface_id: felt252) -> bool {
let unsafe_state = SRC5::unsafe_new_contract_state();
SRC5::SRC5Impl::supports_interface(@unsafe_state, interface_id)
SRC5::SRC5Impl::supports_interface(@src5_state(), interface_id)
}
}

#[external(v0)]
impl SRC5CamelImpl of ISRC5Camel<ContractState> {
fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool {
let unsafe_state = SRC5::unsafe_new_contract_state();
SRC5::SRC5CamelImpl::supportsInterface(@unsafe_state, interfaceId)
SRC5::SRC5CamelImpl::supportsInterface(@src5_state(), interfaceId)
}
}

Expand Down Expand Up @@ -138,7 +137,7 @@ mod AccessControl {
#[generate_trait]
impl InternalImpl of InternalTrait {
fn initializer(ref self: ContractState) {
let mut unsafe_state = SRC5::unsafe_new_contract_state();
let mut unsafe_state = src5_state();
SRC5::InternalImpl::register_interface(ref unsafe_state, interface::IACCESSCONTROL_ID);
}

Expand Down
2 changes: 0 additions & 2 deletions src/access/accesscontrol/dual_accesscontrol.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.7.0 (access/accesscontrol/dual_accesscontrol.cairo)

use array::ArrayTrait;

use openzeppelin::utils::Felt252TryIntoBool;
use openzeppelin::utils::UnwrapAndCast;
use openzeppelin::utils::selectors;
Expand Down
6 changes: 0 additions & 6 deletions src/access/ownable/dual_ownable.cairo
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.7.0 (access/ownable/dual_ownable.cairo)

use array::ArrayTrait;
use array::SpanTrait;
use core::result::ResultTrait;

use openzeppelin::utils::Felt252TryIntoBool;
use openzeppelin::utils::UnwrapAndCast;
use openzeppelin::utils::selectors;
use openzeppelin::utils::serde::SerializedAppend;
use openzeppelin::utils::try_selector_with_fallback;
use option::OptionTrait;
use starknet::ContractAddress;
use starknet::Felt252TryIntoContractAddress;
use starknet::SyscallResultTrait;
use starknet::call_contract_syscall;
use traits::TryInto;

#[derive(Copy, Drop)]
struct DualCaseOwnable {
Expand Down
1 change: 0 additions & 1 deletion src/access/ownable/ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod Ownable {
use openzeppelin::access::ownable::interface;
use starknet::ContractAddress;
use starknet::get_caller_address;
use zeroable::Zeroable;

#[storage]
struct Storage {
Expand Down
2 changes: 0 additions & 2 deletions src/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ mod dual_account;
mod interface;

use account::Account;
use account::QUERY_VERSION;
use account::TRANSACTION_VERSION;
use interface::AccountABIDispatcher;
use interface::AccountABIDispatcherTrait;
use interface::AccountCamelABIDispatcher;
Expand Down
33 changes: 8 additions & 25 deletions src/account/account.cairo
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.7.0 (account/account.cairo)

use array::ArrayTrait;
use array::SpanTrait;
use option::OptionTrait;
use serde::Serde;
use starknet::ContractAddress;
use starknet::account::Call;

const TRANSACTION_VERSION: felt252 = 1;

// 2**128 + TRANSACTION_VERSION
const QUERY_VERSION: felt252 = 340282366920938463463374607431768211457;

trait PublicKeyTrait<TState> {
fn set_public_key(ref self: TState, new_public_key: felt252);
fn get_public_key(self: @TState) -> felt252;
Expand All @@ -25,24 +13,21 @@ trait PublicKeyCamelTrait<TState> {

#[starknet::contract]
mod Account {
use array::ArrayTrait;
use array::SpanTrait;
use box::BoxTrait;
use ecdsa::check_ecdsa_signature;

use openzeppelin::account::interface;
use openzeppelin::introspection::interface::ISRC5;
use openzeppelin::introspection::interface::ISRC5Camel;
use openzeppelin::introspection::src5::SRC5;
use option::OptionTrait;
use openzeppelin::introspection::src5::unsafe_state as src5_state;
use starknet::account::Call;
use starknet::get_caller_address;
use starknet::get_contract_address;
use starknet::get_tx_info;

use super::Call;
use super::QUERY_VERSION;
use super::TRANSACTION_VERSION;
use zeroable::Zeroable;
const TRANSACTION_VERSION: felt252 = 1;
// 2**128 + TRANSACTION_VERSION
const QUERY_VERSION: felt252 = 0x100000000000000000000000000000001;

#[storage]
struct Storage {
Expand Down Expand Up @@ -134,16 +119,14 @@ mod Account {
#[external(v0)]
impl SRC5Impl of ISRC5<ContractState> {
fn supports_interface(self: @ContractState, interface_id: felt252) -> bool {
let unsafe_state = SRC5::unsafe_new_contract_state();
SRC5::SRC5Impl::supports_interface(@unsafe_state, interface_id)
SRC5::SRC5Impl::supports_interface(@src5_state(), interface_id)
}
}

#[external(v0)]
impl SRC5CamelImpl of ISRC5Camel<ContractState> {
fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool {
let unsafe_state = SRC5::unsafe_new_contract_state();
SRC5::SRC5CamelImpl::supportsInterface(@unsafe_state, interfaceId)
SRC5::SRC5CamelImpl::supportsInterface(@src5_state(), interfaceId)
}
}

Expand Down Expand Up @@ -188,7 +171,7 @@ mod Account {
#[generate_trait]
impl InternalImpl of InternalTrait {
fn initializer(ref self: ContractState, _public_key: felt252) {
let mut unsafe_state = SRC5::unsafe_new_contract_state();
let mut unsafe_state = src5_state();
SRC5::InternalImpl::register_interface(ref unsafe_state, interface::ISRC6_ID);
self._set_public_key(_public_key);
}
Expand Down
2 changes: 0 additions & 2 deletions src/account/dual_account.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.7.0 (account/dual_account.cairo)

use array::ArrayTrait;
use array::SpanTrait;
use openzeppelin::utils::UnwrapAndCast;
use openzeppelin::utils::selectors;
use openzeppelin::utils::serde::SerializedAppend;
Expand Down
2 changes: 0 additions & 2 deletions src/account/interface.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.7.0 (account/interface.cairo)

use array::ArrayTrait;
use array::SpanTrait;
use starknet::ContractAddress;
use starknet::account::Call;

Expand Down
1 change: 0 additions & 1 deletion src/introspection/dual_src5.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.7.0 (introspection/dual_src5.cairo)

use array::ArrayTrait;
use openzeppelin::utils::UnwrapAndCast;
use openzeppelin::utils::selectors;
use openzeppelin::utils::try_selector_with_fallback;
Expand Down
5 changes: 5 additions & 0 deletions src/introspection/src5.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ mod SRC5 {
}
}
}

#[inline(always)]
fn unsafe_state() -> SRC5::ContractState {
SRC5::unsafe_new_contract_state()
}
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::utils::constants::{
ADMIN, AUTHORIZED, OTHER, OTHER_ADMIN, ROLE, OTHER_ROLE, ZERO
};
use openzeppelin::tests::utils;
use option::OptionTrait;
use starknet::ContractAddress;
use starknet::contract_address_const;
use starknet::testing;
Expand Down
1 change: 0 additions & 1 deletion src/tests/access/test_dual_accesscontrol.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use array::ArrayTrait;
use openzeppelin::access::accesscontrol::DEFAULT_ADMIN_ROLE;
use openzeppelin::access::accesscontrol::interface::IACCESSCONTROL_ID;
use openzeppelin::access::accesscontrol::interface::IAccessControlDispatcherTrait;
Expand Down
16 changes: 1 addition & 15 deletions src/tests/access/test_dual_ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,11 @@ use openzeppelin::tests::mocks::dual_ownable_mocks::CamelOwnablePanicMock;
use openzeppelin::tests::mocks::dual_ownable_mocks::SnakeOwnableMock;
use openzeppelin::tests::mocks::dual_ownable_mocks::SnakeOwnablePanicMock;
use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock;
use openzeppelin::tests::utils::constants::{OWNER, NEW_OWNER};
use openzeppelin::tests::utils;
use openzeppelin::utils::serde::SerializedAppend;
use starknet::ContractAddress;
use starknet::contract_address_const;
use starknet::testing::set_caller_address;
use starknet::testing::set_contract_address;
use zeroable::Zeroable;

//
// Constants
//

fn OWNER() -> ContractAddress {
contract_address_const::<10>()
}

fn NEW_OWNER() -> ContractAddress {
contract_address_const::<20>()
}

//
// Setup
Expand Down
2 changes: 0 additions & 2 deletions src/tests/access/test_ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ use openzeppelin::access::ownable::Ownable::Ownable_owner::InternalContractMembe
use openzeppelin::access::ownable::Ownable;
use openzeppelin::tests::utils::constants::{ZERO, OTHER, OWNER};
use openzeppelin::tests::utils;
use option::OptionTrait;
use starknet::ContractAddress;
use starknet::contract_address_const;
use starknet::testing;
use zeroable::Zeroable;

//
// Setup
Expand Down
7 changes: 1 addition & 6 deletions src/tests/account/test_account.cairo
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use array::ArrayTrait;
use core::traits::Into;
use openzeppelin::account::Account::OwnerAdded;
use openzeppelin::account::Account::OwnerRemoved;
use openzeppelin::account::Account::PublicKeyCamelImpl;
use openzeppelin::account::Account::PublicKeyImpl;
use openzeppelin::account::Account;
use openzeppelin::account::AccountABIDispatcher;
use openzeppelin::account::AccountABIDispatcherTrait;
use openzeppelin::account::QUERY_VERSION;
use openzeppelin::account::TRANSACTION_VERSION;
use openzeppelin::account::Account::{TRANSACTION_VERSION, QUERY_VERSION};
use openzeppelin::account::interface::ISRC6_ID;
use openzeppelin::introspection::interface::ISRC5_ID;
use openzeppelin::tests::utils;
Expand All @@ -18,8 +15,6 @@ use openzeppelin::token::erc20::interface::IERC20Dispatcher;
use openzeppelin::token::erc20::interface::IERC20DispatcherTrait;
use openzeppelin::utils::selectors;
use openzeppelin::utils::serde::SerializedAppend;
use option::OptionTrait;
use serde::Serde;
use starknet::ContractAddress;
use starknet::account::Call;
use starknet::contract_address_const;
Expand Down
1 change: 0 additions & 1 deletion src/tests/introspection/test_dual_src5.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use array::ArrayTrait;
use openzeppelin::introspection::dual_src5::DualCaseSRC5;
use openzeppelin::introspection::dual_src5::DualCaseSRC5Trait;
use openzeppelin::introspection::interface::ISRC5CamelDispatcher;
Expand Down
4 changes: 1 addition & 3 deletions src/tests/mocks/erc721_receiver.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const SUCCESS: felt252 = 123123;
const FAILURE: felt252 = 456456;
use openzeppelin::tests::utils::constants::{FAILURE, SUCCESS};

#[starknet::contract]
mod ERC721Receiver {
use array::SpanTrait;
use openzeppelin::introspection::interface::ISRC5;
use openzeppelin::introspection::interface::ISRC5Camel;
use openzeppelin::introspection::src5::SRC5;
Expand Down
1 change: 0 additions & 1 deletion src/tests/mocks/upgrades_v1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The functions are NOT PROTECTED.
// DO NOT USE IN PRODUCTION.

use array::ArrayTrait;
use starknet::ClassHash;

#[starknet::interface]
Expand Down
1 change: 0 additions & 1 deletion src/tests/mocks/upgrades_v2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The functions are NOT PROTECTED.
// DO NOT USE IN PRODUCTION.

use array::ArrayTrait;
use starknet::ClassHash;

#[starknet::interface]
Expand Down
1 change: 0 additions & 1 deletion src/tests/security/test_pausable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use openzeppelin::security::pausable::Pausable::Unpaused;
use openzeppelin::security::pausable::Pausable;
use openzeppelin::tests::utils::constants::{CALLER, ZERO};
use openzeppelin::tests::utils;
use option::OptionTrait;
use starknet::contract_address_const;
use starknet::ContractAddress;
use starknet::testing;
Expand Down
29 changes: 3 additions & 26 deletions src/tests/token/test_dual20.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use array::ArrayTrait;
use openzeppelin::tests::mocks::camel20_mock::CamelERC20Mock;
use openzeppelin::tests::mocks::erc20_panic::CamelERC20Panic;
use openzeppelin::tests::mocks::erc20_panic::SnakeERC20Panic;
use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock;
use openzeppelin::tests::mocks::snake20_mock::SnakeERC20Mock;
use openzeppelin::tests::utils::constants::{
OWNER, RECIPIENT, SPENDER, OPERATOR, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE
};
use openzeppelin::tests::utils;
use openzeppelin::token::erc20::dual20::DualCaseERC20;
use openzeppelin::token::erc20::dual20::DualCaseERC20Trait;
Expand All @@ -12,33 +14,8 @@ use openzeppelin::token::erc20::interface::IERC20CamelDispatcherTrait;
use openzeppelin::token::erc20::interface::IERC20Dispatcher;
use openzeppelin::token::erc20::interface::IERC20DispatcherTrait;
use openzeppelin::utils::serde::SerializedAppend;
use starknet::ContractAddress;
use starknet::contract_address_const;
use starknet::testing::set_contract_address;

//
// Constants
//

const NAME: felt252 = 111;
const SYMBOL: felt252 = 222;
const DECIMALS: u8 = 18_u8;
const SUPPLY: u256 = 2000;
const VALUE: u256 = 300;

fn OWNER() -> ContractAddress {
contract_address_const::<10>()
}
fn SPENDER() -> ContractAddress {
contract_address_const::<20>()
}
fn RECIPIENT() -> ContractAddress {
contract_address_const::<30>()
}
fn OPERATOR() -> ContractAddress {
contract_address_const::<40>()
}

//
// Setup
//
Expand Down
Loading

0 comments on commit 420f320

Please sign in to comment.