-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ermvrs/main
Init validations
- Loading branch information
Showing
10 changed files
with
363 additions
and
26 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,137 @@ | ||
# Code generated by scarb DO NOT EDIT. | ||
version = 1 | ||
|
||
[[package]] | ||
name = "openzeppelin" | ||
version = "0.17.0" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:7e77855aaba0825a2a12cad72d52d85380a9fab732007754b3c5d98908918ce7" | ||
dependencies = [ | ||
"openzeppelin_access", | ||
"openzeppelin_account", | ||
"openzeppelin_finance", | ||
"openzeppelin_governance", | ||
"openzeppelin_introspection", | ||
"openzeppelin_merkle_tree", | ||
"openzeppelin_presets", | ||
"openzeppelin_security", | ||
"openzeppelin_token", | ||
"openzeppelin_upgrades", | ||
"openzeppelin_utils", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_access" | ||
version = "0.17.0" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:541bb8fdf1ad17fe0d275b00acb9f0d7f56ea5534741e21535ac3fda2c600281" | ||
dependencies = [ | ||
"openzeppelin_introspection", | ||
"openzeppelin_utils", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_account" | ||
version = "0.17.0" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:c4e11609fdd1f4c3d3004cd1468711bd2ea664739c9e59a4b270567fe4c23ee3" | ||
dependencies = [ | ||
"openzeppelin_introspection", | ||
"openzeppelin_utils", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_finance" | ||
version = "0.17.0" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:9adcbec76ee8ed08be8d87c6af6014aa7080d67578816f5ba77f4376b25bc165" | ||
dependencies = [ | ||
"openzeppelin_access", | ||
"openzeppelin_token", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_governance" | ||
version = "0.17.0" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:b7e0142d88d69a8c367aea8c9dc7f659f27372551efc23f39a0cf71a189c1302" | ||
dependencies = [ | ||
"openzeppelin_access", | ||
"openzeppelin_introspection", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_introspection" | ||
version = "0.17.0" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:892433a4a1ea0fc9cf7cdb01e06ddc2782182abcc188e4ea5dd480906d006cf8" | ||
|
||
[[package]] | ||
name = "openzeppelin_merkle_tree" | ||
version = "0.17.0" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:3c338fa07cbaba8034051a42967816800abe535ef7d709a929175616603dccf9" | ||
|
||
[[package]] | ||
name = "openzeppelin_presets" | ||
version = "0.17.0" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:0a39e0effff133ab7fb003961ee2986438ee09b53608ce0d71aca24459879597" | ||
dependencies = [ | ||
"openzeppelin_access", | ||
"openzeppelin_account", | ||
"openzeppelin_finance", | ||
"openzeppelin_introspection", | ||
"openzeppelin_token", | ||
"openzeppelin_upgrades", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_security" | ||
version = "0.17.0" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:6e2dee39d87f9ddec2ad37e33e80cf0d8b6c6927fd7950f220dbc2baea658d43" | ||
|
||
[[package]] | ||
name = "openzeppelin_token" | ||
version = "0.17.0" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:77997a7e217b69674c34b402dc0c7b2210540db66a56087572679c31896eaabb" | ||
dependencies = [ | ||
"openzeppelin_account", | ||
"openzeppelin_governance", | ||
"openzeppelin_introspection", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_upgrades" | ||
version = "0.17.0" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:a0fa5934f2924e1e85ec8f8c5b7dcd95c25295c029d3a745ba87b3191146004d" | ||
|
||
[[package]] | ||
name = "openzeppelin_utils" | ||
version = "0.17.0" | ||
source = "registry+https://scarbs.xyz/" | ||
checksum = "sha256:36d93e353f42fd6b824abcd8b4b51c3f5d02c893c5f886ae81403b0368aa5fde" | ||
|
||
[[package]] | ||
name = "rosettacontracts" | ||
version = "0.1.0" | ||
dependencies = [ | ||
"openzeppelin", | ||
"snforge_std", | ||
] | ||
|
||
[[package]] | ||
name = "snforge_scarb_plugin" | ||
version = "0.31.0" | ||
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.31.0#72ea785ca354e9e506de3e5d687da9fb2c1b3c67" | ||
|
||
[[package]] | ||
name = "snforge_std" | ||
version = "0.31.0" | ||
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.31.0#72ea785ca354e9e506de3e5d687da9fb2c1b3c67" | ||
dependencies = [ | ||
"snforge_scarb_plugin", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use starknet::secp256_trait; | ||
use rosettacontracts::accounts::base::{EthPublicKey}; | ||
|
||
#[derive(Copy, Drop, Serde)] | ||
pub struct EthSignature { | ||
pub r: u256, | ||
pub s: u256, | ||
} | ||
|
||
pub fn is_valid_eth_signature( | ||
msg_hash: felt252, public_key: EthPublicKey, signature: Span<felt252> | ||
) -> bool { | ||
let mut signature = signature; | ||
let signature: EthSignature = Serde::deserialize(ref signature) | ||
.expect('Signature: Invalid format.'); | ||
|
||
secp256_trait::is_valid_signature(msg_hash.into(), signature.r, signature.s, public_key) | ||
} | ||
|
||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts for Cairo v0.17.0 (account/utils/secp256k1.cairo) | ||
|
||
use core::fmt::{Formatter, Error}; | ||
use starknet::SyscallResultTrait; | ||
use starknet::secp256_trait::{Secp256Trait, Secp256PointTrait}; | ||
use starknet::secp256k1::Secp256k1Point; | ||
use starknet::storage_access::StorePacking; | ||
|
||
/// Packs a Secp256k1Point into a (felt252, felt252). | ||
/// | ||
/// 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). | ||
pub impl Secp256k1PointStorePacking of StorePacking<Secp256k1Point, (felt252, felt252)> { | ||
fn pack(value: Secp256k1Point) -> (felt252, felt252) { | ||
let (x, y) = value.get_coordinates().unwrap_syscall(); | ||
|
||
let parity = y % 2; | ||
let xhigh_and_parity = 2 * x.high.into() + parity.try_into().unwrap(); | ||
|
||
(x.low.into(), xhigh_and_parity) | ||
} | ||
|
||
fn unpack(value: (felt252, felt252)) -> Secp256k1Point { | ||
let (xlow, xhigh_and_parity) = value; | ||
let xhigh_and_parity: u256 = xhigh_and_parity.into(); | ||
|
||
let x = u256 { | ||
low: xlow.try_into().unwrap(), high: (xhigh_and_parity / 2).try_into().unwrap(), | ||
}; | ||
let parity = xhigh_and_parity % 2 == 1; | ||
|
||
// Expects parity odd to be true | ||
Secp256Trait::secp256_ec_get_point_from_x_syscall(x, parity) | ||
.unwrap_syscall() | ||
.expect('Secp256k1Point: Invalid point.') | ||
} | ||
} | ||
|
||
pub impl Secp256k1PointPartialEq of PartialEq<Secp256k1Point> { | ||
#[inline(always)] | ||
fn eq(lhs: @Secp256k1Point, rhs: @Secp256k1Point) -> bool { | ||
(*lhs).get_coordinates().unwrap_syscall() == (*rhs).get_coordinates().unwrap_syscall() | ||
} | ||
#[inline(always)] | ||
fn ne(lhs: @Secp256k1Point, rhs: @Secp256k1Point) -> bool { | ||
!(lhs == rhs) | ||
} | ||
} | ||
|
||
pub impl DebugSecp256k1Point of core::fmt::Debug<Secp256k1Point> { | ||
fn fmt(self: @Secp256k1Point, ref f: Formatter) -> Result<(), Error> { | ||
let (x, y) = (*self).get_coordinates().unwrap_syscall(); | ||
write!(f, "({x:?},{y:?})") | ||
} | ||
} |
Oops, something went wrong.