I think there are two current limits which most constrain the functionality of the Bitcoin Cash VM. They are closely related, and any changes to them must be tested together.
What work needs to be done before these limits may be relaxed?
520 Byte Push Limit
This limit prevents items longer than 520 bytes from being pushed, OP_NUM2BIN
ed, or OP_CAT
ed on to the stack. In the C++ implementation, the constant is called MAX_SCRIPT_ELEMENT_SIZE
. The limit was present as a magic number in the earliest versions of Bitcoin.
Increasing this limit has the potential to:
- make hashing operations much more expensive
- increase VM memory usage (
OP_DUP OP_CAT OP_DUP OP_CAT [...]
) - magnify other pathological constructions, especially by allowing larger P2SH scripts
If we can reduce or eliminate these potential bottlenecks/DOS vectors, it will allow:
- larger P2SH scripts – constraining scripts to 520 bytes prevents a huge variety of more complex use cases (including many useful CashToken-based public covenants)
- more efficient P2SH scripts – some data is more efficient to include in the P2SH script itself, but the 520 byte limit forces authors to design contracts to pull and validate this data from the unlocking bytecode. By allowing larger P2SH scripts, this overhead can be avoided.
-
larger hash preimages – many
OP_CHECKDATASIG
use cases require inspecting the contents of a signed message; the 520 byte limit also limits the size of these messages. (This could be worked around using merkle trees, but at the cost of much more expensive hashing.) In particular, CashToken proofs must include their parent transactions, so this limit also sets the upper-bound for CashToken transaction sizes.
I think we should consider making this limit the same as the current MAX_SCRIPT_SIZE
limit: 10,000 bytes.
This would effectively eliminate it as a roadblock to complex use cases, while still serving its purpose for DOS prevention.
Some things I think need to be done before this is possible:
- O(1) OP_IF/NOTIF/ELSE/ENDIF
- some hashing-specific operation limit
What other DOS attacks are possible? What else could raising this limit break?
201 Operation Limit
This limit invalidates scripts which use more than 201 non-push opcodes. In the Satoshi implementation, the constant is called MAX_OPS_PER_SCRIPT
.
This one is more straight-forward – more operations allows for more complex scripts.
What are some concerning constructions here?
- A full block of transactions with
<n> OP_HASH160 OP_HASH160 OP_HASH160 [...x201]
, where n is incremented for every script (preventing caches from being useful) – increasing the limit reduces the “transaction overhead” in this block, allowing a few more pathological transactions to be included
To raise this limit, I think we need:
- some hashing-specific operation limit
Can anyone offer any other attacks which are magnified by raising these limits?
Also, if anyone has links to any analyses of relevant DOS attacks, it would be great if we could collect those here.