Skip to content

Commit

Permalink
Add journal entry for logs
Browse files Browse the repository at this point in the history
  • Loading branch information
LindaGuiga committed Oct 10, 2023
1 parent b4203c3 commit 406bba9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions evm/src/cpu/kernel/asm/core/log.asm
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ log_after_topics:
%rlp_list_len
// stack: rlp_log_len, data_len_ptr, num_topics, data_len, data_offset, retdest
%mload_global_metadata(@GLOBAL_METADATA_LOGS_PAYLOAD_LEN)
// Add payload length and logs_data_len to journal.
DUP1 %mload_global_metadata(@GLOBAL_METADATA_LOGS_DATA_LEN) %journal_add_log
ADD
%mstore_global_metadata(@GLOBAL_METADATA_LOGS_PAYLOAD_LEN)
// stack: data_len_ptr, num_topics, data_len, data_offset, retdest
Expand Down Expand Up @@ -263,3 +265,22 @@ one_byte_data:
%jump(rlp_data_len)
%%after:
%endmacro

%macro journal_add_log
%journal_add_2(@JOURNAL_ENTRY_LOG)
%endmacro

global revert_log:
// stack: entry_type, ptr, retdest
POP
// First, reduce the number of logs.
%mload_global_metadata(@GLOBAL_METADATA_LOGS_LEN)
%decrement
%mstore_global_metadata(@GLOBAL_METADATA_LOGS_LEN)
// stack: ptr, retdest
// Second, restore payload length.
%journal_load_2
// stack: prev_logs_data_len, prev_payload_len, retdest
%mstore_global_metadata(@GLOBAL_METADATA_LOGS_DATA_LEN)
%mstore_global_metadata(@GLOBAL_METADATA_LOGS_PAYLOAD_LEN)
JUMP
1 change: 1 addition & 0 deletions evm/src/cpu/kernel/asm/journal/revert.asm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
DUP1 %eq_const(@JOURNAL_ENTRY_CODE_CHANGE) %jumpi(revert_code_change)
DUP1 %eq_const(@JOURNAL_ENTRY_REFUND) %jumpi(revert_refund)
DUP1 %eq_const(@JOURNAL_ENTRY_ACCOUNT_CREATED) %jumpi(revert_account_created)
DUP1 %eq_const(@JOURNAL_ENTRY_LOG) %jumpi(revert_log)
PANIC // This should never happen.
%%after:
// stack: journal_size-1
Expand Down
5 changes: 4 additions & 1 deletion evm/src/cpu/kernel/constants/journal_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ pub(crate) enum JournalEntry {
CodeChange = 7,
Refund = 8,
AccountCreated = 9,
Log = 10,
}

impl JournalEntry {
pub(crate) const COUNT: usize = 10;
pub(crate) const COUNT: usize = 11;

pub(crate) fn all() -> [Self; Self::COUNT] {
[
Expand All @@ -28,6 +29,7 @@ impl JournalEntry {
Self::CodeChange,
Self::Refund,
Self::AccountCreated,
Self::Log,
]
}

Expand All @@ -44,6 +46,7 @@ impl JournalEntry {
Self::CodeChange => "JOURNAL_ENTRY_CODE_CHANGE",
Self::Refund => "JOURNAL_ENTRY_REFUND",
Self::AccountCreated => "JOURNAL_ENTRY_ACCOUNT_CREATED",
Self::Log => "JOURNAL_ENTRY_LOG",
}
}
}

0 comments on commit 406bba9

Please sign in to comment.