Skip to content

Commit

Permalink
Removed all references to Homestead in go-quai, except for jump table…
Browse files Browse the repository at this point in the history
… (removed next)
  • Loading branch information
jdowning100 committed Apr 25, 2023
1 parent 7ccb9b1 commit 171e5a4
Show file tree
Hide file tree
Showing 35 changed files with 82 additions and 300 deletions.
4 changes: 1 addition & 3 deletions cmd/go-quai/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var daoOldGenesis = `{
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"config" : {
"homesteadBlock" : 0
}
}`

Expand All @@ -56,7 +55,7 @@ var daoNoForkGenesis = `{
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"config" : {
"homesteadBlock" : 0,
"daoForkBlock" : 314,
"daoForkSupport" : false
}
Expand All @@ -74,7 +73,6 @@ var daoProForkGenesis = `{
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"config" : {
"homesteadBlock" : 0,
"daoForkBlock" : 314,
"daoForkSupport" : true
}
Expand Down
1 change: 0 additions & 1 deletion cmd/go-quai/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ var customGenesisTests = []struct {
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"config" : {
"homesteadBlock" : 42,
"daoForkBlock" : 141,
"daoForkSupport" : true
}
Expand Down
15 changes: 1 addition & 14 deletions consensus/blake3pow/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestCalcDifficulty(t *testing.T) {
t.Fatal(err)
}

config := &params.ChainConfig{HomesteadBlock: big.NewInt(1150000)}
config := &params.ChainConfig{}

for name, test := range tests {
number := new(big.Int).Sub(test.CurrentBlocknumber, big.NewInt(1))
Expand Down Expand Up @@ -106,7 +106,6 @@ func TestDifficultyCalculators(t *testing.T) {
u256Fn func(time uint64, parent *types.Header) *big.Int
}{
{FrontierDifficultyCalulator, CalcDifficultyFrontierU256},
{HomesteadDifficultyCalulator, CalcDifficultyHomesteadU256},
{DynamicDifficultyCalculator(bombDelay), MakeDifficultyCalculatorU256(bombDelay)},
} {
time := header.Time() + timeDelta
Expand Down Expand Up @@ -145,18 +144,6 @@ func BenchmarkDifficultyCalculator(b *testing.B) {
CalcDifficultyFrontierU256(1000014, h)
}
})
b.Run("big-homestead", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
calcDifficultyHomestead(1000014, h)
}
})
b.Run("u256-homestead", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
CalcDifficultyHomesteadU256(1000014, h)
}
})
b.Run("big-generic", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Expand Down
56 changes: 2 additions & 54 deletions consensus/blake3pow/difficulty.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package blake3pow
import (
"math/big"

"github.com/holiman/uint256"
"github.com/dominant-strategies/go-quai/core/types"
"github.com/holiman/uint256"
)

const (
Expand Down Expand Up @@ -60,60 +60,8 @@ func CalcDifficultyFrontierU256(time uint64, parent *types.Header) *big.Int {
return pDiff.ToBig()
}

// CalcDifficultyHomesteadU256 is the difficulty adjustment algorithm. It returns
// the difficulty that a new block should have when created at time given the
// parent block's time and difficulty. The calculation uses the Homestead rules.
func CalcDifficultyHomesteadU256(time uint64, parent *types.Header) *big.Int {
/*
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2.md
Algorithm:
block_diff = pdiff + pdiff / 2048 * max(1 - (time - ptime) / 10, -99) + 2 ^ int((num / 100000) - 2))
Our modification, to use unsigned ints:
block_diff = pdiff - pdiff / 2048 * max((time - ptime) / 10 - 1, 99) + 2 ^ int((num / 100000) - 2))
Where:
- pdiff = parent.difficulty
- ptime = parent.time
- time = block.timestamp
- num = block.number
*/

pDiff, _ := uint256.FromBig(parent.Difficulty()) // pDiff: pdiff
adjust := pDiff.Clone()
adjust.Rsh(adjust, difficultyBoundDivisor) // adjust: pDiff / 2048

x := (time - parent.Time()) / 10 // (time - ptime) / 10)
var neg = true
if x == 0 {
x = 1
neg = false
} else if x >= 100 {
x = 99
} else {
x = x - 1
}
z := new(uint256.Int).SetUint64(x)
adjust.Mul(adjust, z) // adjust: (pdiff / 2048) * max((time - ptime) / 10 - 1, 99)
if neg {
pDiff.Sub(pDiff, adjust) // pdiff - pdiff / 2048 * max((time - ptime) / 10 - 1, 99)
} else {
pDiff.Add(pDiff, adjust) // pdiff + pdiff / 2048 * max((time - ptime) / 10 - 1, 99)
}
if pDiff.LtUint64(minimumDifficulty) {
pDiff.SetUint64(minimumDifficulty)
}
// for the exponential factor, a.k.a "the bomb"
// diff = diff + 2^(periodCount - 2)
if periodCount := (1 + parent.Number().Uint64()) / expDiffPeriodUint; periodCount > 1 {
expFactor := adjust.Lsh(adjust.SetOne(), uint(periodCount-2))
pDiff.Add(pDiff, expFactor)
}
return pDiff.ToBig()
}

// MakeDifficultyCalculatorU256 creates a difficultyCalculator with the given bomb-delay.
// the difficulty is calculated with Byzantium rules, which differs from Homestead in
// the difficulty is calculated with Byzantium rules, which differs in
// how uncles affect the calculation
func MakeDifficultyCalculatorU256(bombDelay *big.Int) func(time uint64, parent *types.Header) *big.Int {
// Note, the calculations below looks at the parent number, which is 1 below
Expand Down
1 change: 0 additions & 1 deletion consensus/misc/eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
func copyConfig(original *params.ChainConfig) *params.ChainConfig {
return &params.ChainConfig{
ChainID: original.ChainID,
HomesteadBlock: original.HomesteadBlock,
DAOForkBlock: original.DAOForkBlock,
DAOForkSupport: original.DAOForkSupport,
EIP150Block: original.EIP150Block,
Expand Down
3 changes: 1 addition & 2 deletions consensus/misc/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ func VerifyForkHashes(config *params.ChainConfig, header *types.Header, uncle bo
if uncle {
return nil
}
// If the homestead reprice hash is set, validate it
if config.EIP150Block != nil && config.EIP150Block.Cmp(header.Number()) == 0 {
if config.EIP150Hash != (common.Hash{}) && config.EIP150Hash != header.Hash() {
return fmt.Errorf("homestead gas reprice fork: have 0x%x, want 0x%x", header.Hash(), config.EIP150Hash)
return fmt.Errorf("gas reprice fork: have 0x%x, want 0x%x", header.Hash(), config.EIP150Hash)
}
}
// All ok, return
Expand Down
3 changes: 0 additions & 3 deletions core/forkid/forkid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ func TestCreation(t *testing.T) {
[]testcase{
{0, ID{Hash: checksumToBytes(0xfc64ec04), Next: 1150000}}, // Unsynced
{1149999, ID{Hash: checksumToBytes(0xfc64ec04), Next: 1150000}}, // Last Frontier block
{1150000, ID{Hash: checksumToBytes(0x97c2c34c), Next: 1920000}}, // First Homestead block
{1919999, ID{Hash: checksumToBytes(0x97c2c34c), Next: 1920000}}, // Last Homestead block
{1920000, ID{Hash: checksumToBytes(0x91d1f948), Next: 2463000}}, // First DAO block
{2462999, ID{Hash: checksumToBytes(0x91d1f948), Next: 2463000}}, // Last DAO block
{2463000, ID{Hash: checksumToBytes(0x7a64da13), Next: 2675000}}, // First Tangerine block
Expand All @@ -72,7 +70,6 @@ func TestCreation(t *testing.T) {
params.GardenChainConfig,
params.GardenGenesisHash,
[]testcase{
{0, ID{Hash: checksumToBytes(0x30c7ddbc), Next: 10}}, // Unsynced, last Frontier, Homestead and first Tangerine block
{9, ID{Hash: checksumToBytes(0x30c7ddbc), Next: 10}}, // Last Tangerine block
{10, ID{Hash: checksumToBytes(0x63760190), Next: 1700000}}, // First Spurious block
{1699999, ID{Hash: checksumToBytes(0x63760190), Next: 1700000}}, // Last Spurious block
Expand Down
1 change: 0 additions & 1 deletion core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ func TestStateProcessorErrors(t *testing.T) {
var (
config = &params.ChainConfig{
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
Expand Down
7 changes: 3 additions & 4 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ func (result *ExecutionResult) Revert() []byte {
}

// IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation bool, isHomestead, isEIP2028 bool) (uint64, error) {
func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation bool, isEIP2028 bool) (uint64, error) {
// Set the starting gas for the raw transaction
var gas uint64
if isContractCreation && isHomestead {
if isContractCreation {
gas = params.TxGasContractCreation
} else {
gas = params.TxGas
Expand Down Expand Up @@ -304,13 +304,12 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
}
msg := st.msg
sender := vm.AccountRef(msg.From())
homestead := st.evm.ChainConfig().IsHomestead(st.evm.Context.BlockNumber)
istanbul := st.evm.ChainConfig().IsIstanbul(st.evm.Context.BlockNumber)
london := st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber)
contractCreation := msg.To() == nil

// Check clauses 4-5, subtract intrinsic gas if everything is correct
gas, err := IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, homestead, istanbul)
gas, err := IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, istanbul)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return ErrInsufficientFunds
}
// Ensure the transaction has more gas than the basic tx fee.
intrGas, err := IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, pool.istanbul)
intrGas, err := IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, pool.istanbul)
if err != nil {
return err
}
Expand Down
3 changes: 0 additions & 3 deletions core/types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func TestBlockEncoding(t *testing.T) {
check("Size", block.Size(), common.StorageSize(len(blockEnc)))

tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), 50000, big.NewInt(10), nil)
tx1, _ = tx1.WithSignature(HomesteadSigner{}, common.Hex2Bytes("9bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094f8a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b100"))
check("len(Transactions)", len(block.Transactions()), 1)
check("Transactions[0].Hash", block.Transactions()[0].Hash(), tx1.Hash())
ourBlockEnc, err := rlp.EncodeToBytes(&block)
Expand Down Expand Up @@ -92,7 +91,6 @@ func TestEIP1559BlockEncoding(t *testing.T) {
check("BaseFee", block.BaseFee(), new(big.Int).SetUint64(params.InitialBaseFee))

tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), 50000, big.NewInt(10), nil)
tx1, _ = tx1.WithSignature(HomesteadSigner{}, common.Hex2Bytes("9bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094f8a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b100"))

addr := common.HexToAddress("0x0000000000000000000000000000000000000001")
accesses := AccessList{AccessTuple{
Expand Down Expand Up @@ -162,7 +160,6 @@ func TestEIP2718BlockEncoding(t *testing.T) {
GasPrice: big.NewInt(10),
})
sig := common.Hex2Bytes("9bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094f8a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b100")
tx1, _ = tx1.WithSignature(HomesteadSigner{}, sig)

// Create ACL tx.
addr := common.HexToAddress("0x0000000000000000000000000000000000000001")
Expand Down
2 changes: 1 addition & 1 deletion core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func sanityCheckSignature(v *big.Int, r *big.Int, s *big.Int, maybeProtected boo
// must already be equal to the recovery id.
plainV = byte(v.Uint64())
}
if !crypto.ValidateSignatureValues(plainV, r, s, false) {
if !crypto.ValidateSignatureValues(plainV, r, s) {
return ErrInvalidSig
}

Expand Down
12 changes: 6 additions & 6 deletions core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ func (s SignerV1) Sender(tx *Transaction) (common.Address, error) {
}
V, R, S := tx.RawSignatureValues()
// DynamicFee txs are defined to use 0 and 1 as their recovery
// id, add 27 to become equivalent to unprotected Homestead signatures.
// id, add 27 to become equivalent to unprotected signatures.
V = new(big.Int).Add(V, big.NewInt(27))
if tx.ChainId().Cmp(s.chainId) != 0 {
return common.ZeroAddr, ErrInvalidChainId
}
return recoverPlain(s.Hash(tx), R, S, V, true)
return recoverPlain(s.Hash(tx), R, S, V)
}

func (s SignerV1) Equal(s2 Signer) bool {
Expand Down Expand Up @@ -201,7 +201,7 @@ func (s SignerV1) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big.Int
func (s SignerV1) Hash(tx *Transaction) common.Hash {
txTo := tx.To()
var txToBytes []byte
if (txTo == nil) {
if txTo == nil {
txToBytes = []byte{}
} else {
txToBytes = txTo.Bytes()
Expand Down Expand Up @@ -255,13 +255,13 @@ func decodeSignature(sig []byte) (r, s, v *big.Int) {
return r, s, v
}

func recoverPlain(sighash common.Hash, R, S, Vb *big.Int, homestead bool) (common.Address, error) {
func recoverPlain(sighash common.Hash, R, S, Vb *big.Int) (common.Address, error) {
if Vb.BitLen() > 8 {
return common.ZeroAddr, ErrInvalidSig
}
V := byte(Vb.Uint64() - 27)
if !crypto.ValidateSignatureValues(V, R, S, homestead) {
return common.ZeroAddr, ErrInvalidSig
if !crypto.ValidateSignatureValues(V, R, S) {
return common.Address{}, ErrInvalidSig
}
// encode the signature in uncompressed format
r, s := R.Bytes(), S.Bytes()
Expand Down
1 change: 0 additions & 1 deletion core/types/transaction_signing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func TestEIP155ChainId(t *testing.T) {
}

tx = NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil)
tx, err = SignTx(tx, HomesteadSigner{}, key)
if err != nil {
t.Fatal(err)
}
Expand Down
46 changes: 0 additions & 46 deletions core/types/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ var (
big.NewInt(1),
common.FromHex("5544"),
).WithSignature(
HomesteadSigner{},
common.Hex2Bytes("98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a301"),
)

Expand Down Expand Up @@ -81,16 +80,6 @@ func TestDecodeEmptyTypedTx(t *testing.T) {
}
}

func TestTransactionSigHash(t *testing.T) {
var homestead HomesteadSigner
if homestead.Hash(emptyTx) != common.HexToHash("c775b99e7ad12f50d819fcd602390467e28141316969f4b57f0626f74fe3b386") {
t.Errorf("empty transaction hash mismatch, got %x", emptyTx.Hash())
}
if homestead.Hash(rightvrsTx) != common.HexToHash("fe7a79529ed5f7c3375d06b26b186a8644e0e16c373d7a12be41c62d6042b77a") {
t.Errorf("RightVRS transaction hash mismatch, got %x", rightvrsTx.Hash())
}
}

func TestTransactionEncode(t *testing.T) {
txb, err := rlp.EncodeToBytes(rightvrsTx)
if err != nil {
Expand Down Expand Up @@ -226,39 +215,6 @@ func defaultTestKey() (*ecdsa.PrivateKey, common.Address) {
return key, addr
}

func TestRecipientEmpty(t *testing.T) {
_, addr := defaultTestKey()
tx, err := decodeTx(common.Hex2Bytes("f8498080808080011ca09b16de9d5bdee2cf56c28d16275a4da68cd30273e2525f3959f5d62557489921a0372ebd8fb3345f7db7b5a86d42e24d36e983e259b0664ceb8c227ec9af572f3d"))
if err != nil {
t.Fatal(err)
}

from, err := Sender(HomesteadSigner{}, tx)
if err != nil {
t.Fatal(err)
}
if addr != from {
t.Fatal("derived address doesn't match")
}
}

func TestRecipientNormal(t *testing.T) {
_, addr := defaultTestKey()

tx, err := decodeTx(common.Hex2Bytes("f85d80808094000000000000000000000000000000000000000080011ca0527c0d8f5c63f7b9f41324a7c8a563ee1190bcbf0dac8ab446291bdbf32f5c79a0552c4ef0a09a04395074dab9ed34d3fbfb843c2f2546cc30fe89ec143ca94ca6"))
if err != nil {
t.Fatal(err)
}

from, err := Sender(HomesteadSigner{}, tx)
if err != nil {
t.Fatal(err)
}
if addr != from {
t.Fatal("derived address doesn't match")
}
}

func TestTransactionPriceNonceSortLegacy(t *testing.T) {
testTransactionPriceNonceSort(t, nil)
}
Expand Down Expand Up @@ -365,8 +321,6 @@ func TestTransactionTimeSort(t *testing.T) {
for i := 0; i < len(keys); i++ {
keys[i], _ = crypto.GenerateKey()
}
signer := HomesteadSigner{}

// Generate a batch of transactions with overlapping prices, but different creation times
groups := map[common.Address]Transactions{}
for start, key := range keys {
Expand Down
4 changes: 2 additions & 2 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ func (c *ecrecover) Run(input []byte) ([]byte, error) {
s := new(big.Int).SetBytes(input[96:128])
v := input[63] - 27

// tighter sig s values input homestead only apply to tx sigs
if !allZero(input[32:63]) || !crypto.ValidateSignatureValues(v, r, s, false) {
// tighter sig s values input only apply to tx sigs
if !allZero(input[32:63]) || !crypto.ValidateSignatureValues(v, r, s) {
return nil, nil
}
// We must make sure not to modify the 'input', so placing the 'v' along with
Expand Down
Loading

0 comments on commit 171e5a4

Please sign in to comment.