Skip to content

Commit

Permalink
feat: add eth_chain_id entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfalt committed Sep 12, 2024
1 parent eeac8bb commit 4bfc236
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/contracts/src/kakarot_core/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub trait IKakarotCore<TContractState> {
self: @TContractState, origin: EthAddress, tx: Transaction
) -> (bool, Span<u8>, u64);

// Getter for the transaction chain_id
// Returns the chain_id of the transaction after applying modulo 2^53
fn eth_chain_id(self: @TContractState) -> u64;

/// Transaction entrypoint into the EVM
/// Executes an EVM transaction and possibly modifies the state
fn eth_send_transaction(ref self: TContractState, tx: Transaction) -> (bool, Span<u8>, u64);
Expand Down
7 changes: 7 additions & 0 deletions crates/contracts/src/kakarot_core/kakarot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub mod KakarotCore {
use utils::eth_transaction::transaction::{Transaction, TransactionTrait};
use utils::helpers::compute_starknet_address;
use utils::set::{Set, SetTrait};
use utils::constants::POW_2_53;

component!(path: ownable_component, storage: ownable, event: OwnableEvent);
component!(path: upgradeable_component, storage: upgradeable, event: UpgradeableEvent);
Expand Down Expand Up @@ -164,6 +165,12 @@ pub mod KakarotCore {
(success, return_data, gas_used)
}

fn eth_chain_id(self: @ContractState) -> u64 {
let tx_info = get_tx_info().unbox();
let tx_chain_id: u64 = tx_info.chain_id.try_into().unwrap();
tx_chain_id % POW_2_53.try_into().unwrap()
}

fn eth_send_transaction(ref self: ContractState, tx: Transaction) -> (bool, Span<u8>, u64) {
let gas_price = validate_eth_tx(@self, tx);

Expand Down
1 change: 1 addition & 0 deletions crates/utils/src/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ pub const POW_2_24: u128 = 0x1000000;
pub const POW_2_32: u128 = 0x100000000;
pub const POW_2_40: u128 = 0x10000000000;
pub const POW_2_48: u128 = 0x1000000000000;
pub const POW_2_53: u128 = 0x20000000000000;
pub const POW_2_56: u128 = 0x100000000000000;
pub const POW_2_64: u128 = 0x10000000000000000;
pub const POW_2_72: u128 = 0x1000000000000000000;
Expand Down

0 comments on commit 4bfc236

Please sign in to comment.