Skip to content
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

fix: allow pre-EIP-155 transactions #3157

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/evm/jsonrpc/evmchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (e *EVMChain) gasLimits() *gas.Limits {
func (e *EVMChain) SendTransaction(tx *types.Transaction) error {
e.log.Debugf("SendTransaction(tx=%v)", tx)
chainID := e.ChainID()
if tx.ChainId().Uint64() != uint64(chainID) {
if tx.Protected() && tx.ChainId().Uint64() != uint64(chainID) {
return errors.New("chain ID mismatch")
}
signer, err := e.Signer()
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/core/evm/evmimpl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func applyTransaction(ctx isc.Sandbox) dict.Dict {

emu := createEmulator(ctx)

if tx.ChainId().Uint64() != uint64(emu.BlockchainDB().GetChainID()) {
if tx.Protected() && tx.ChainId().Uint64() != uint64(emu.BlockchainDB().GetChainID()) {
panic(errChainIDMismatch)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vm/core/evm/evmtest/contractInstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (e *EVMContractInstance) buildEthTx(opts []ethCallOptions, fnName string, a

unsignedTx := types.NewTransaction(nonce, e.address, opt.value, opt.gasLimit, opt.gasPrice, callData)

return types.SignTx(unsignedTx, e.chain.signer(), opt.sender)
return types.SignTx(unsignedTx, e.chain.getSigner(), opt.sender)
}

func (e *EVMContractInstance) estimateGas(opts []ethCallOptions, fnName string, args ...interface{}) (uint64, error) {
Expand Down
13 changes: 12 additions & 1 deletion packages/vm/core/evm/evmtest/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ func TestEVMGasPriceMismatch(t *testing.T) {
nonce := storage.chain.getNonce(senderAddress)
unsignedTx := types.NewTransaction(nonce, storage.address, util.Big0, env.maxGasLimit(), gasPrice, callArguments)

tx, err := types.SignTx(unsignedTx, storage.chain.signer(), ethKey)
tx, err := types.SignTx(unsignedTx, storage.chain.getSigner(), ethKey)
require.NoError(t, err)

err = storage.chain.evmChain.SendTransaction(tx)
Expand Down Expand Up @@ -2196,3 +2196,14 @@ func TestDecimalsConversion(t *testing.T) {
)
require.ErrorContains(t, err, "execution reverted")
}

func TestPreEIP155Transaction(t *testing.T) {
env := InitEVM(t)
ethKey, _ := env.Chain.EthereumAccountByIndexWithL2Funds(0)

// set a signer without replay protection
env.setSigner(types.HomesteadSigner{})

// deploy solidity `storage` contract, it should suceeed
env.deployStorageContract(ethKey)
}
12 changes: 9 additions & 3 deletions packages/vm/core/evm/evmtest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type SoloChainEnv struct {
Chain *solo.Chain
evmChainID uint16
evmChain *jsonrpc.EVMChain
signer types.Signer
}

type iscCallOptions struct {
Expand Down Expand Up @@ -70,6 +71,7 @@ func InitEVMWithSolo(t testing.TB, env *solo.Solo) *SoloChainEnv {
Chain: soloChain,
evmChainID: evm.DefaultChainID,
evmChain: soloChain.EVM(),
signer: evmutil.Signer(big.NewInt(int64(evm.DefaultChainID))),
}
}

Expand Down Expand Up @@ -256,8 +258,12 @@ func (e *SoloChainEnv) deployERC20ExampleContract(creator *ecdsa.PrivateKey) *er
return &erc20ContractInstance{e.DeployContract(creator, evmtest.ERC20ExampleContractABI, evmtest.ERC20ExampleContractBytecode)}
}

func (e *SoloChainEnv) signer() types.Signer {
return evmutil.Signer(big.NewInt(int64(e.evmChainID)))
func (e *SoloChainEnv) setSigner(s types.Signer) {
e.signer = s
}

func (e *SoloChainEnv) getSigner() types.Signer {
return e.signer
}

func (e *SoloChainEnv) maxGasLimit() uint64 {
Expand Down Expand Up @@ -291,7 +297,7 @@ func (e *SoloChainEnv) DeployContract(creator *ecdsa.PrivateKey, abiJSON string,

tx, err := types.SignTx(
types.NewContractCreation(nonce, value, gasLimit, e.evmChain.GasPrice(), data),
e.signer(),
e.getSigner(),
creator,
)
require.NoError(e.t, err)
Expand Down