Research/Bitcoin Dev Archive / lightning-dev list
We don't need R-Value, how OP_CODESEPARATOR saves the day
2 messages, Mar 7, 2016. Started by Nicolas Dorier.
Nicolas Dorier, Rusty Russell
I'm amazed as I found a useful case for OP_CODESEPARATOR. I think the script can be improved to take less byte for removing the duplication of <KeyA>, will take a look later. Let's change escape redeem:
OP_HASH160 <RHashA> OP_EQUAL OP_IF <KeyB> OP_ELSE <Delay> OP_CSV OP_DROP <KeyA> OP_ENDIF OP_CHECKSIG
To
<KeyA> OP_CHECKSIG OP_IF <KeyB> OP_ELSE <Delay> OP_CSV OP_DROP OP_CODESEPARATOR <KeyA> OP_ENDIF OP_CHECKSIG
The Escape output would be
<SIG-B> <SIGA-Revocation> {<ESCAPE-REDEEM>}
Where SIGA-Revocation is the signature of KeyA computed with the ScriptCode=<ESCAPE-REDEEM>
The second escape would be
<SIG-A> 0 {<ESCAPE-REDEEMSCRIPT>}
where <SIG-A> script equals to
<KeyA> OP_ENDIF OP_CHECKSIG
You would revoke a commitment by revealing <SIGA-Revocation>
Btw, you can play with http://n.bitcoin.ninja/checkscript to test such script (I'm checking it myself)
Nicolas Dorier <nicolas.dorier at gmail.com> writes:
Quoted text (1 line)
> I'm amazed as I found a useful case for OP_CODESEPARATOR.
Me too! This is an awesome hack.
There is an important caveats: You must make sure you never ever create a commit tx which is identical a previous one.
There's also a requirement that you store all previous signatures, avoided by both the original draft scheme (using BIP32 and handing over old private keys) and the deployable lightning chain-of-hashes.
Since these scripts will hardly ever hit the chain, I think this a premature optimization. But maybe I'm still a bit stunned by this use of OP_CODESEPARATOR :)
Great work! Rusty.