core/vm: derive maxStack from numPop & numPush (#6397)

This commit is contained in:
Andrew Ashikhmin 2022-12-21 14:55:00 +01:00 committed by GitHub
parent dc248c5ea4
commit 49bb63661f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 389 deletions

View File

@ -45,6 +45,7 @@ func EnableEIP(eipNum int, jt *JumpTable) error {
return fmt.Errorf("undefined eip %d", eipNum)
}
enablerFn(jt)
validateAndFillMaxStack(jt)
return nil
}
@ -76,8 +77,8 @@ func enable1884(jt *JumpTable) {
jt[SELFBALANCE] = &operation{
execute: opSelfBalance,
constantGas: GasFastStep,
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),
numPop: 0,
numPush: 1,
}
}
@ -94,8 +95,8 @@ func enable1344(jt *JumpTable) {
jt[CHAINID] = &operation{
execute: opChainID,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),
numPop: 0,
numPush: 1,
}
}
@ -162,8 +163,8 @@ func enable3198(jt *JumpTable) {
jt[BASEFEE] = &operation{
execute: opBaseFee,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),
numPop: 0,
numPush: 1,
}
}
@ -180,8 +181,8 @@ func enable3855(jt *JumpTable) {
jt[PUSH0] = &operation{
execute: opPush0,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),
numPop: 0,
numPush: 1,
}
}

View File

@ -240,8 +240,8 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
operation := in.jt[op]
cost = operation.constantGas // For tracing
// Validate stack
if sLen := locStack.Len(); sLen < operation.minStack {
return nil, &ErrStackUnderflow{stackLen: sLen, required: operation.minStack}
if sLen := locStack.Len(); sLen < operation.numPop {
return nil, &ErrStackUnderflow{stackLen: sLen, required: operation.numPop}
} else if sLen > operation.maxStack {
return nil, &ErrStackOverflow{stackLen: sLen, limit: operation.maxStack}
}

File diff suppressed because it is too large Load Diff

View File

@ -20,23 +20,6 @@ import (
"github.com/ledgerwatch/erigon/params"
)
func minSwapStack(n int) int {
return minStack(n, n)
}
func maxSwapStack(n int) int {
return maxStack(n, n)
}
func minDupStack(n int) int {
return minStack(n, n+1)
}
func maxDupStack(n int) int {
return maxStack(n, n+1)
}
func maxStack(pop, push int) int {
return int(params.StackLimit) + pop - push
}
func minStack(pops, push int) int {
return pops
}