-
Notifications
You must be signed in to change notification settings - Fork 78
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
EVM: simplify and fix evm storage #831
Conversation
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.
There isn't really a good reason to be tracking storage status of an item unless you are doing analysis of the values, though at that point you could view the blockstore changes directly and build tooling to analyze at that layer (like we currently do with our memory analysis graphs). 👍
1. The EVM doesn't distinguish between "exists" and "doesn't exist". 2. There was some interesting dead code. 3. Only mark the state-tree dirty if something has changed.
15d50e8
to
914514a
Compare
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.
uh oh problems here?
let opt_value = if value == U256::zero() { None } else { Some(value) }; | ||
|
||
system.set_storage(location, opt_value)?; | ||
system.set_storage(state.stack.pop(), state.stack.pop())?; |
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.
Wait, this is potential undefined behavior with the pops.
Does rust mandate left to right evaluation order for args?
In any othe language you've shot yourself in the foot 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.
left -> right, in -> out. Yes.
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.
uhm ok, interesting.
Can we still either pop first to named or add a comment regardless?
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.
Sure, we can pop first. I agree that it does make the pop order clearer.
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.
left to right is how it is evaluated https://doc.rust-lang.org/reference/expressions.html#evaluation-order-of-operands
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.
I have to say, it is highly unusual of high perf languages to do that.
The compiler is allowed to go bersek here, ocaml does right to left, some C compilers do whatever works faster situationally, and in scheme you are expelled if you assume evaluation order :)
None => U256::zero(), | ||
}; | ||
state.stack.push(value); | ||
state.stack.push(system.get_storage(location)?); |
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.
error? Doesnt evm zero for everything?
Ot is it internal now?
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.
This is a fatal "something is really broken" error (same as before).
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.
Ok, do we have a test for this?
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.
No? This is a "the HAMT is corrupted" error. I.e., there's a bug.
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.
ok, no need to bother then.
Ok(self | ||
.slots | ||
.get(&key) | ||
.map_err(|e| StatusCode::InternalError(e.to_string()))? |
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.
get of something not existing is just zero.
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.
Yes. In the EVM, all storage "exists", it's just all zeros.
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.
Same re test.
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.
See the fixed test below.
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.
thank you.
Lets make sure we got a test or two about boundary behaviour.
Well, there was a test. It was just wrong. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## next #831 +/- ##
==========================================
- Coverage 87.50% 87.49% -0.01%
==========================================
Files 125 125
Lines 22649 22634 -15
==========================================
- Hits 19818 19803 -15
Misses 2831 2831
|
fixes the second half of filecoin-project/ref-fvm#912