-
Notifications
You must be signed in to change notification settings - Fork 21.6k
all: use uint256 in state #28598
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,7 +16,11 @@ | |||||
|
|
||||||
| package common | ||||||
|
|
||||||
| import "math/big" | ||||||
| import ( | ||||||
| "math/big" | ||||||
|
|
||||||
| "github.com/holiman/uint256" | ||||||
| ) | ||||||
|
|
||||||
| // Common big integers often used | ||||||
| var ( | ||||||
|
|
@@ -27,4 +31,6 @@ var ( | |||||
| Big32 = big.NewInt(32) | ||||||
| Big256 = big.NewInt(256) | ||||||
| Big257 = big.NewInt(257) | ||||||
|
|
||||||
| U2560 = uint256.NewInt(0) | ||||||
|
||||||
| 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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ import ( | |
| "github.com/ethereum/go-ethereum/ethdb" | ||
| "github.com/ethereum/go-ethereum/params" | ||
| "github.com/ethereum/go-ethereum/trie" | ||
| "github.com/holiman/uint256" | ||
| ) | ||
|
|
||
| // So we can deterministically seed different blockchains | ||
|
|
@@ -3652,7 +3653,7 @@ func testInitThenFailCreateContract(t *testing.T, scheme string) { | |
| defer chain.Stop() | ||
|
|
||
| statedb, _ := chain.State() | ||
| if got, exp := statedb.GetBalance(aa), big.NewInt(100000); got.Cmp(exp) != 0 { | ||
| if got, exp := statedb.GetBalance(aa), uint256.NewInt(100000); got.Cmp(exp) != 0 { | ||
| t.Fatalf("Genesis err, got %v exp %v", got, exp) | ||
| } | ||
| // First block tries to create, but fails | ||
|
|
@@ -3662,7 +3663,7 @@ func testInitThenFailCreateContract(t *testing.T, scheme string) { | |
| t.Fatalf("block %d: failed to insert into chain: %v", block.NumberU64(), err) | ||
| } | ||
| statedb, _ = chain.State() | ||
| if got, exp := statedb.GetBalance(aa), big.NewInt(100000); got.Cmp(exp) != 0 { | ||
| if got, exp := statedb.GetBalance(aa), uint256.NewInt(100000); got.Cmp(exp) != 0 { | ||
| t.Fatalf("block %d: got %v exp %v", block.NumberU64(), got, exp) | ||
| } | ||
| } | ||
|
|
@@ -3848,17 +3849,17 @@ func testEIP1559Transition(t *testing.T, scheme string) { | |
| state, _ := chain.State() | ||
|
|
||
| // 3: Ensure that miner received only the tx's tip. | ||
| actual := state.GetBalance(block.Coinbase()) | ||
| actual := state.GetBalance(block.Coinbase()).ToBig() | ||
| expected := new(big.Int).Add( | ||
| new(big.Int).SetUint64(block.GasUsed()*block.Transactions()[0].GasTipCap().Uint64()), | ||
| ethash.ConstantinopleBlockReward, | ||
|
||
| ethash.ConstantinopleBlockReward.ToBig(), | ||
| ) | ||
| if actual.Cmp(expected) != 0 { | ||
| t.Fatalf("miner balance incorrect: expected %d, got %d", expected, actual) | ||
| } | ||
|
|
||
| // 4: Ensure the tx sender paid for the gasUsed * (tip + block baseFee). | ||
| actual = new(big.Int).Sub(funds, state.GetBalance(addr1)) | ||
| actual = new(big.Int).Sub(funds, state.GetBalance(addr1).ToBig()) | ||
| expected = new(big.Int).SetUint64(block.GasUsed() * (block.Transactions()[0].GasTipCap().Uint64() + block.BaseFee().Uint64())) | ||
| if actual.Cmp(expected) != 0 { | ||
| t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual) | ||
|
|
@@ -3888,17 +3889,17 @@ func testEIP1559Transition(t *testing.T, scheme string) { | |
| effectiveTip := block.Transactions()[0].GasTipCap().Uint64() - block.BaseFee().Uint64() | ||
|
|
||
| // 6+5: Ensure that miner received only the tx's effective tip. | ||
| actual = state.GetBalance(block.Coinbase()) | ||
| actual = state.GetBalance(block.Coinbase()).ToBig() | ||
| expected = new(big.Int).Add( | ||
| new(big.Int).SetUint64(block.GasUsed()*effectiveTip), | ||
| ethash.ConstantinopleBlockReward, | ||
| ethash.ConstantinopleBlockReward.ToBig(), | ||
| ) | ||
| if actual.Cmp(expected) != 0 { | ||
| t.Fatalf("miner balance incorrect: expected %d, got %d", expected, actual) | ||
| } | ||
|
|
||
| // 4: Ensure the tx sender paid for the gasUsed * (effectiveTip + block baseFee). | ||
| actual = new(big.Int).Sub(funds, state.GetBalance(addr2)) | ||
| actual = new(big.Int).Sub(funds, state.GetBalance(addr2).ToBig()) | ||
| expected = new(big.Int).SetUint64(block.GasUsed() * (effectiveTip + block.BaseFee().Uint64())) | ||
| if actual.Cmp(expected) != 0 { | ||
| t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual) | ||
|
|
@@ -4703,14 +4704,14 @@ func TestEIP3651(t *testing.T) { | |
| state, _ := chain.State() | ||
|
|
||
| // 3: Ensure that miner received only the tx's tip. | ||
| actual := state.GetBalance(block.Coinbase()) | ||
| actual := state.GetBalance(block.Coinbase()).ToBig() | ||
| expected := new(big.Int).SetUint64(block.GasUsed() * block.Transactions()[0].GasTipCap().Uint64()) | ||
| if actual.Cmp(expected) != 0 { | ||
| t.Fatalf("miner balance incorrect: expected %d, got %d", expected, actual) | ||
| } | ||
|
|
||
| // 4: Ensure the tx sender paid for the gasUsed * (tip + block baseFee). | ||
| actual = new(big.Int).Sub(funds, state.GetBalance(addr1)) | ||
| actual = new(big.Int).Sub(funds, state.GetBalance(addr1).ToBig()) | ||
| expected = new(big.Int).SetUint64(block.GasUsed() * (block.Transactions()[0].GasTipCap().Uint64() + block.BaseFee().Uint64())) | ||
| if actual.Cmp(expected) != 0 { | ||
| t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.