-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Bug Description
Modular Exponentiation leads to resource exhaustion during script execution.
import { Transaction, Script } from '@bsv/sdk'
const sourceTransaction = new Transaction()
sourceTransaction.addInput({
sourceOutputIndex: 0,
sourceTXID: 'beefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef', unlockingScript: Script.fromASM('OP_TRUE'),
})
sourceTransaction.addOutput({
lockingScript: Script.fromASM('OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL OP_DUP OP_MUL'),
satoshis: 1
})
sourceTransaction.merklePath = {}
const tx = new Transaction()
tx.addInput({
sourceTransaction,
sourceOutputIndex: 0,
unlockingScript: Script.fromASM('OP_2')
})
tx.addOutput({
satoshis: 1,
lockingScript: Script.fromASM('OP_TRUE')
})
await tx.fee()
await tx.sign()
console.log(sourceTransaction.outputs[0].lockingScript.chunks.length / 2)
await tx.verify('scripts only')Expected Behavior
Script execution should fail once stack memory usage hits 100 MB since this is the max allowed in node's policy.
Actual Behavior
What actually happened?
Stack Traces or Screenshots
If applicable, add screenshots or stack traces to help explain the issue.
Environment
- OS: MacOS MacBookPro M3
- Node version: LTS
@bsv/sdkversion: 1.3.18
Additional Information
At 22 iterations my machine copes, beyond that it's noticeably lagging each time I add more iterations.
The limit to match current default policy should be 100MB.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working