mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 03:10:48 +00:00
core/vm: adapt generated switch to merged in-place stack and gas API
This commit is contained in:
parent
5a2400ddd1
commit
12eb1f1e02
3 changed files with 45 additions and 45 deletions
|
|
@ -510,7 +510,7 @@ func (g *generator) emitFile() {
|
||||||
if isEIP4762 && !contract.IsDeployment && !contract.IsSystemCall {
|
if isEIP4762 && !contract.IsDeployment && !contract.IsSystemCall {
|
||||||
contractAddr := contract.Address()
|
contractAddr := contract.Address()
|
||||||
consumed, wanted := evm.TxContext.AccessEvents.CodeChunksRangeGas(contractAddr, pc, 1, uint64(len(contract.Code)), false, contract.Gas.RegularGas)
|
consumed, wanted := evm.TxContext.AccessEvents.CodeChunksRangeGas(contractAddr, pc, 1, uint64(len(contract.Code)), false, contract.Gas.RegularGas)
|
||||||
contract.UseGas(GasCosts{RegularGas: consumed}, evm.Config.Tracer, tracing.GasChangeWitnessCodeChunk)
|
contract.chargeRegular(consumed, evm.Config.Tracer, tracing.GasChangeWitnessCodeChunk)
|
||||||
if consumed < wanted {
|
if consumed < wanted {
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -279,7 +279,7 @@ func TestExtraEIPs(t *testing.T) {
|
||||||
Origin: diffCaller,
|
Origin: diffCaller,
|
||||||
GasPrice: uint256.NewInt(1),
|
GasPrice: uint256.NewInt(1),
|
||||||
})
|
})
|
||||||
_, _, err := evm.Call(diffCaller, diffContractAddr, nil, NewGasBudget(100000), new(uint256.Int))
|
_, _, err := evm.Call(diffCaller, diffContractAddr, nil, NewGasBudget(100000, 0), new(uint256.Int))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("PUSH0 enabled via ExtraEips failed: %v", err)
|
t.Fatalf("PUSH0 enabled via ExtraEips failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -301,7 +301,7 @@ func runOne(t testing.TB, cfg *params.ChainConfig, merged, useTableLoop bool, co
|
||||||
})
|
})
|
||||||
evm.forceTableLoop = useTableLoop
|
evm.forceTableLoop = useTableLoop
|
||||||
|
|
||||||
ret, leftOver, err := evm.Call(diffCaller, diffContractAddr, input, NewGasBudget(gas), new(uint256.Int))
|
ret, leftOver, err := evm.Call(diffCaller, diffContractAddr, input, NewGasBudget(gas, 0), new(uint256.Int))
|
||||||
errStr := ""
|
errStr := ""
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errStr = err.Error()
|
errStr = err.Error()
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ mainLoop:
|
||||||
if isEIP4762 && !contract.IsDeployment && !contract.IsSystemCall {
|
if isEIP4762 && !contract.IsDeployment && !contract.IsSystemCall {
|
||||||
contractAddr := contract.Address()
|
contractAddr := contract.Address()
|
||||||
consumed, wanted := evm.TxContext.AccessEvents.CodeChunksRangeGas(contractAddr, pc, 1, uint64(len(contract.Code)), false, contract.Gas.RegularGas)
|
consumed, wanted := evm.TxContext.AccessEvents.CodeChunksRangeGas(contractAddr, pc, 1, uint64(len(contract.Code)), false, contract.Gas.RegularGas)
|
||||||
contract.UseGas(GasCosts{RegularGas: consumed}, evm.Config.Tracer, tracing.GasChangeWitnessCodeChunk)
|
contract.chargeRegular(consumed, evm.Config.Tracer, tracing.GasChangeWitnessCodeChunk)
|
||||||
if consumed < wanted {
|
if consumed < wanted {
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
|
|
@ -50,8 +50,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
y.Add(&x, y)
|
y.Add(x, y)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -63,8 +63,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 5
|
contract.Gas.RegularGas -= 5
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
y.Mul(&x, y)
|
y.Mul(x, y)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -76,8 +76,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
y.Sub(&x, y)
|
y.Sub(x, y)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -89,8 +89,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 5
|
contract.Gas.RegularGas -= 5
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
y.Div(&x, y)
|
y.Div(x, y)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -102,8 +102,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 5
|
contract.Gas.RegularGas -= 5
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
y.SDiv(&x, y)
|
y.SDiv(x, y)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -115,8 +115,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 5
|
contract.Gas.RegularGas -= 5
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
y.Mod(&x, y)
|
y.Mod(x, y)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -128,8 +128,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 5
|
contract.Gas.RegularGas -= 5
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
y.SMod(&x, y)
|
y.SMod(x, y)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -141,8 +141,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 8
|
contract.Gas.RegularGas -= 8
|
||||||
x, y, z := scope.Stack.pop(), scope.Stack.pop(), scope.Stack.peek()
|
x, y, z := scope.Stack.pop2Peek1()
|
||||||
z.AddMod(&x, &y, z)
|
z.AddMod(x, y, z)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -154,8 +154,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 8
|
contract.Gas.RegularGas -= 8
|
||||||
x, y, z := scope.Stack.pop(), scope.Stack.pop(), scope.Stack.peek()
|
x, y, z := scope.Stack.pop2Peek1()
|
||||||
z.MulMod(&x, &y, z)
|
z.MulMod(x, y, z)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -167,8 +167,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 5
|
contract.Gas.RegularGas -= 5
|
||||||
back, num := scope.Stack.pop(), scope.Stack.peek()
|
back, num := scope.Stack.pop1Peek1()
|
||||||
num.ExtendSign(num, &back)
|
num.ExtendSign(num, back)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -180,7 +180,7 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
if x.Lt(y) {
|
if x.Lt(y) {
|
||||||
y.SetOne()
|
y.SetOne()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -197,7 +197,7 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
if x.Gt(y) {
|
if x.Gt(y) {
|
||||||
y.SetOne()
|
y.SetOne()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -214,7 +214,7 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
if x.Slt(y) {
|
if x.Slt(y) {
|
||||||
y.SetOne()
|
y.SetOne()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -231,7 +231,7 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
if x.Sgt(y) {
|
if x.Sgt(y) {
|
||||||
y.SetOne()
|
y.SetOne()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -248,7 +248,7 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
if x.Eq(y) {
|
if x.Eq(y) {
|
||||||
y.SetOne()
|
y.SetOne()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -282,8 +282,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
y.And(&x, y)
|
y.And(x, y)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -295,8 +295,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
y.Or(&x, y)
|
y.Or(x, y)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -308,8 +308,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
x, y := scope.Stack.pop(), scope.Stack.peek()
|
x, y := scope.Stack.pop1Peek1()
|
||||||
y.Xor(&x, y)
|
y.Xor(x, y)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -334,8 +334,8 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
th, val := scope.Stack.pop(), scope.Stack.peek()
|
th, val := scope.Stack.pop1Peek1()
|
||||||
val.Byte(&th)
|
val.Byte(th)
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -348,7 +348,7 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
shift, value := scope.Stack.pop(), scope.Stack.peek()
|
shift, value := scope.Stack.pop1Peek1()
|
||||||
if shift.LtUint64(256) {
|
if shift.LtUint64(256) {
|
||||||
value.Lsh(value, uint(shift.Uint64()))
|
value.Lsh(value, uint(shift.Uint64()))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -369,7 +369,7 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
shift, value := scope.Stack.pop(), scope.Stack.peek()
|
shift, value := scope.Stack.pop1Peek1()
|
||||||
if shift.LtUint64(256) {
|
if shift.LtUint64(256) {
|
||||||
value.Rsh(value, uint(shift.Uint64()))
|
value.Rsh(value, uint(shift.Uint64()))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -390,7 +390,7 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 3
|
contract.Gas.RegularGas -= 3
|
||||||
shift, value := scope.Stack.pop(), scope.Stack.peek()
|
shift, value := scope.Stack.pop1Peek1()
|
||||||
if shift.GtUint64(256) {
|
if shift.GtUint64(256) {
|
||||||
if value.Sign() >= 0 {
|
if value.Sign() >= 0 {
|
||||||
value.Clear()
|
value.Clear()
|
||||||
|
|
@ -470,7 +470,7 @@ mainLoop:
|
||||||
return nil, ErrOutOfGas
|
return nil, ErrOutOfGas
|
||||||
}
|
}
|
||||||
contract.Gas.RegularGas -= 2
|
contract.Gas.RegularGas -= 2
|
||||||
scope.Stack.pop()
|
scope.Stack.drop()
|
||||||
pc++
|
pc++
|
||||||
continue mainLoop
|
continue mainLoop
|
||||||
|
|
||||||
|
|
@ -594,8 +594,8 @@ mainLoop:
|
||||||
res, err = nil, errStopToken
|
res, err = nil, errStopToken
|
||||||
break mainLoop
|
break mainLoop
|
||||||
}
|
}
|
||||||
pos := scope.Stack.pop()
|
pos := scope.Stack.pop1()
|
||||||
if !scope.Contract.validJumpdest(&pos) {
|
if !scope.Contract.validJumpdest(pos) {
|
||||||
res, err = nil, ErrInvalidJump
|
res, err = nil, ErrInvalidJump
|
||||||
break mainLoop
|
break mainLoop
|
||||||
}
|
}
|
||||||
|
|
@ -615,9 +615,9 @@ mainLoop:
|
||||||
res, err = nil, errStopToken
|
res, err = nil, errStopToken
|
||||||
break mainLoop
|
break mainLoop
|
||||||
}
|
}
|
||||||
pos, cond := scope.Stack.pop(), scope.Stack.pop()
|
pos, cond := scope.Stack.pop2()
|
||||||
if !cond.IsZero() {
|
if !cond.IsZero() {
|
||||||
if !scope.Contract.validJumpdest(&pos) {
|
if !scope.Contract.validJumpdest(pos) {
|
||||||
res, err = nil, ErrInvalidJump
|
res, err = nil, ErrInvalidJump
|
||||||
break mainLoop
|
break mainLoop
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue