From 419d68329c1fa31962df2cbe139fa0112619d4ab Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 13 Jul 2020 18:24:58 +0300 Subject: [PATCH] core: limit GAS available for block verification --- pkg/core/blockchain.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index bbfa38219..866f38a9f 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -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.