Skip to content

Commit

Permalink
workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ermvrs committed Jul 12, 2024
1 parent d23cad6 commit 868bfa4
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 54 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Lint build and test

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
lint_build_and_test:
name: Lint build and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Extract scarb version
run: |
SCARB_VERSION=$(grep 'scarb-version = ' Scarb.toml | sed 's/scarb-version = "\(.*\)"/\1/')
echo "SCARB_VERSION=$SCARB_VERSION" >> $GITHUB_ENV
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}
- name: Cairo lint
run: scarb fmt --check
- name: Cairo test
run: scarb test
1 change: 1 addition & 0 deletions src/accounts.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

79 changes: 41 additions & 38 deletions src/accounts/base.cairo
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
pub type EthPublicKey = starknet::secp256k1::Secp256k1Point;
#[starknet::interface]
pub trait IRosettaAccount<TContractState> {
fn __validate__(ref self: TContractState, calls: Array<Call>) -> felt252;
fn __execute__(ref self: TContractState, calls: Array<Call>) -> Array<Span<felt252>>;
fn is_valid_signature(self: @TContractState, hash: felt252, signature: Array<felt252>) -> felt252;
fn is_rosetta_account(self: @TContractState) -> bool;
fn supports_interface(self: @TContractState, interface_id: felt252) -> bool;
pub trait IRosettaAccount<TState> {
fn __execute__(self: @TState, calls: Array<felt252>) -> Array<Span<felt252>>;
fn __validate__(self: @TState, calls: Array<Call>) -> felt252;
fn is_valid_signature(self: @TState, hash: felt252, signature: Array<felt252>) -> felt252;
fn supports_interface(self: @TState, interface_id: felt252) -> bool;
fn __validate_declare__(self: @TState, class_hash: felt252) -> felt252;
fn __validate_deploy__(
self: @TState, class_hash: felt252, contract_address_salt: felt252, public_key: EthPublicKey
) -> felt252;
fn get_public_key(self: @TState) -> EthPublicKey;
fn set_public_key(ref self: TState, new_public_key: EthPublicKey, signature: Span<felt252>);
// Camel case
fn isValidSignature(self: @TState, hash: felt252, signature: Array<felt252>) -> felt252;
fn getPublicKey(self: @TState) -> EthPublicKey;
fn setPublicKey(ref self: TState, newPublicKey: EthPublicKey, signature: Span<felt252>);
}

#[starknet::contract(account)]
mod RosettaAccount {
const TX_V1: felt252 = 1;
const TX_V1_ESTIMATE: felt252 = consteval_int!(0x100000000000000000000000000000000 + 1);
const TX_V3: felt252 = 3;
const TX_V3_ESTIMATE: felt252 = consteval_int!(0x100000000000000000000000000000000 + 3);

use super::EthPublicKey;
use starknet::{EthAddress, get_execution_info, get_contract_address};


#[storage]
struct Storage {
ethereum_address: EthAddress
Expand All @@ -26,43 +33,39 @@ mod RosettaAccount {

#[abi(embed_v0)]
impl AccountImpl of super::IRosettaAccount<ContractState> {
// Verifies signature is the valid signature for this accounts ethereum address equivalent
// And also can verify calldata length
// Calldata will be array of u128s, ethereum calldata slots splitted into low and highs.
fn __validate__(ref self: ContractState, calldata: Array<felt252>) -> felt252 {
// TODO: verify that calldata parameter is the param that passed to the RPC addInvokeTransaction method
// Validate ethereum signature
let execution_info = get_execution_info().unbox();
assert(execution_info.caller_address.is_zero(), 'rosetta-caller-zero');
fn __execute__(self: @TState, calls: Array<felt252>) -> Array<Span<felt252>> {}

let tx_info = execution_info.tx_info.unbox();
assert(tx_info.nonce == 0, 'rosetta-invalid-nonce');
fn __validate__(self: @TState, calls: Array<Call>) -> felt252 {}

let execution_hash = tx_info.transaction_hash;
fn is_valid_signature(self: @TState, hash: felt252, signature: Array<felt252>) -> felt252 {}

let signature = tx_info.signature; // Must be ethereum signature somehow
// assert(signature.len() == 2, 'invalid-signature-len'); // check signature length
fn supports_interface(self: @TState, interface_id: felt252) -> bool {}

let tx_version = tx_info.version;
assert(tx_version == TX_V3_ESTIMATE || tx_version == TX_V1_ESTIMATE,'escrow/invalid-signature'); // TODO: add signature verification
// TODO
starknet::VALIDATED
}
fn __validate_declare__(self: @TState, class_hash: felt252) -> felt252 {}

fn __execute__(ref self: ContractState, calldata: Array<felt252>) -> Array<Span<felt252>> { // TODO: can we pass any array of felts into calls param?
fn __validate_deploy__(
self: @TState,
class_hash: felt252,
contract_address_salt: felt252,
public_key: EthPublicKey
) -> felt252 {}

}
fn get_public_key(self: @TState) -> EthPublicKey {}

fn set_public_key(
ref self: TState, new_public_key: EthPublicKey, signature: Span<felt252>
) {}

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

fn is_rosetta_account(self: @ContractState) -> felt252 {
1
fn getPublicKey(self: @TState) -> EthPublicKey {
self.get_public_key()
}

fn supports_interface(self: @ContractState, interface_id: felt252) -> bool {
true
fn setPublicKey(ref self: TState, newPublicKey: EthPublicKey, signature: Span<felt252>) {
self.set_public_key(newPublicKey, signature)
}
}
}
}
6 changes: 4 additions & 2 deletions src/factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ mod Factory {
/// `address` - Ethereum Address that will be used to precalculate starknet account address.
/// # Returns
/// `ContractAddress` - Precalculated starknet address
fn precalculate_starknet_address(self: @ContractState, address: EthAddress) -> ContractAddress {
fn precalculate_starknet_address(
self: @ContractState, address: EthAddress
) -> ContractAddress {
// todo
0.try_into().unwrap()
}
}
}
}
2 changes: 1 addition & 1 deletion src/lens.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod lens;
mod lens_dev;
mod lens_dev;
6 changes: 4 additions & 2 deletions src/lens/lens_dev.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ mod LensDev {

// 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) {
fn register_address_dev(
ref self: ContractState, address: ContractAddress, eth: EthAddress
) {
assert(self.sn_address_to_eth_address.read(address).is_zero(), 'already registered');

self.eth_address_to_sn_address.write(eth, address);
Expand All @@ -98,4 +100,4 @@ mod LensDev {
self.eth_address_to_sn_address.read(eth_address)
}
}
}
}
2 changes: 1 addition & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod factory;
mod lens;
mod lens;
2 changes: 1 addition & 1 deletion src/verifier.cairo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod utils;
mod utils;
12 changes: 3 additions & 9 deletions src/verifier/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
/// `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.
pub fn parse_calldata(offsets: Span<u128>, calldata: Span<u256>) -> Span<felt252> {

}
pub fn parse_calldata(offsets: Span<u128>, calldata: Span<u256>) -> Span<felt252> {}


/// Finds correct selector with trial and error method
Expand All @@ -16,16 +14,12 @@ pub fn parse_calldata(offsets: Span<u128>, calldata: Span<u256>) -> Span<felt252
/// # Params
/// `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 {

}
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)
/// # Returns
/// `Span<u128>` - Calldata read offsets in bits
pub fn parse_calldata_offsets(function: ByteArray) -> Span<u128> {

}
pub fn parse_calldata_offsets(function: ByteArray) -> Span<u128> {}

0 comments on commit 868bfa4

Please sign in to comment.