Skip to content
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

Add journal entry for logs #1286

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: For other journal entries, we have a file evm/src/cpu/kernel/asm/journal/X.asm containing journal_add_X and revert_X. So maybe we can add a evm/src/cpu/kernel/asm/journal/log.asm with this code.

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",
}
}
}
Loading