From 868bfa45ac6fcf8aaff224c7d26ccbd0034ea4c2 Mon Sep 17 00:00:00 2001 From: ermvrs Date: Fri, 12 Jul 2024 13:32:14 +0300 Subject: [PATCH] workflow --- .github/workflows/build.yml | 27 +++++++++++++ src/accounts.cairo | 1 + src/accounts/base.cairo | 79 +++++++++++++++++++------------------ src/factory.cairo | 6 ++- src/lens.cairo | 2 +- src/lens/lens_dev.cairo | 6 ++- src/lib.cairo | 2 +- src/verifier.cairo | 2 +- src/verifier/utils.cairo | 12 ++---- 9 files changed, 83 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a1352bc --- /dev/null +++ b/.github/workflows/build.yml @@ -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 \ No newline at end of file diff --git a/src/accounts.cairo b/src/accounts.cairo index e69de29..8b13789 100644 --- a/src/accounts.cairo +++ b/src/accounts.cairo @@ -0,0 +1 @@ + diff --git a/src/accounts/base.cairo b/src/accounts/base.cairo index 4e8865b..b63e33d 100644 --- a/src/accounts/base.cairo +++ b/src/accounts/base.cairo @@ -1,21 +1,28 @@ +pub type EthPublicKey = starknet::secp256k1::Secp256k1Point; #[starknet::interface] -pub trait IRosettaAccount { - fn __validate__(ref self: TContractState, calls: Array) -> felt252; - fn __execute__(ref self: TContractState, calls: Array) -> Array>; - fn is_valid_signature(self: @TContractState, hash: felt252, signature: Array) -> felt252; - fn is_rosetta_account(self: @TContractState) -> bool; - fn supports_interface(self: @TContractState, interface_id: felt252) -> bool; +pub trait IRosettaAccount { + fn __execute__(self: @TState, calls: Array) -> Array>; + fn __validate__(self: @TState, calls: Array) -> felt252; + fn is_valid_signature(self: @TState, hash: felt252, signature: Array) -> 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); + // Camel case + fn isValidSignature(self: @TState, hash: felt252, signature: Array) -> felt252; + fn getPublicKey(self: @TState) -> EthPublicKey; + fn setPublicKey(ref self: TState, newPublicKey: EthPublicKey, signature: Span); } #[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 @@ -26,43 +33,39 @@ mod RosettaAccount { #[abi(embed_v0)] impl AccountImpl of super::IRosettaAccount { - // 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 { - // 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) -> Array> {} - let tx_info = execution_info.tx_info.unbox(); - assert(tx_info.nonce == 0, 'rosetta-invalid-nonce'); + fn __validate__(self: @TState, calls: Array) -> felt252 {} - let execution_hash = tx_info.transaction_hash; + fn is_valid_signature(self: @TState, hash: felt252, signature: Array) -> 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) -> Array> { // 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 + ) {} - fn is_valid_signature(self: @ContractState, hash: felt252, signature: Array) -> felt252 { - 0 + fn isValidSignature(self: @TState, hash: felt252, signature: Array) -> 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) { + self.set_public_key(newPublicKey, signature) } } -} \ No newline at end of file +} diff --git a/src/factory.cairo b/src/factory.cairo index 038f968..9057557 100644 --- a/src/factory.cairo +++ b/src/factory.cairo @@ -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() } } -} \ No newline at end of file +} diff --git a/src/lens.cairo b/src/lens.cairo index 6073ea4..89ec276 100644 --- a/src/lens.cairo +++ b/src/lens.cairo @@ -1,2 +1,2 @@ mod lens; -mod lens_dev; \ No newline at end of file +mod lens_dev; diff --git a/src/lens/lens_dev.cairo b/src/lens/lens_dev.cairo index 7e01192..6a5d17d 100644 --- a/src/lens/lens_dev.cairo +++ b/src/lens/lens_dev.cairo @@ -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); @@ -98,4 +100,4 @@ mod LensDev { self.eth_address_to_sn_address.read(eth_address) } } -} \ No newline at end of file +} diff --git a/src/lib.cairo b/src/lib.cairo index 253e7e3..64f626a 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -1,2 +1,2 @@ mod factory; -mod lens; \ No newline at end of file +mod lens; diff --git a/src/verifier.cairo b/src/verifier.cairo index 40679bc..95adf51 100644 --- a/src/verifier.cairo +++ b/src/verifier.cairo @@ -1 +1 @@ -mod utils; \ No newline at end of file +mod utils; diff --git a/src/verifier/utils.cairo b/src/verifier/utils.cairo index 10ed2c0..7d1f15c 100644 --- a/src/verifier/utils.cairo +++ b/src/verifier/utils.cairo @@ -5,9 +5,7 @@ /// `calldata` - Actual EVM calldata, each element presents one slot /// # Returns /// `Span` - Parsed and converted calldata which is going to be passed to call_contract_syscall. -pub fn parse_calldata(offsets: Span, calldata: Span) -> Span { - -} +pub fn parse_calldata(offsets: Span, calldata: Span) -> Span {} /// Finds correct selector with trial and error method @@ -16,9 +14,7 @@ pub fn parse_calldata(offsets: Span, calldata: Span) -> Span, signature: u16) -> felt252 { - -} +pub fn find_selector(functions: Span, 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. @@ -26,6 +22,4 @@ pub fn find_selector(functions: Span, signature: u16) -> felt252 { /// `function` - Ethereum function name and parameters e.g. balanceOf(address), witharray(uint256[]), withtuple((uint128,uint64,uint256),address) /// # Returns /// `Span` - Calldata read offsets in bits -pub fn parse_calldata_offsets(function: ByteArray) -> Span { - -} \ No newline at end of file +pub fn parse_calldata_offsets(function: ByteArray) -> Span {}