-
Notifications
You must be signed in to change notification settings - Fork 40
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
Conversation
// 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; |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!)
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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
.
Ah good point, will do! |
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:
I've added an
INITIAL_TXN_RLP_ADDR
constant for easier addressing in the kernel.closes #26