diff --git a/common/u256/big.go b/common/u256/big.go index c43f2d896ca3330860d6d9d2b2d435a518bedfcb..9e0b74c04c16ada5126c6fd6ddce4afb57a7a3b5 100644 --- a/common/u256/big.go +++ b/common/u256/big.go @@ -29,37 +29,3 @@ var ( Num32 = uint256.NewInt().SetUint64(32) Num35 = uint256.NewInt().SetUint64(35) ) - -func SetBytes(z *uint256.Int, buf []byte, length int) *uint256.Int { - if len(buf) == length { - return z.SetBytes(buf) - } else { - return SetBytesRightPadded(z, buf, length) - } -} - -func SetBytesRightPadded(z *uint256.Int, buf []byte, length int) *uint256.Int { - var d uint64 - k := 0 - s := uint64(0) - i := length - st := len(buf) - z[0], z[1], z[2], z[3] = 0, 0, 0, 0 - for ; i > 0; i-- { - if i-1 < st { - d |= uint64(buf[i-1]) << s - } - if s += 8; s == 64 { - z[k] = d - k++ - s, d = 0, 0 - if k >= len(z) { - break - } - } - } - if k < len(z) { - z[k] = d - } - return z -} diff --git a/common/u256/big_test.go b/common/u256/big_test.go deleted file mode 100644 index 2ee49f2583d58c27cb4ad8e85dc489dcdb5a86e3..0000000000000000000000000000000000000000 --- a/common/u256/big_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package u256 - -import ( - "testing" - - "github.com/davecgh/go-spew/spew" - "github.com/holiman/uint256" - - "github.com/ledgerwatch/turbo-geth/common" -) - -func TestRightPadding(t *testing.T) { - bs := []byte{0, 1, 0x10, 0x11, 0x20, 0xfa, 0xff} - - for n := 1; n <= 4; n++ { - for l := n; l <= 4; l++ { - slice := make([]byte, n) - for _, b := range bs { - for i := range slice { - slice[i] = b - - withPadding := setUint256WithPadding(slice, l) - withoutPadding := setUint256(slice, l) - if withoutPadding.Cmp(withPadding) != 0 { - t.Fatalf("not equal n=%d l=%d slice=%v\nGot\t\t%v\n!=\nExpect\t%v(%v)", - n, l, slice, withoutPadding.Bytes32(), withPadding.Bytes32(), spew.Sdump(withPadding)) - } - } - } - } - } -} - -func setUint256WithPadding(slice []byte, l int) *uint256.Int { - return new(uint256.Int).SetBytes(common.RightPadBytes(slice, l)) -} - -func setUint256(slice []byte, l int) *uint256.Int { - return SetBytesRightPadded(new(uint256.Int), slice, l) -} diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 47020160343ff655b222aad930dc7292dbddfdbd..9d8824c86e9cf463ce028ba8581b85d76843bbac 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -21,7 +21,6 @@ import ( "golang.org/x/crypto/sha3" "github.com/ledgerwatch/turbo-geth/common" - "github.com/ledgerwatch/turbo-geth/common/u256" "github.com/ledgerwatch/turbo-geth/core/types" "github.com/ledgerwatch/turbo-geth/params" ) @@ -831,7 +830,9 @@ func makePush(size uint64, pushByteSize int) executionFunc { } integer := new(uint256.Int) - callContext.stack.Push(u256.SetBytes(integer, callContext.contract.Code[startMin:endMin], pushByteSize)) + // No need to right-pad: if we're at the end of the code, the execution will stop. + // So it doesn't matter what we push onto the stack. + callContext.stack.Push(integer.SetBytes(callContext.contract.Code[startMin:endMin])) *pc += size return nil, nil