@@ -19,6 +19,7 @@ package core
1919import (
2020 "crypto/ecdsa"
2121 "encoding/binary"
22+ "errors"
2223 "fmt"
2324 "math"
2425 "math/big"
@@ -598,6 +599,63 @@ func TestApplyTransactionWithEVMStateChangeHooks(t *testing.T) {
598599 }
599600}
600601
602+ func TestApplyTransactionWithEVMRejectsValueOverflow (t * testing.T ) {
603+ t .Parallel ()
604+
605+ config := & params.ChainConfig {
606+ ChainID : big .NewInt (1 ),
607+ HomesteadBlock : big .NewInt (0 ),
608+ EIP155Block : big .NewInt (0 ),
609+ EIP158Block : big .NewInt (0 ),
610+ ByzantiumBlock : big .NewInt (0 ),
611+ Ethash : new (params.EthashConfig ),
612+ }
613+ signer := types .LatestSigner (config )
614+ key , err := crypto .HexToECDSA ("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
615+ if err != nil {
616+ t .Fatalf ("Failed to create key: %v" , err )
617+ }
618+ sender := crypto .PubkeyToAddress (key .PublicKey )
619+ recipient := common .HexToAddress ("0x1234567890123456789012345678901234567890" )
620+ tooBigValue := new (big.Int ).Lsh (big .NewInt (1 ), 256 )
621+ hugeBalance := new (big.Int ).Lsh (big .NewInt (1 ), 300 )
622+
623+ db := rawdb .NewMemoryDatabase ()
624+ gspec := & Genesis {
625+ Config : config ,
626+ Alloc : types.GenesisAlloc {
627+ sender : {
628+ Balance : hugeBalance ,
629+ },
630+ },
631+ }
632+ genesis := gspec .MustCommit (db )
633+ blockchain , _ := NewBlockChain (db , nil , gspec , ethash .NewFaker (), vm.Config {})
634+ defer blockchain .Stop ()
635+
636+ statedb , err := blockchain .State ()
637+ if err != nil {
638+ t .Fatalf ("Failed to get state: %v" , err )
639+ }
640+ tx := types .NewTransaction (0 , recipient , tooBigValue , 21000 , big .NewInt (1 ), nil )
641+ signedTx , err := types .SignTx (tx , signer , key )
642+ if err != nil {
643+ t .Fatalf ("Failed to sign tx: %v" , err )
644+ }
645+ msg , err := TransactionToMessage (signedTx , signer , nil , big .NewInt (1 ), nil )
646+ if err != nil {
647+ t .Fatalf ("Failed to build message: %v" , err )
648+ }
649+ vmContext := NewEVMBlockContext (blockchain .CurrentBlock (), blockchain , nil )
650+ evmenv := vm .NewEVM (vmContext , statedb , nil , blockchain .Config (), vm.Config {})
651+ gasPool := new (GasPool ).AddGas (1000000 )
652+ var usedGas uint64
653+ _ , _ , _ , err = ApplyTransactionWithEVM (msg , gasPool , statedb , big .NewInt (1 ), genesis .Hash (), signedTx , & usedGas , evmenv , nil , common.Address {})
654+ if ! errors .Is (err , types .ErrUint256Overflow ) {
655+ t .Fatalf ("expected %v, got %v" , types .ErrUint256Overflow , err )
656+ }
657+ }
658+
601659func TestProcessParentBlockHash (t * testing.T ) {
602660 var (
603661 chainConfig = params .MergedTestChainConfig
0 commit comments