Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
ermvrs committed Oct 12, 2024
1 parent 3f5bc2f commit d93b918
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 16 deletions.
22 changes: 15 additions & 7 deletions src/accounts/base.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ pub trait IRosettaAccount<TState> {
mod RosettaAccount {
use super::EthPublicKey;
use core::num::traits::Zero;
use starknet::{EthAddress, get_execution_info, get_contract_address, get_caller_address, get_tx_info};
use starknet::{
EthAddress, get_execution_info, get_contract_address, get_caller_address, get_tx_info
};
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};
use rosettacontracts::accounts::utils::{is_valid_eth_signature, Secp256k1PointStorePacking};

Expand All @@ -46,11 +48,11 @@ mod RosettaAccount {

#[abi(embed_v0)]
impl AccountImpl of super::IRosettaAccount<ContractState> {
// Instead of Array<Call> we use Array<felt252> since we pass different values to the parameter
// Instead of Array<Call> we use Array<felt252> since we pass different values to the
// parameter
fn __execute__(self: @ContractState, calls: Array<felt252>) -> Array<Span<felt252>> {
let sender = get_caller_address();
assert(sender.is_zero(), Errors::INVALID_CALLER);

assert(sender.is_zero(), Errors::INVALID_CALLER);
// TODO: Check tx version

// TODO: Exec calls
Expand All @@ -61,7 +63,9 @@ mod RosettaAccount {
self.validate_transaction()
}

fn is_valid_signature(self: @ContractState, hash: felt252, signature: Array<felt252>) -> felt252 {
fn is_valid_signature(
self: @ContractState, hash: felt252, signature: Array<felt252>
) -> felt252 {
if self._is_valid_signature(hash, signature.span()) {
starknet::VALIDATED
} else {
Expand Down Expand Up @@ -97,7 +101,9 @@ mod RosettaAccount {
ref self: ContractState, new_public_key: EthPublicKey, signature: Span<felt252>
) {}

fn isValidSignature(self: @ContractState, hash: felt252, signature: Array<felt252>) -> felt252 {
fn isValidSignature(
self: @ContractState, hash: felt252, signature: Array<felt252>
) -> felt252 {
self.is_valid_signature(hash, signature)
}

Expand All @@ -106,7 +112,9 @@ mod RosettaAccount {
}

// We dont need that function
fn setPublicKey(ref self: ContractState, newPublicKey: EthPublicKey, signature: Span<felt252>) {
fn setPublicKey(
ref self: ContractState, newPublicKey: EthPublicKey, signature: Span<felt252>
) {
self.set_public_key(newPublicKey, signature)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/accounts/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ pub impl DebugSecp256k1Point of core::fmt::Debug<Secp256k1Point> {
let (x, y) = (*self).get_coordinates().unwrap_syscall();
write!(f, "({x:?},{y:?})")
}
}
}
12 changes: 10 additions & 2 deletions src/factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ mod Factory {
// TODO: Tests

let eth_address_felt: felt252 = address.into();
calculate_contract_address_from_deploy_syscall(eth_address_felt, self.account_class.read(), array![eth_address_felt].span(), 0.try_into().unwrap())
calculate_contract_address_from_deploy_syscall(
eth_address_felt,
self.account_class.read(),
array![eth_address_felt].span(),
0.try_into().unwrap()
)
}

/// Deploys new rosettanet account. Fails if account already deployed
Expand All @@ -64,7 +69,10 @@ mod Factory {
// TODO: Tests
let eth_address_felt: felt252 = address.into();

let (account, _) = deploy_syscall(self.account_class.read(), eth_address_felt, array![eth_address_felt].span(), true).unwrap();
let (account, _) = deploy_syscall(
self.account_class.read(), eth_address_felt, array![eth_address_felt].span(), true
)
.unwrap();

// Todo: register lens if needed ?? Or we can use precalculate
account
Expand Down
3 changes: 2 additions & 1 deletion src/lens/lens_dev.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ mod LensDev {
}
}

// Function just for development tests. We can match any address with any eth address we want.
// Function just for development tests. We can match any address with any eth address we
// want.
// Helps developing.
fn register_address_dev(
ref self: ContractState, address: ContractAddress, eth: EthAddress
Expand Down
2 changes: 1 addition & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ pub mod lens;
pub mod accounts {
pub mod base;
pub mod utils;
}
}
11 changes: 7 additions & 4 deletions src/verifier/utils.cairo
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
/// Returns starknet calldata span of felt252s
/// Returns starknet calldata span of felt252s
/// This function do not checks function selector
/// # Params
/// `offsets` - Calldata read offsets, parse done according to these values
/// `calldata` - Actual EVM calldata, each element presents one slot
/// # Returns
/// `Span<felt252>` - Parsed and converted calldata which is going to be passed to call_contract_syscall.
/// `Span<felt252>` - Parsed and converted calldata which is going to be passed to
/// call_contract_syscall.
pub fn parse_calldata(offsets: Span<u128>, calldata: Span<u256>) -> Span<felt252> {}


/// Finds correct selector with trial and error method
/// It tries to re-calculate ethereum function signature by trying
/// all functions from the input.
/// # Params
/// `functions` - Function names with data types of ethereum span (balanceOf(address), transfer_from(address,address,uint256))
/// `functions` - Function names with data types of ethereum span (balanceOf(address),
/// transfer_from(address,address,uint256))
/// `signature` - Actual ethereum function signature from calldata.
pub fn find_selector(functions: Span<ByteArray>, signature: u16) -> felt252 {}

/// Parse parameters bit offsets according their sizes in ethereum slot
/// It has to be called after function name is found and matched.
/// # Params
/// `function` - Ethereum function name and parameters e.g. balanceOf(address), witharray(uint256[]), withtuple((uint128,uint64,uint256),address)
/// `function` - Ethereum function name and parameters e.g. balanceOf(address),
/// witharray(uint256[]), withtuple((uint128,uint64,uint256),address)
/// # Returns
/// `Span<u128>` - Calldata read offsets in bits
pub fn parse_calldata_offsets(function: ByteArray) -> Span<u128> {}
1 change: 1 addition & 0 deletions tests/factory_tests.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit d93b918

Please sign in to comment.