core: limit GAS available for block verification

This commit is contained in:
Roman Khimov 2020-07-13 18:24:58 +03:00
parent 395f4ea46d
commit 419d68329c

View file

@ -35,7 +35,8 @@ const (
headerBatchCount = 2000
version = "0.1.0"
defaultMemPoolSize = 50000
defaultMemPoolSize = 50000
verificationGasLimit = 100000000 // 1 GAS
)
var (
@ -1294,13 +1295,15 @@ func ScriptFromWitness(hash util.Uint160, witness *transaction.Witness) ([]byte,
}
// verifyHashAgainstScript verifies given hash against the given witness.
func (bc *Blockchain) verifyHashAgainstScript(hash util.Uint160, witness *transaction.Witness, interopCtx *interop.Context, useKeys bool) error {
func (bc *Blockchain) verifyHashAgainstScript(hash util.Uint160, witness *transaction.Witness, interopCtx *interop.Context, useKeys bool, gas int64) error {
verification, err := ScriptFromWitness(hash, witness)
if err != nil {
return err
}
vm := SpawnVM(interopCtx)
vm.SetPriceGetter(getPrice)
vm.GasLimit = gas
vm.LoadScriptWithFlags(verification, smartcontract.ReadOnly)
vm.LoadScript(witness.InvocationScript)
if useKeys {
@ -1355,7 +1358,7 @@ func (bc *Blockchain) verifyTxWitnesses(t *transaction.Transaction, block *block
sort.Slice(witnesses, func(i, j int) bool { return witnesses[i].ScriptHash().Less(witnesses[j].ScriptHash()) })
interopCtx := bc.newInteropContext(trigger.Verification, bc.dao, block, t)
for i := 0; i < len(hashes); i++ {
err := bc.verifyHashAgainstScript(hashes[i], &witnesses[i], interopCtx, false)
err := bc.verifyHashAgainstScript(hashes[i], &witnesses[i], interopCtx, false, 0)
if err != nil {
numStr := fmt.Sprintf("witness #%d", i)
return errors.Wrap(err, numStr)
@ -1375,7 +1378,7 @@ func (bc *Blockchain) verifyHeaderWitnesses(currHeader, prevHeader *block.Header
}
interopCtx := bc.newInteropContext(trigger.Verification, bc.dao, nil, nil)
interopCtx.Container = currHeader
return bc.verifyHashAgainstScript(hash, &currHeader.Script, interopCtx, true)
return bc.verifyHashAgainstScript(hash, &currHeader.Script, interopCtx, true, verificationGasLimit)
}
// GoverningTokenHash returns the governing token (NEO) native contract hash.