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

Change unwrap to unwrap_syscall #901

Merged
merged 5 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 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

- Change unwrap to unwrap_syscall (#901)

## 0.9.0 (2024-02-08)

### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/upgrades.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The `{replace_class_syscall}` syscall allows a contract to update its source cod
/// Upgrades the contract source code to the new contract class.
fn _upgrade(new_class_hash: ClassHash) {
assert(!new_class_hash.is_zero(), 'Class hash cannot be zero');
starknet::replace_class_syscall(new_class_hash).unwrap();
starknet::replace_class_syscall(new_class_hash).unwrap_syscall();
}
----

Expand Down
3 changes: 2 additions & 1 deletion src/account/eth_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod EthAccountComponent {
use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait;
use openzeppelin::introspection::src5::SRC5Component;
use poseidon::poseidon_hash_span;
use starknet::SyscallResultTrait;
use starknet::account::Call;
use starknet::get_caller_address;
use starknet::get_contract_address;
Expand Down Expand Up @@ -256,7 +257,7 @@ mod EthAccountComponent {
}

fn _get_guid_from_public_key(public_key: EthPublicKey) -> felt252 {
let (x, y) = public_key.get_coordinates().unwrap();
let (x, y) = public_key.get_coordinates().unwrap_syscall();
poseidon_hash_span(array![x.low.into(), x.high.into(), y.low.into(), y.high.into()].span())
}
}
8 changes: 4 additions & 4 deletions src/account/utils/secp256k1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use starknet::secp256k1::{
/// - Second felt contains x.high and the parity bit, at the least significant bits (2 * x.high + parity).
impl Secp256k1PointStorePacking of starknet::StorePacking<Secp256k1Point, (felt252, felt252)> {
fn pack(value: Secp256k1Point) -> (felt252, felt252) {
let (x, y) = value.get_coordinates().unwrap();
let (x, y) = value.get_coordinates().unwrap_syscall();

let parity = y % 2;
let xhigh_and_parity = 2 * x.high.into() + parity.try_into().unwrap();
Expand All @@ -41,7 +41,7 @@ impl Secp256k1PointStorePacking of starknet::StorePacking<Secp256k1Point, (felt2

impl Secp256k1PointSerde of Serde<Secp256k1Point> {
fn serialize(self: @Secp256k1Point, ref output: Array<felt252>) {
let point = (*self).get_coordinates().unwrap();
let point = (*self).get_coordinates().unwrap_syscall();
point.serialize(ref output)
}
fn deserialize(ref serialized: Span<felt252>) -> Option<Secp256k1Point> {
Expand All @@ -53,7 +53,7 @@ impl Secp256k1PointSerde of Serde<Secp256k1Point> {
impl Secp256k1PointPartialEq of PartialEq<Secp256k1Point> {
#[inline(always)]
fn eq(lhs: @Secp256k1Point, rhs: @Secp256k1Point) -> bool {
(*lhs).get_coordinates().unwrap() == (*rhs).get_coordinates().unwrap()
(*lhs).get_coordinates().unwrap_syscall() == (*rhs).get_coordinates().unwrap_syscall()
}
#[inline(always)]
fn ne(lhs: @Secp256k1Point, rhs: @Secp256k1Point) -> bool {
Expand All @@ -63,7 +63,7 @@ impl Secp256k1PointPartialEq of PartialEq<Secp256k1Point> {

impl DebugSecp256k1Point of core::fmt::Debug<Secp256k1Point> {
fn fmt(self: @Secp256k1Point, ref f: Formatter) -> Result<(), Error> {
let (x, y) = (*self).get_coordinates().unwrap();
let (x, y) = (*self).get_coordinates().unwrap_syscall();
write!(f, "({x:?},{y:?})")
}
}
3 changes: 2 additions & 1 deletion src/tests/account/test_eth_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use openzeppelin::utils::selectors;
use openzeppelin::utils::serde::SerializedAppend;
use poseidon::poseidon_hash_span;
use starknet::ContractAddress;
use starknet::SyscallResultTrait;
use starknet::account::Call;
use starknet::eth_signature::Signature;
use starknet::secp256k1::secp256k1_new_syscall;
Expand Down Expand Up @@ -609,6 +610,6 @@ fn assert_event_owner_removed(contract: ContractAddress, public_key: EthPublicKe
}

fn get_guid_from_public_key(public_key: EthPublicKey) -> felt252 {
let (x, y) = public_key.get_coordinates().unwrap();
let (x, y) = public_key.get_coordinates().unwrap_syscall();
poseidon_hash_span(array![x.low.into(), x.high.into(), y.low.into(), y.high.into()].span())
}
16 changes: 8 additions & 8 deletions src/tests/account/test_secp256k1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ fn test_unpack_big_secp256k1_points() {

// Check point 1

let (expected_x, expected_y) = big_point_1.get_coordinates().unwrap();
let (expected_x, expected_y) = big_point_1.get_coordinates().unwrap_syscall();

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

assert_eq!(x, expected_x);
assert_eq!(y, expected_y);

// Check point 2

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

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

assert_eq!(x, expected_x);
}
Expand All @@ -71,14 +71,14 @@ fn test_secp256k1_serialization() {
// Check point 1

big_point_1.serialize(ref serialized_point);
big_point_1.get_coordinates().unwrap().serialize(ref expected_serialization);
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().serialize(ref expected_serialization);
big_point_2.get_coordinates().unwrap_syscall().serialize(ref expected_serialization);

assert!(serialized_point == expected_serialization);
}
Expand All @@ -91,7 +91,7 @@ fn test_secp256k1_deserialization() {

let mut expected_serialization = array![];

big_point_1.get_coordinates().unwrap().serialize(ref expected_serialization);
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();

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

let mut expected_serialization = array![];

big_point_2.get_coordinates().unwrap().serialize(ref expected_serialization);
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();

Expand Down
6 changes: 4 additions & 2 deletions src/tests/mocks/eth_account_mocks.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ mod CamelEthAccountMock {
mod SnakeEthAccountPanicMock {
use openzeppelin::account::interface::EthPublicKey;
use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde;
use starknet::SyscallResultTrait;
use starknet::secp256k1::secp256k1_new_syscall;

#[storage]
Expand All @@ -165,7 +166,7 @@ mod SnakeEthAccountPanicMock {
#[external(v0)]
fn get_public_key(self: @ContractState) -> EthPublicKey {
panic!("Some error");
secp256k1_new_syscall(3, 3).unwrap().unwrap()
secp256k1_new_syscall(3, 3).unwrap_syscall().unwrap()
}

#[external(v0)]
Expand All @@ -187,6 +188,7 @@ mod SnakeEthAccountPanicMock {
mod CamelEthAccountPanicMock {
use openzeppelin::account::interface::EthPublicKey;
use openzeppelin::account::utils::secp256k1::Secp256k1PointSerde;
use starknet::SyscallResultTrait;
use starknet::secp256k1::secp256k1_new_syscall;

#[storage]
Expand All @@ -200,7 +202,7 @@ mod CamelEthAccountPanicMock {
#[external(v0)]
fn getPublicKey(self: @ContractState) -> EthPublicKey {
panic!("Some error");
secp256k1_new_syscall(3, 3).unwrap().unwrap()
secp256k1_new_syscall(3, 3).unwrap_syscall().unwrap()
}

#[external(v0)]
Expand Down
3 changes: 2 additions & 1 deletion src/tests/utils.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
mod constants;

use starknet::ContractAddress;
use starknet::SyscallResultTrait;
use starknet::testing;

fn deploy(contract_class_hash: felt252, calldata: Array<felt252>) -> ContractAddress {
let (address, _) = starknet::deploy_syscall(
contract_class_hash.try_into().unwrap(), 0, calldata.span(), false
)
.unwrap();
.unwrap_syscall();
address
}

Expand Down
5 changes: 3 additions & 2 deletions src/tests/utils/constants.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use openzeppelin::account::interface::EthPublicKey;
use starknet::ClassHash;
use starknet::ContractAddress;
use starknet::SyscallResultTrait;
use starknet::class_hash_const;
use starknet::contract_address_const;
use starknet::secp256k1::secp256k1_get_point_from_x_syscall;
Expand All @@ -26,11 +27,11 @@ const QUERY_OFFSET: felt252 = 0x100000000000000000000000000000000;
const QUERY_VERSION: felt252 = 0x100000000000000000000000000000001;

fn ETH_PUBKEY() -> EthPublicKey {
secp256k1_get_point_from_x_syscall(3, false).unwrap().unwrap()
secp256k1_get_point_from_x_syscall(3, false).unwrap_syscall().unwrap()
}

fn NEW_ETH_PUBKEY() -> EthPublicKey {
secp256k1_get_point_from_x_syscall(4, false).unwrap().unwrap()
secp256k1_get_point_from_x_syscall(4, false).unwrap_syscall().unwrap()
}

fn ADMIN() -> ContractAddress {
Expand Down
3 changes: 2 additions & 1 deletion src/upgrades/upgradeable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#[starknet::component]
mod UpgradeableComponent {
use starknet::ClassHash;
use starknet::SyscallResultTrait;

#[storage]
struct Storage {}
Expand Down Expand Up @@ -40,7 +41,7 @@ mod UpgradeableComponent {
/// Emits an `Upgraded` event.
fn _upgrade(ref self: ComponentState<TContractState>, new_class_hash: ClassHash) {
assert(!new_class_hash.is_zero(), Errors::INVALID_CLASS);
starknet::replace_class_syscall(new_class_hash).unwrap();
starknet::replace_class_syscall(new_class_hash).unwrap_syscall();
self.emit(Upgraded { class_hash: new_class_hash });
}
}
Expand Down