@@ -18,7 +18,6 @@ package vm
1818
1919import (
2020 "errors"
21- "fmt"
2221 "math/big"
2322
2423 "github.com/ethereum/go-ethereum/common"
3534 errReturnDataOutOfBounds = errors .New ("evm: return data out of bounds" )
3635 errExecutionReverted = errors .New ("evm: execution reverted" )
3736 errMaxCodeSizeExceeded = errors .New ("evm: max code size exceeded" )
37+ errInvalidJump = errors .New ("evm: invalid jump destination" )
3838)
3939
4040func opAdd (pc * uint64 , interpreter * EVMInterpreter , contract * Contract , memory * Memory , stack * Stack ) ([]byte , error ) {
@@ -405,7 +405,7 @@ func opSha3(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory
405405}
406406
407407func opAddress (pc * uint64 , interpreter * EVMInterpreter , contract * Contract , memory * Memory , stack * Stack ) ([]byte , error ) {
408- stack .push (contract .Address ().Big ( ))
408+ stack .push (interpreter . intPool . get (). SetBytes ( contract .Address ().Bytes () ))
409409 return nil , nil
410410}
411411
@@ -416,12 +416,12 @@ func opBalance(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memo
416416}
417417
418418func opOrigin (pc * uint64 , interpreter * EVMInterpreter , contract * Contract , memory * Memory , stack * Stack ) ([]byte , error ) {
419- stack .push (interpreter .evm .Origin .Big ( ))
419+ stack .push (interpreter .intPool . get (). SetBytes ( interpreter . evm .Origin .Bytes () ))
420420 return nil , nil
421421}
422422
423423func opCaller (pc * uint64 , interpreter * EVMInterpreter , contract * Contract , memory * Memory , stack * Stack ) ([]byte , error ) {
424- stack .push (contract .Caller ().Big ( ))
424+ stack .push (interpreter . intPool . get (). SetBytes ( contract .Caller ().Bytes () ))
425425 return nil , nil
426426}
427427
@@ -467,7 +467,7 @@ func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, contract *Contrac
467467 )
468468 defer interpreter .intPool .put (memOffset , dataOffset , length , end )
469469
470- if end .BitLen () > 64 || uint64 (len (interpreter .returnData )) < end .Uint64 () {
470+ if ! end .IsUint64 () || uint64 (len (interpreter .returnData )) < end .Uint64 () {
471471 return nil , errReturnDataOutOfBounds
472472 }
473473 memory .Set (memOffset .Uint64 (), length .Uint64 (), interpreter .returnData [dataOffset .Uint64 ():end .Uint64 ()])
@@ -572,7 +572,7 @@ func opBlockhash(pc *uint64, interpreter *EVMInterpreter, contract *Contract, me
572572}
573573
574574func opCoinbase (pc * uint64 , interpreter * EVMInterpreter , contract * Contract , memory * Memory , stack * Stack ) ([]byte , error ) {
575- stack .push (interpreter .evm .Coinbase .Big ( ))
575+ stack .push (interpreter .intPool . get (). SetBytes ( interpreter . evm .Coinbase .Bytes () ))
576576 return nil , nil
577577}
578578
@@ -645,8 +645,7 @@ func opSstore(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memor
645645func opJump (pc * uint64 , interpreter * EVMInterpreter , contract * Contract , memory * Memory , stack * Stack ) ([]byte , error ) {
646646 pos := stack .pop ()
647647 if ! contract .validJumpdest (pos ) {
648- nop := contract .GetOp (pos .Uint64 ())
649- return nil , fmt .Errorf ("invalid jump destination (%v) %v" , nop , pos )
648+ return nil , errInvalidJump
650649 }
651650 * pc = pos .Uint64 ()
652651
@@ -658,8 +657,7 @@ func opJumpi(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory
658657 pos , cond := stack .pop (), stack .pop ()
659658 if cond .Sign () != 0 {
660659 if ! contract .validJumpdest (pos ) {
661- nop := contract .GetOp (pos .Uint64 ())
662- return nil , fmt .Errorf ("invalid jump destination (%v) %v" , nop , pos )
660+ return nil , errInvalidJump
663661 }
664662 * pc = pos .Uint64 ()
665663 } else {
@@ -711,7 +709,7 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memor
711709 } else if suberr != nil && suberr != ErrCodeStoreOutOfGas {
712710 stack .push (interpreter .intPool .getZero ())
713711 } else {
714- stack .push (addr .Big ( ))
712+ stack .push (interpreter . intPool . get (). SetBytes ( addr .Bytes () ))
715713 }
716714 contract .Gas += returnGas
717715 interpreter .intPool .put (value , offset , size )
@@ -739,7 +737,7 @@ func opCreate2(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memo
739737 if suberr != nil {
740738 stack .push (interpreter .intPool .getZero ())
741739 } else {
742- stack .push (addr .Big ( ))
740+ stack .push (interpreter . intPool . get (). SetBytes ( addr .Bytes () ))
743741 }
744742 contract .Gas += returnGas
745743 interpreter .intPool .put (endowment , offset , size , salt )
@@ -912,6 +910,21 @@ func makeLog(size int) executionFunc {
912910 }
913911}
914912
913+ // opPush1 is a specialized version of pushN
914+ func opPush1 (pc * uint64 , interpreter * EVMInterpreter , contract * Contract , memory * Memory , stack * Stack ) ([]byte , error ) {
915+ var (
916+ codeLen = uint64 (len (contract .Code ))
917+ integer = interpreter .intPool .get ()
918+ )
919+ * pc += 1
920+ if * pc < codeLen {
921+ stack .push (integer .SetUint64 (uint64 (contract .Code [* pc ])))
922+ } else {
923+ stack .push (integer .SetUint64 (0 ))
924+ }
925+ return nil , nil
926+ }
927+
915928// make push instruction function
916929func makePush (size uint64 , pushByteSize int ) executionFunc {
917930 return func (pc * uint64 , interpreter * EVMInterpreter , contract * Contract , memory * Memory , stack * Stack ) ([]byte , error ) {
0 commit comments