Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

Oversize preimage attack.

3 messages, May 2, 2016. Started by Rusty Russell.

Rusty Russell (2), Olaoluwa Osuntokun

Permalink First message in the Wayback Machine

Rusty Russell permalink original

Hi all!

   I'm about to modify the HTLC scripts for the first time in a while to
prepend: "OP_SIZE 32 OP_EQUALVERIFY".  It means that even timing out an
HTLC requires a 32 byte value (say, all-zeroes), but it's the simplest
and shortest change.
   Without this, the length of a scriptsig which redeems a transaction
was ill-defined.  The wire protocol requires a 32-byte R preimage to
redeem a HTLC, but there was no such on-chain restriction.  An attacker
could create an HTLC which requires a different-size preimage to redeem,
then drop the commit tx to the blockchain and redeem it.  A node
couldn't use that preimage via the wire protocol.
   Or require a 110k preimage to redeem, drop to the blockchain, then
redeem it by sending direct to a miner.  A node trying to use that
preimage would create a non-standard transaction, which may not
propagate.  Similarly with an almost 4MB preimage which requires you
to grind out a tiny signature to redeem in a tx small enough...
   I'm also dropping the per-side HTLC limit from 1500 to 450 in BOLT
#2.  This means that a single "steal" transaction which spends all the
inputs is still under 400k cost (thanks segwit!), simplifying the
protocol.

Cheers, Rusty.

Olaoluwa Osuntokun in reply to Rusty Russell permalink original
Quoted text (7 lines)
>
>  Or require a 110k preimage to redeem, drop to the blockchain, then
> redeem it by sending direct to a miner.  A node trying to use that
> preimage would create a non-standard transaction, which may not
> propagate.  Similarly with an almost 4MB preimage which requires you
> to grind out a tiny signature to redeem in a tx small enough...
>

Segwit's witness program validation logic ensures that each element of the passed witness stack is less-than-or-equal-to the maximum script element size (520 bytes). This check is enforced before execution itself. Therefore, even without the additional OP_SIZE check, Script will enforce a ceiling on the pre-image size.

We've also recently made such an observation, resulting in a modification to our scripts similar to the one you've detailed. Thanks for sounding the alarm with this mailing-list post!

Best, Laolu

Rusty Russell in reply to Olaoluwa Osuntokun permalink original

Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (12 lines)
>>  Or require a 110k preimage to redeem, drop to the blockchain, then
>> redeem it by sending direct to a miner.  A node trying to use that
>> preimage would create a non-standard transaction, which may not
>> propagate.  Similarly with an almost 4MB preimage which requires you
>> to grind out a tiny signature to redeem in a tx small enough...
>>
>
> Segwit's witness program validation logic ensures that each element of the
> passed witness stack is less-than-or-equal-to the maximum script element
> size (520 bytes). This check is enforced before execution itself.
> Therefore, even without the additional OP_SIZE check, Script will enforce a
> ceiling on the pre-image size.

Right! I'd missed MAX_SCRIPT_ELEMENT_SIZE, thanks.

Quoted text (3 lines)
> We've also recently made such an observation, resulting in a modification
> to our scripts similar to the one you've detailed. Thanks for sounding the
> alarm with this mailing-list post!

Hmm, are there any other issues you've come across? Every time I find something like this I worry what else we've missed :(

Thanks! Rusty.