-
Notifications
You must be signed in to change notification settings - Fork 354
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
Minor improvements to Account package #1224
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -13,16 +13,12 @@ pub mod EthAccountComponent { | |
use crate::interface::EthPublicKey; | ||
use crate::interface; | ||
use crate::utils::secp256_point::Secp256PointStorePacking; | ||
use crate::utils::{MIN_TRANSACTION_VERSION, QUERY_OFFSET}; | ||
use crate::utils::{execute_calls, is_valid_eth_signature}; | ||
use crate::utils::{is_tx_version_valid, execute_calls, is_valid_eth_signature}; | ||
use openzeppelin_introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; | ||
use openzeppelin_introspection::src5::SRC5Component::SRC5Impl; | ||
use openzeppelin_introspection::src5::SRC5Component; | ||
use starknet::SyscallResultTrait; | ||
use starknet::account::Call; | ||
use starknet::get_caller_address; | ||
use starknet::get_contract_address; | ||
use starknet::get_tx_info; | ||
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; | ||
|
||
#[storage] | ||
|
@@ -72,34 +68,23 @@ pub mod EthAccountComponent { | |
/// Requirements: | ||
/// | ||
/// - The transaction version must be greater than or equal to `MIN_TRANSACTION_VERSION`. | ||
/// - If the transaction is a simulation (version than `QUERY_OFFSET`), it must be | ||
/// - If the transaction is a simulation (version >= `QUERY_OFFSET`), it must be | ||
/// greater than or equal to `QUERY_OFFSET` + `MIN_TRANSACTION_VERSION`. | ||
fn __execute__( | ||
self: @ComponentState<TContractState>, mut calls: Array<Call> | ||
self: @ComponentState<TContractState>, calls: Array<Call> | ||
) -> Array<Span<felt252>> { | ||
// Avoid calls from other contracts | ||
// https://github.com/OpenZeppelin/cairo-contracts/issues/344 | ||
let sender = get_caller_address(); | ||
let sender = starknet::get_caller_address(); | ||
assert(sender.is_zero(), Errors::INVALID_CALLER); | ||
|
||
// Check tx version | ||
let tx_info = get_tx_info().unbox(); | ||
let tx_version: u256 = tx_info.version.into(); | ||
// Check if tx is a query | ||
if (tx_version >= QUERY_OFFSET) { | ||
assert( | ||
QUERY_OFFSET + MIN_TRANSACTION_VERSION <= tx_version, Errors::INVALID_TX_VERSION | ||
); | ||
} else { | ||
assert(MIN_TRANSACTION_VERSION <= tx_version, Errors::INVALID_TX_VERSION); | ||
} | ||
assert(is_tx_version_valid(), Errors::INVALID_TX_VERSION); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏼 |
||
|
||
execute_calls(calls.span()) | ||
} | ||
|
||
/// Verifies the validity of the signature for the current transaction. | ||
/// This function is used by the protocol to verify `invoke` transactions. | ||
fn __validate__(self: @ComponentState<TContractState>, mut calls: Array<Call>) -> felt252 { | ||
fn __validate__(self: @ComponentState<TContractState>, calls: Array<Call>) -> felt252 { | ||
self.validate_transaction() | ||
} | ||
|
||
|
@@ -317,8 +302,9 @@ pub mod EthAccountComponent { | |
impl SRC5: SRC5Component::HasComponent<TContractState>, | ||
+Drop<TContractState> | ||
> of InternalTrait<TContractState> { | ||
/// Initializes the account by setting the initial public key | ||
/// and registering the ISRC6 interface Id. | ||
/// Initializes the account with the given public key, and registers the ISRC6 interface ID. | ||
/// | ||
/// Emits an `OwnerAdded` event. | ||
fn initializer(ref self: ComponentState<TContractState>, public_key: EthPublicKey) { | ||
let mut src5_component = get_dep_component_mut!(ref self, SRC5); | ||
src5_component.register_interface(interface::ISRC6_ID); | ||
|
@@ -327,8 +313,8 @@ pub mod EthAccountComponent { | |
|
||
/// Validates that the caller is the account itself. Otherwise it reverts. | ||
fn assert_only_self(self: @ComponentState<TContractState>) { | ||
let caller = get_caller_address(); | ||
let self = get_contract_address(); | ||
let caller = starknet::get_caller_address(); | ||
let self = starknet::get_contract_address(); | ||
assert(self == caller, Errors::UNAUTHORIZED); | ||
} | ||
|
||
|
@@ -349,7 +335,7 @@ pub mod EthAccountComponent { | |
let message_hash = PoseidonTrait::new() | ||
.update_with('StarkNet Message') | ||
.update_with('accept_ownership') | ||
.update_with(get_contract_address()) | ||
.update_with(starknet::get_contract_address()) | ||
.update_with(current_owner.get_coordinates().unwrap_syscall()) | ||
.finalize(); | ||
|
||
|
@@ -360,7 +346,7 @@ pub mod EthAccountComponent { | |
/// Validates the signature for the current transaction. | ||
/// Returns the short string `VALID` if valid, otherwise it reverts. | ||
fn validate_transaction(self: @ComponentState<TContractState>) -> felt252 { | ||
let tx_info = get_tx_info().unbox(); | ||
let tx_info = starknet::get_tx_info().unbox(); | ||
let tx_hash = tx_info.transaction_hash; | ||
let signature = tx_info.signature; | ||
assert(self._is_valid_signature(tx_hash, signature), Errors::INVALID_SIGNATURE); | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!