generated from keep-starknet-strange/alexandria
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create first version of skeleton for kakarot ssj (#42)
* feat: create first version of skeleton for kakarot ssj * fix: run scarb fmt * fix: use span * fix: fix rebase on main * chore: format * fix: remove unused methods * feat: change types to not use felts * chore: remove max unused function
- Loading branch information
Showing
17 changed files
with
141 additions
and
98 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Migrate https://github.com/kkrt-labs/kakarot/blob/7ec7a96074394ddb592a2b6fbea279c6c5cb25a6/src/kakarot/accounts/contract/contract_account.cairo#L4 | ||
// Note that we don't need proxies anymore with the new idiomatic way to replace implementations. | ||
// For now, as discussed with Shahar Papini, we can still use storage slots to store bytecode. | ||
// That being said, we can modify the way we store it with new mappings and storage outlays to optimize steps. | ||
// Use Traits, impls blocks and idiomatic Cairo 1.0 | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use array::ArrayTrait; | ||
|
||
struct EthereumTransaction { | ||
nonce: u128, | ||
gas_price: u128, | ||
gas_limit: u128, | ||
destination: EthAddress, | ||
amount: u256, | ||
payload: Span<felt252>, | ||
tx_hash: u256, | ||
v: u128, | ||
r: u256, | ||
s: u256, | ||
} | ||
|
||
trait EthTransaction { | ||
/// Decode a legacy Ethereum transaction | ||
/// This function decodes a legacy Ethereum transaction in accordance with EIP-155. | ||
/// It returns transaction details including nonce, gas price, gas limit, destination address, amount, payload, | ||
/// transaction hash, and signature (v, r, s). The transaction hash is computed by keccak hashing the signed | ||
/// transaction data, which includes the chain ID in accordance with EIP-155. | ||
/// # Arguments | ||
/// tx_data The raw transaction data | ||
fn decode_legacy_tx(tx_data: Span<u8>) -> EthereumTransaction; | ||
|
||
/// Decode a modern Ethereum transaction | ||
/// This function decodes a modern Ethereum transaction in accordance with EIP-2718. | ||
/// It returns transaction details including nonce, gas price, gas limit, destination address, amount, payload, | ||
/// transaction hash, and signature (v, r, s). The transaction hash is computed by keccak hashing the signed | ||
/// transaction data, which includes the chain ID as part of the transaction data itself. | ||
/// # Arguments | ||
/// tx_data The raw transaction data | ||
fn decode_tx(tx_data: Span<u8>) -> EthereumTransaction; | ||
|
||
/// Check if a raw transaction is a legacy Ethereum transaction | ||
/// This function checks if a raw transaction is a legacy Ethereum transaction by checking the transaction type | ||
/// according to EIP-2718. If the transaction type is less than or equal to 0xc0, it's a legacy transaction. | ||
/// # Arguments | ||
/// - `tx_data` The raw transaction data | ||
fn is_legacy_tx(tx_data: Span<u8>) -> bool; | ||
|
||
/// Decode a raw Ethereum transaction | ||
/// This function decodes a raw Ethereum transaction. It checks if the transaction | ||
/// is a legacy transaction or a modern transaction, and calls the appropriate decode function | ||
/// resp. `decode_legacy_tx` or `decode_tx` based on the result. | ||
/// # Arguments | ||
/// - `tx_data` The raw transaction data | ||
fn decode(tx_data: Span<u8>) -> EthereumTransaction; | ||
|
||
/// Validate an Ethereum transaction | ||
/// This function validates an Ethereum transaction by checking if the transaction | ||
/// is correctly signed by the given address, and if the nonce in the transaction | ||
/// matches the nonce of the account. | ||
/// It decodes the transaction using the decode function, | ||
/// and then verifies the Ethereum signature on the transaction hash. | ||
/// # Arguments | ||
/// - `address` The ethereum address that is supposed to have signed the transaction | ||
/// - `account_nonce` The nonce of the account | ||
/// - `param tx_data` The raw transaction data | ||
fn validate_eth_tx(address: EthAddress, account_nonce: u128, tx_data: Span<u8>) -> bool; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Migrate https://github.com/kkrt-labs/kakarot/blob/7ec7a96074394ddb592a2b6fbea279c6c5cb25a6/src/kakarot/accounts/eoa/externally_owned_account.cairo#L4 | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Reproduce the original rlp.cairo from https://github.com/kkrt-labs/kakarot/blob/7ec7a96074394ddb592a2b6fbea279c6c5cb25a6/src/utils/rlp.cairo#L18 | ||
// By using new Cairo idiomatic ways: Traits, Struct and impl blocks. | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// import modules tests/contract_account folder | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// tests go here | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// import modules from tests/eoa folder here | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// tests go here | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// tests go here | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// tests go here | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// import modules from tests/instructions folder here | ||
|
||
|
3 changes: 3 additions & 0 deletions
3
src/tests/instructions/test_stop_and_arithmetic_operations.cairo
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// tests for stop and arithmetic operations go here | ||
|
||
|
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