-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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
all: use uint256 in state #28598
all: use uint256 in state #28598
Conversation
b94bec4
to
43d4ff8
Compare
@@ -27,4 +31,6 @@ var ( | |||
Big32 = big.NewInt(32) | |||
Big256 = big.NewInt(256) | |||
Big257 = big.NewInt(257) | |||
|
|||
U2560 = uint256.NewInt(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.
U2560 = uint256.NewInt(0) | |
U256_0 = uint256.NewInt(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.
Yeah, I did that originally. But my editor went ahead and changed it. I think there might be something special about numerics and underscores.
e373279
to
47c0888
Compare
This is going to bitrot. Please review. I'd say that the most important parts to check are :
|
@@ -260,7 +265,8 @@ func (st *StateTransition) buyGas() error { | |||
st.gasRemaining += st.msg.GasLimit | |||
|
|||
st.initialGas = st.msg.GasLimit | |||
st.state.SubBalance(st.msg.From, mgval) | |||
mgvalU256, _ := uint256.FromBig(mgval) |
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 can not overflow because mgval is guaranteed to be <= balanceCheck and we check that balance check does not overflow
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, I had some questions/clarifications but I think the PR is good to go
Thanks! I am pushing a change re the stack pushes though |
this PR brings me so much joy inside |
expected := new(big.Int).Add( | ||
new(big.Int).SetUint64(block.GasUsed()*block.Transactions()[0].GasTipCap().Uint64()), | ||
ethash.ConstantinopleBlockReward, |
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 think this is kind of lazy here. Should we just compute the expected value as uint256 as well and then 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.
If we do it in big.Int
, then the test can simply do the calculations, and not worry about overflows or negatives. You might call it lazy, but on the other hand, it means that the test becomes less encumbered with overflow spot-checks.
All in all, I think it's better the way it is (I started changing it, and didn't find the changed code to be an improvement)
I wonder if we should use non-pointer |
Yeah, that might be a good idea. Maybe I'll do a follow-up commit, and if it becomes too large, I'll put it into a separate PR |
Deployed in on bench6 for a full sync, just to ensure nothing broken. |
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 change makes use of uin256 to represent balance in state. It touches primarily upon statedb, stateobject and state processing, trying to avoid changes in transaction pools, core types, rpc and tracers.
core, core/txpool/blobpool: fix tests core/vm: fix tests core/txpool/legacypool: fix tests eth/tracers: fix tests trie: fix tests core/state, core/vm/runtime: fix tests eth: fix tests miner: fix tests
This change makes use of uin256 to represent balance in state. It touches primarily upon statedb, stateobject and state processing, trying to avoid changes in transaction pools, core types, rpc and tracers.
This change makes use of uin256 to represent balance in state. It touches primarily upon statedb, stateobject and state processing, trying to avoid changes in transaction pools, core types, rpc and tracers.
Addresses #28578
Some notable differences:
A. (See conversion: behavioural changes inbig.Int
spits out the decimal form, inString()
andMarshalJson
etc, whereasuint256.Int
spits out hex-form. This caused a few failures in the tracer-engine, since the bignum js did not expect to parse hex. It also causes a test-failure inTestIterativeDump
due to output format change. I'm not sure if we should fix these, or if we should instead switchuint256.Int
over to default to decimal output over hex, to maintain compatibility with big.IntString
,MarshalText
andMarshalJSON
holiman/uint256#144)For reviewers
_test
files (or utilities for use in testing, e.g./tests/
)There are some subtleties to be aware of. Consider the following example:
The code above is perfectly fine with
big.Int
, but as soon as we switch touint256.Int
, the code is buggy. The reason for this is thatAdd
,Mul
andSub
inbig.Int
are lossless, whereas they are lossy inuint256.Int
. Therefore, we need to ensure that in all places where it matter, the second return-value from these operations,overflow
, is checked.And to be extra clear: the github diffview may hide the place where this type of error sits, since the diff is far away from where the bug is.