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.
* mstore tests impl * made exec_mstore panic * corrected test case error * mstore opcode impl * review correction + add 2 tests * correction test case * used pop_n instead * corrected #263 succeed into succeeded * reverted to single pop + removed tests * first commit * removed print and used default for array * added readonly test & cleaned imports * added internal get_datas * need to merge main * removed ',' from merge * check load vs loadn * switch data array from felt to u8 * cleaned code/tests * review correction * compare all bytes in tests + inlined app_event * stop useless slicing * added tests cases * simplified expected array * merge correction * cleaned imports * scarb fmt did that * dupl app_event + setup_readonly * change error message + setup with readonly * correction rebase --------- Co-authored-by: Elias Tazartes <[email protected]>
- Loading branch information
Showing
10 changed files
with
436 additions
and
45 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
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 |
---|---|---|
@@ -1,48 +1,77 @@ | ||
use evm::errors::EVMError; | ||
//! Logging Operations. | ||
|
||
// Internal imports | ||
use evm::machine::Machine; | ||
|
||
mod internal { | ||
use evm::machine::Machine; | ||
#[generate_trait] | ||
impl LoggingOperations of LoggingOperationsTrait { | ||
/// 0xA0 - LOG0 operation | ||
/// Append log record with no topic. | ||
/// # Specification: https://www.evm.codes/#a0?fork=shanghai | ||
fn exec_log0(ref self: Machine) -> Result<(), EVMError> { | ||
internal::exec_log_i(ref self, 0) | ||
} | ||
|
||
/// Generic logging operation. | ||
/// Append log record with n topics. | ||
fn exec_log_i(ref machine: Machine, topics_len: u8) {} | ||
} | ||
/// 0xA1 - LOG1 | ||
/// Append log record with one topic. | ||
/// # Specification: https://www.evm.codes/#a1?fork=shanghai | ||
fn exec_log1(ref self: Machine) -> Result<(), EVMError> { | ||
internal::exec_log_i(ref self, 1) | ||
} | ||
|
||
/// 0xA0 - LOG0 operation | ||
/// Append log record with no topic. | ||
/// # Specification: https://www.evm.codes/#a0?fork=shanghai | ||
fn exec_log0(ref machine: Machine) { | ||
internal::exec_log_i(ref machine, 0); | ||
} | ||
/// 0xA2 - LOG2 | ||
/// Append log record with two topics. | ||
/// # Specification: https://www.evm.codes/#a2?fork=shanghai | ||
fn exec_log2(ref self: Machine) -> Result<(), EVMError> { | ||
internal::exec_log_i(ref self, 2) | ||
} | ||
|
||
/// 0xA3 - LOG3 | ||
/// Append log record with three topics. | ||
/// # Specification: https://www.evm.codes/#a3?fork=shanghai | ||
fn exec_log3(ref self: Machine) -> Result<(), EVMError> { | ||
internal::exec_log_i(ref self, 3) | ||
} | ||
|
||
/// 0xA1 - LOG1 | ||
/// Append log record with one topic. | ||
/// # Specification: https://www.evm.codes/#a1?fork=shanghai | ||
fn exec_log1(ref machine: Machine) { | ||
internal::exec_log_i(ref machine, 1); | ||
/// 0xA4 - LOG4 | ||
/// Append log record with four topics. | ||
/// # Specification: https://www.evm.codes/#a4?fork=shanghai | ||
fn exec_log4(ref self: Machine) -> Result<(), EVMError> { | ||
internal::exec_log_i(ref self, 4) | ||
} | ||
} | ||
|
||
/// 0xA2 - LOG2 | ||
/// Append log record with two topics. | ||
/// # Specification: https://www.evm.codes/#a2?fork=shanghai | ||
fn exec_log2(ref machine: Machine) { | ||
internal::exec_log_i(ref machine, 2); | ||
} | ||
mod internal { | ||
use evm::errors::{EVMError, WRITE_IN_STATIC_CONTEXT}; | ||
use evm::machine::{Machine, MachineCurrentContextTrait}; | ||
use evm::memory::MemoryTrait; | ||
use evm::model::Event; | ||
use evm::stack::StackTrait; | ||
|
||
/// 0xA3 - LOG3 | ||
/// Append log record with three topics. | ||
/// # Specification: https://www.evm.codes/#a3?fork=shanghai | ||
fn exec_log3(ref machine: Machine) { | ||
internal::exec_log_i(ref machine, 3); | ||
} | ||
/// Store a new event in the dynamic context using topics | ||
/// popped from the stack and data from the memory. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `self` - The context to which the event will be added | ||
/// * `topics_len` - The amount of topics to pop from the stack | ||
fn exec_log_i(ref self: Machine, topics_len: u8) -> Result<(), EVMError> { | ||
// Revert if the transaction is in a read only context | ||
if self.read_only() { | ||
return Result::Err(EVMError::WriteInStaticContext(WRITE_IN_STATIC_CONTEXT)); | ||
} | ||
|
||
let offset = self.stack.pop_usize()?; | ||
let size = self.stack.pop_usize()?; | ||
let topics: Array<u256> = self.stack.pop_n(topics_len.into())?; | ||
|
||
let mut data: Array<u8> = Default::default(); | ||
self.memory.load_n(size, ref data, offset); | ||
|
||
let event: Event = Event { keys: topics, data }; | ||
self.append_event(event); | ||
|
||
/// 0xA4 - LOG4 | ||
/// Append log record with 4 topics. | ||
/// # Specification: https://www.evm.codes/#a4?fork=shanghai | ||
fn exec_log4(ref machine: Machine) { | ||
internal::exec_log_i(ref machine, 4); | ||
Result::Ok(()) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#[derive(Drop)] | ||
struct Event { | ||
keys: Array<u256>, | ||
data: Array<felt252>, | ||
data: Array<u8>, | ||
} |
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.