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

Update location of ENCODED_EMPTY_NODE #62

Merged
merged 6 commits into from
Feb 27, 2024
Merged

Conversation

Nashtare
Copy link
Collaborator

@Nashtare Nashtare commented Feb 26, 2024

This PR updates the position of ENCODED_EMPTY_NODE from 2^32 to 1, in order to save on padded memory rows, in particular in the context of continuations.

The RLP segment now looks like so:

  • offset 0: rlp data size
  • offset 1: empty node encoding
  • offset 2: start of txn rlp encoding

I've added an INITIAL_TXN_RLP_ADDR constant for easier addressing in the kernel.

closes #26

@Nashtare Nashtare added the crate: evm_arithmetization Anything related to the evm_arithmetization crate. label Feb 26, 2024
@Nashtare Nashtare self-assigned this Feb 26, 2024
// Initialize the trie data length in the RlpRaw segment.
let trie_data_len = interpreter.get_trie_data().len().into();
interpreter.generation_state.memory.contexts[0].segments[Segment::RlpRaw.unscale()].content
[0] = trie_data_len;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the same value stored in GLOBAL_METADATA_TRIE_DATA_SIZE?


// The two first values of the RLP segment are trie_data_len (here 0), and the
// hardcoded 0x80 for an empty node.
let expected_rlp = vec![0, 0x80, 0x80 + 3, 0x01, 0x23, 0x45];
Copy link
Contributor

Choose a reason for hiding this comment

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

Is trie_data_len supposed to be 0? (Is it updated anywhere? Or is it just the length of the initial MPTs?). I am not sure I understand the need for trie_data_len actually, since we have the global metadata for the size of the segment. Am I missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We initially store at offset 0 the length of TrieData when initializing the RLP segment. But for this test (and in others), it doesn't matter. As we update address at offset 1 for the empty node, it is initialized with 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I'm still a bit confused about trie_data_len: I'm not sure where we need it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe the comment is confusing. This cell isn't supposed to store trie_data_len at anytime per se, but the length of the RLP segment, so that we know where to allocate a new buffer whenever we need to write in this segment. It's initialized with the length of trie data, hence why I wrote this, but it's really just rlp_data_size

Copy link
Contributor

Choose a reason for hiding this comment

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

Then what is the difference with the global metadata? (Why do we need both?). Also, can you point to the part of the code that uses trie_data_len please? (Sorry for my confusion!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I think I may have been confused by this comment in the end:

    /// The size of the `TrieData` segment, in bytes, represented as a whole
    /// address. In other words, the next address available for appending
    /// additional trie data.
    RlpDataSize,

but it's not really accurate, and we store SEGMENT_RLP_RAW in main.asm (i.e. the initial address). So mea culpa, I'll update it tomorrow (and I'll fix this comment).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's updated. Now EMPTY_NODE_ADDR is at offset 0, and we initialize the next RLP address in main.asm as INITIAL_TXN_RLP_ADDR (which is at offset 1).

Copy link
Contributor

@4l0n50 4l0n50 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@LindaGuiga LindaGuiga left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! But I think it would also be good to remove, in this PR, the Segment::constant method (and its usage in get and set) that was used to not actually have to set the memory value to 0x80 in the MemoryState.

@Nashtare
Copy link
Collaborator Author

Ah good point, will do!

@Nashtare Nashtare enabled auto-merge (squash) February 27, 2024 10:35
@Nashtare Nashtare merged commit ab682f1 into main Feb 27, 2024
5 checks passed
@Nashtare Nashtare deleted the move_encode_node_pos branch February 27, 2024 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate: evm_arithmetization Anything related to the evm_arithmetization crate.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Move the empty node encoding to pos 0
3 participants