Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Resource Exhaustion in Script Interpreter #203

Open
sirdeggen opened this issue Feb 14, 2025 · 0 comments
Open

[BUG] Resource Exhaustion in Script Interpreter #203

sirdeggen opened this issue Feb 14, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@sirdeggen
Copy link
Collaborator

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/sdk version: 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.

@sirdeggen sirdeggen added the bug Something isn't working label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant