diff --git a/accounts/abi/bind/auth.go b/accounts/abi/bind/auth.go index 2fa2c150736..d2dda5a15c4 100644 --- a/accounts/abi/bind/auth.go +++ b/accounts/abi/bind/auth.go @@ -24,7 +24,6 @@ import ( "github.com/ledgerwatch/erigon/common" "github.com/ledgerwatch/erigon/core/types" "github.com/ledgerwatch/erigon/crypto" - "github.com/ledgerwatch/log/v3" ) // ErrNoChainID is returned whenever the user failed to specify a chain id. @@ -33,29 +32,6 @@ var ErrNoChainID = errors.New("no chain id specified") // ErrNotAuthorized is returned when an account is not properly unlocked. var ErrNotAuthorized = errors.New("not authorized to sign this account") -// NewKeyedTransactor is a utility method to easily create a transaction signer -// from a single private key. -// -// Deprecated: Use NewKeyedTransactorWithChainID instead. -func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts { - log.Warn("WARNING: NewKeyedTransactor has been deprecated in favour of NewKeyedTransactorWithChainID") - keyAddr := crypto.PubkeyToAddress(key.PublicKey) - signer := types.LatestSignerForChainID(nil) - return &TransactOpts{ - From: keyAddr, - Signer: func(address common.Address, tx types.Transaction) (types.Transaction, error) { - if address != keyAddr { - return nil, ErrNotAuthorized - } - signature, err := crypto.Sign(tx.SigningHash(nil).Bytes(), key) - if err != nil { - return nil, err - } - return tx.WithSignature(*signer, signature) - }, - } -} - // NewKeyedTransactorWithChainID is a utility method to easily create a transaction signer // from a single private key. func NewKeyedTransactorWithChainID(key *ecdsa.PrivateKey, chainID *big.Int) (*TransactOpts, error) { diff --git a/cmd/pics/state.go b/cmd/pics/state.go index 75cd63cd42a..fd91148acc2 100644 --- a/cmd/pics/state.go +++ b/cmd/pics/state.go @@ -288,9 +288,18 @@ func initialState1() error { contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackend.Close() - transactOpts := bind.NewKeyedTransactor(key) - transactOpts1 := bind.NewKeyedTransactor(key1) - transactOpts2 := bind.NewKeyedTransactor(key2) + transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + if err != nil { + panic(err) + } + transactOpts1, err := bind.NewKeyedTransactorWithChainID(key1, m.ChainConfig.ChainID) + if err != nil { + panic(err) + } + transactOpts2, err := bind.NewKeyedTransactorWithChainID(key2, m.ChainConfig.ChainID) + if err != nil { + panic(err) + } var tokenContract *contracts.Token // We generate the blocks without plainstant because it's not supported in core.GenerateChain diff --git a/core/state/database_test.go b/core/state/database_test.go index b29b3a966a0..c7f69c8806e 100644 --- a/core/state/database_test.go +++ b/core/state/database_test.go @@ -72,12 +72,12 @@ func TestCreate2Revive(t *testing.T) { contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackend.Close() - transactOpts := bind.NewKeyedTransactor(key) + transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOpts.GasLimit = 1000000 var contractAddress common.Address var revive *contracts.Revive - var err error // Change this address whenever you make any changes in the code of the revive contract in // contracts/revive.sol var create2address = common.HexToAddress("e70fd65144383e1189bd710b1e23b61e26315ff4") @@ -263,12 +263,13 @@ func TestCreate2Polymorth(t *testing.T) { contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackend.Close() - transactOpts := bind.NewKeyedTransactor(key) + transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOpts.GasLimit = 1000000 var contractAddress common.Address var poly *contracts.Poly - var err error + // Change this address whenever you make any changes in the code of the poly contract in // contracts/poly.sol var create2address = common.HexToAddress("c66aa74c220476f244b7f45897a124d1a01ca8a8") @@ -509,12 +510,12 @@ func TestReorgOverSelfDestruct(t *testing.T) { contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackend.Close() - transactOpts := bind.NewKeyedTransactor(key) + transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOpts.GasLimit = 1000000 var contractAddress common.Address var selfDestruct *contracts.Selfdestruct - var err error // Here we generate 3 blocks, two of which (the one with "Change" invocation and "Destruct" invocation will be reverted during the reorg) chain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 3, func(i int, block *core.BlockGen) { @@ -549,7 +550,8 @@ func TestReorgOverSelfDestruct(t *testing.T) { // Create a longer chain, with 4 blocks (with higher total difficulty) that reverts the change of stroage self-destruction of the contract contractBackendLonger := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackendLonger.Close() - transactOptsLonger := bind.NewKeyedTransactor(key) + transactOptsLonger, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOptsLonger.GasLimit = 1000000 longerChain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 4, func(i int, block *core.BlockGen) { @@ -658,12 +660,12 @@ func TestReorgOverStateChange(t *testing.T) { contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackend.Close() - transactOpts := bind.NewKeyedTransactor(key) + transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOpts.GasLimit = 1000000 var contractAddress common.Address var selfDestruct *contracts.Selfdestruct - var err error // Here we generate 3 blocks, two of which (the one with "Change" invocation and "Destruct" invocation will be reverted during the reorg) chain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 2, func(i int, block *core.BlockGen) { @@ -692,7 +694,8 @@ func TestReorgOverStateChange(t *testing.T) { // Create a longer chain, with 4 blocks (with higher total difficulty) that reverts the change of stroage self-destruction of the contract contractBackendLonger := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackendLonger.Close() - transactOptsLonger := bind.NewKeyedTransactor(key) + transactOptsLonger, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOptsLonger.GasLimit = 1000000 longerChain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 3, func(i int, block *core.BlockGen) { var tx types.Transaction @@ -813,10 +816,8 @@ func TestCreateOnExistingStorage(t *testing.T) { contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackend.Close() - transactOpts, err := bind.NewKeyedTransactorWithChainID(key, gspec.Config.ChainID) - if err != nil { - t.Fatal(err) - } + transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOpts.GasLimit = 1000000 var contractAddress common.Address @@ -943,12 +944,12 @@ func TestEip2200Gas(t *testing.T) { contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackend.Close() - transactOpts := bind.NewKeyedTransactor(key) + transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOpts.GasLimit = 1000000 var contractAddress common.Address var selfDestruct *contracts.Selfdestruct - var err error // Here we generate 1 block with 2 transactions, first creates a contract with some initial values in the // It activates the SSTORE pricing rules specific to EIP-2200 (istanbul) @@ -1035,12 +1036,12 @@ func TestWrongIncarnation(t *testing.T) { contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackend.Close() - transactOpts := bind.NewKeyedTransactor(key) + transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOpts.GasLimit = 1000000 var contractAddress common.Address var changer *contracts.Changer - var err error chain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 2, func(i int, block *core.BlockGen) { var tx types.Transaction @@ -1151,9 +1152,9 @@ func TestWrongIncarnation2(t *testing.T) { contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackend.Close() - transactOpts := bind.NewKeyedTransactor(key) + transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOpts.GasLimit = 1000000 - var err error var contractAddress common.Address @@ -1190,7 +1191,8 @@ func TestWrongIncarnation2(t *testing.T) { // Create a longer chain, with 4 blocks (with higher total difficulty) that reverts the change of stroage self-destruction of the contract contractBackendLonger := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) - transactOptsLonger := bind.NewKeyedTransactor(key) + transactOptsLonger, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOptsLonger.GasLimit = 1000000 longerChain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 3, func(i int, block *core.BlockGen) { var tx types.Transaction @@ -1402,13 +1404,13 @@ func TestRecreateAndRewind(t *testing.T) { m := stages.MockWithGenesis(t, gspec, key) contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackend.Close() - transactOpts := bind.NewKeyedTransactor(key) + transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOpts.GasLimit = 1000000 var revive *contracts.Revive2 var phoenix *contracts.Phoenix var reviveAddress common.Address var phoenixAddress common.Address - var err error chain, err1 := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 4, func(i int, block *core.BlockGen) { var tx types.Transaction @@ -1470,7 +1472,8 @@ func TestRecreateAndRewind(t *testing.T) { contractBackendLonger := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackendLonger.Close() - transactOptsLonger := bind.NewKeyedTransactor(key) + transactOptsLonger, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) transactOptsLonger.GasLimit = 1000000 longerChain, err1 := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 5, func(i int, block *core.BlockGen) { var tx types.Transaction diff --git a/tests/statedb_chain_test.go b/tests/statedb_chain_test.go index a578c46e23f..b15b49c03c5 100644 --- a/tests/statedb_chain_test.go +++ b/tests/statedb_chain_test.go @@ -22,6 +22,7 @@ import ( "github.com/holiman/uint256" "github.com/ledgerwatch/erigon/ethdb/olddb" + "github.com/stretchr/testify/require" "github.com/ledgerwatch/erigon/accounts/abi/bind" "github.com/ledgerwatch/erigon/accounts/abi/bind/backends" @@ -64,11 +65,11 @@ func TestSelfDestructReceive(t *testing.T) { contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit) defer contractBackend.Close() - transactOpts := bind.NewKeyedTransactor(key) + transactOpts, err := bind.NewKeyedTransactorWithChainID(key, m.ChainConfig.ChainID) + require.NoError(t, err) var contractAddress common.Address var selfDestructorContract *contracts.SelfDestructor - var err error // There are two blocks // First block deploys a contract, then makes it self-destruct, and then sends 1 wei to the address of the contract, diff --git a/tests/statedb_insert_chain_transaction_test.go b/tests/statedb_insert_chain_transaction_test.go index 0d228d5d630..2a99d518a61 100644 --- a/tests/statedb_insert_chain_transaction_test.go +++ b/tests/statedb_insert_chain_transaction_test.go @@ -705,7 +705,11 @@ func getGenesis(funds ...*big.Int) initialData { for _, key := range keys { addr := crypto.PubkeyToAddress(key.PublicKey) addresses = append(addresses, addr) - transactOpts = append(transactOpts, bind.NewKeyedTransactor(key)) + to, err := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1)) + if err != nil { + panic(err) + } + transactOpts = append(transactOpts, to) allocs[addr] = core.GenesisAccount{Balance: accountFunds} }