-
Notifications
You must be signed in to change notification settings - Fork 38
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 context pruning #112
Add context pruning #112
Conversation
125a7cc
to
02ba230
Compare
It seems this happens if and only if you are in |
Hmm, that's a good idea. There's another case than |
assert_eq!( | ||
interpreter.stack(), | ||
vec![U256::one() << CONTEXT_SCALING_FACTOR, code.len().into()] | ||
); |
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.
DQ: why do we expect this to be the content of the stack here? And why only for EXTCODESIZE
but not for other tests?
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.
That's because extcodesize
(not sys_extcodesize
) now returns code_size, codesize_ctx
. I added the returned stack in a comment in the ASM.
} | ||
Some(mem) | ||
} else { | ||
None |
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.
For my education, what is the case when get_full_memory
is None
? What does that mean that GenerationState
use the default impl and returns None
?
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.
When you're generating the proof (with the full trace), you don't need this memory. The Memory
trace will be generated from the list of MemOps
instead.
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.
Looks great, thank you!
@@ -112,6 +112,15 @@ calldataload_large_offset: | |||
codecopy_within_bounds: | |||
// stack: total_size, segment, src_ctx, kexit_info, dest_offset, offset, size | |||
POP | |||
// stack: segment, src_ctx, kexit_info, dest_offset, offset, 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.
Why do you need to add these changes?
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.
codecopy_within_bounds
calls codecopy_after
instead of wcopy_after
. I agree that's more or less code duplication, but I didn't see an easy way to do it more cleanly.
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.
My problem is that I can't see where are you changing the context here.
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.
From my understanding, the problem with codecopy etc. is that they do not change contexts, but write code in another context. And the idea here is to still be able to prune that extra context when needed by setting the context in codecopy_after.
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.
Ahhh, and why src_ctx
will be never accessed again?
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.
In the case of extcodecopy
and extcodesize
, we generate src_ctx
with next_context_id
which increments @GLOBAL_METADATA_LARGEST_CONTEXT
, meaning that any other created context will have a different id.
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.
Ahhh ok, I think see now. It's because you just need the new_ctx
for writing the code there (and check the hash etc) but after you copy the code you can forget about 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.
LGTM modulo some nits.
@@ -112,6 +112,15 @@ calldataload_large_offset: | |||
codecopy_within_bounds: | |||
// stack: total_size, segment, src_ctx, kexit_info, dest_offset, offset, size | |||
POP | |||
// stack: segment, src_ctx, kexit_info, dest_offset, offset, 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.
My problem is that I can't see where are you changing the context here.
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.
Overall LGTM
Quality Gate passedIssues Measures |
Implements the pruning of stale contexts. A context is stale when it returns to its parent context; after it returns, it can never be accessed again and can be omitted from the memory of subsequent segments.
To detect when a context goes stale, we instrument
SET_CONTEXT
, and check ifnew_ctx < old_ctx
. Since contexts are attributed in a strictly increasing order, this means thatnew_ctx
is the parent context ofold_ctx
, and thus thatold_ctx
is stale.This check is made in the
CPU
table. All the staleold_ctx
values are then transmitted to theMemory
table via a CTL.In
Memory
, for each row, we check ifADDR_CONTEXT
is contained in thePRUNED_CONTEXTS
column via a lookup. If that's the case, it will be omitted from the CTL toMemAfter
.This PR contains #109 and #111. These are required fixes which aren't merged upstream yet. It's opened as a draft so people can look at it and run the test suite on it if they wish, but will wait for these PRs to be merged before opening it in earnest.Edit: Done.
Closes #24