mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-11 23:44:27 +00:00
parent
fc6c692097
commit
3211c8ef2f
3 changed files with 87 additions and 8 deletions
|
|
@ -979,12 +979,13 @@ func makePush(size uint64, pushByteSize int) executionFunc {
|
||||||
start = min(codeLen, int(*pc+1))
|
start = min(codeLen, int(*pc+1))
|
||||||
end = min(codeLen, start+pushByteSize)
|
end = min(codeLen, start+pushByteSize)
|
||||||
)
|
)
|
||||||
scope.Stack.push(new(uint256.Int).SetBytes(
|
a := new(uint256.Int).SetBytes(scope.Contract.Code[start:end])
|
||||||
common.RightPadBytes(
|
|
||||||
scope.Contract.Code[start:end],
|
// Missing bytes: pushByteSize - len(pushData)
|
||||||
pushByteSize,
|
if missing := pushByteSize - (end - start); missing > 0 {
|
||||||
)),
|
a.Lsh(a, uint(8*missing))
|
||||||
)
|
}
|
||||||
|
scope.Stack.push(a)
|
||||||
*pc += size
|
*pc += size
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -947,3 +947,75 @@ func TestOpCLZ(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestPush sanity-checks how code with immediates are handled when the code size is
|
||||||
|
// smaller than the size of the immediate.
|
||||||
|
func TestPush(t *testing.T) {
|
||||||
|
code := common.FromHex("0011223344556677889900aabbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a19181716151413121")
|
||||||
|
|
||||||
|
push32 := makePush(32, 32)
|
||||||
|
|
||||||
|
scope := &ScopeContext{
|
||||||
|
Memory: nil,
|
||||||
|
Stack: newstack(),
|
||||||
|
Contract: &Contract{
|
||||||
|
Code: code,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for i, want := range []string{
|
||||||
|
"0x11223344556677889900aabbccddeeff0102030405060708090a0b0c0d0e0ff1",
|
||||||
|
"0x223344556677889900aabbccddeeff0102030405060708090a0b0c0d0e0ff1e1",
|
||||||
|
"0x3344556677889900aabbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1",
|
||||||
|
"0x44556677889900aabbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1",
|
||||||
|
"0x556677889900aabbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1",
|
||||||
|
"0x6677889900aabbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a1",
|
||||||
|
"0x77889900aabbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a191",
|
||||||
|
"0x889900aabbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a19181",
|
||||||
|
"0x9900aabbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a1918171",
|
||||||
|
"0xaabbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a191817161",
|
||||||
|
"0xaabbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a19181716151",
|
||||||
|
"0xbbccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a1918171615141",
|
||||||
|
"0xccddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a191817161514131",
|
||||||
|
"0xddeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a19181716151413121",
|
||||||
|
"0xeeff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a1918171615141312100",
|
||||||
|
"0xff0102030405060708090a0b0c0d0e0ff1e1d1c1b1a191817161514131210000",
|
||||||
|
"0x102030405060708090a0b0c0d0e0ff1e1d1c1b1a19181716151413121000000",
|
||||||
|
"0x2030405060708090a0b0c0d0e0ff1e1d1c1b1a1918171615141312100000000",
|
||||||
|
"0x30405060708090a0b0c0d0e0ff1e1d1c1b1a191817161514131210000000000",
|
||||||
|
"0x405060708090a0b0c0d0e0ff1e1d1c1b1a19181716151413121000000000000",
|
||||||
|
"0x5060708090a0b0c0d0e0ff1e1d1c1b1a1918171615141312100000000000000",
|
||||||
|
"0x60708090a0b0c0d0e0ff1e1d1c1b1a191817161514131210000000000000000",
|
||||||
|
"0x708090a0b0c0d0e0ff1e1d1c1b1a19181716151413121000000000000000000",
|
||||||
|
"0x8090a0b0c0d0e0ff1e1d1c1b1a1918171615141312100000000000000000000",
|
||||||
|
"0x90a0b0c0d0e0ff1e1d1c1b1a191817161514131210000000000000000000000",
|
||||||
|
"0xa0b0c0d0e0ff1e1d1c1b1a19181716151413121000000000000000000000000",
|
||||||
|
"0xb0c0d0e0ff1e1d1c1b1a1918171615141312100000000000000000000000000",
|
||||||
|
"0xc0d0e0ff1e1d1c1b1a191817161514131210000000000000000000000000000",
|
||||||
|
"0xd0e0ff1e1d1c1b1a19181716151413121000000000000000000000000000000",
|
||||||
|
"0xe0ff1e1d1c1b1a1918171615141312100000000000000000000000000000000",
|
||||||
|
"0xff1e1d1c1b1a191817161514131210000000000000000000000000000000000",
|
||||||
|
"0xf1e1d1c1b1a19181716151413121000000000000000000000000000000000000",
|
||||||
|
"0xe1d1c1b1a1918171615141312100000000000000000000000000000000000000",
|
||||||
|
"0xd1c1b1a191817161514131210000000000000000000000000000000000000000",
|
||||||
|
"0xc1b1a19181716151413121000000000000000000000000000000000000000000",
|
||||||
|
"0xb1a1918171615141312100000000000000000000000000000000000000000000",
|
||||||
|
"0xa191817161514131210000000000000000000000000000000000000000000000",
|
||||||
|
"0x9181716151413121000000000000000000000000000000000000000000000000",
|
||||||
|
"0x8171615141312100000000000000000000000000000000000000000000000000",
|
||||||
|
"0x7161514131210000000000000000000000000000000000000000000000000000",
|
||||||
|
"0x6151413121000000000000000000000000000000000000000000000000000000",
|
||||||
|
"0x5141312100000000000000000000000000000000000000000000000000000000",
|
||||||
|
"0x4131210000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"0x3121000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"0x2100000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"0x0",
|
||||||
|
} {
|
||||||
|
pc := new(uint64)
|
||||||
|
*pc = uint64(i)
|
||||||
|
push32(pc, nil, scope)
|
||||||
|
res := scope.Stack.pop()
|
||||||
|
if have := res.Hex(); have != want {
|
||||||
|
t.Fatalf("case %d, have %v want %v", i, have, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -176,8 +176,11 @@ func (evm *EVM) Run(contract *Contract, input []byte, readOnly bool) (ret []byte
|
||||||
} else if sLen > operation.maxStack {
|
} else if sLen > operation.maxStack {
|
||||||
return nil, &ErrStackOverflow{stackLen: sLen, limit: operation.maxStack}
|
return nil, &ErrStackOverflow{stackLen: sLen, limit: operation.maxStack}
|
||||||
}
|
}
|
||||||
if !contract.UseGas(cost, evm.Config.Tracer, tracing.GasChangeIgnored) {
|
// for tracing: this gas consumption event is emitted below in the debug section.
|
||||||
|
if contract.Gas < cost {
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
|
} else {
|
||||||
|
contract.Gas -= cost
|
||||||
}
|
}
|
||||||
|
|
||||||
if operation.dynamicGas != nil {
|
if operation.dynamicGas != nil {
|
||||||
|
|
@ -206,8 +209,11 @@ func (evm *EVM) Run(contract *Contract, input []byte, readOnly bool) (ret []byte
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrOutOfGas, err)
|
return nil, fmt.Errorf("%w: %v", ErrOutOfGas, err)
|
||||||
}
|
}
|
||||||
if !contract.UseGas(dynamicCost, evm.Config.Tracer, tracing.GasChangeIgnored) {
|
// for tracing: this gas consumption event is emitted below in the debug section.
|
||||||
|
if contract.Gas < dynamicCost {
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
|
} else {
|
||||||
|
contract.Gas -= dynamicCost
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do tracing before memory expansion
|
// Do tracing before memory expansion
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue