Do you remember that time when the owners of Bitcoin Cash, the Bitcoin ABC development group, included a change where they would start to enforce CLEANSTACK? I do, and I think quite a few other experienced Bitcoin SV developers do too.

CLEANSTACK assumptions

Shortly after enforcement started, it turns out that there was a special case related to P2SH which miners were using to refund Segwit transactions accidentally made on the Bitcoin Cash blockchain instead of the Bitcoin Core blockchain. So they made another change which presumably allowed this special case to work again.

I assumed that because they were enforcing it, it was never enforced on Bitcoin SV. The Bitcoin source code is somewhat convoluted, so it is hard to get in there and verify these things. And I know I am not the only one, as I have been discussing coin splitting solutions, more than one experienced Bitcoin SV developer said something like “just pop an extra item in the spending script.”


If you received funds, you should know how to spend them. Funds are received in the “scriptpubkey” and you spend them with the matching “scriptsig”. Logically, if you know how they are spent, then you know the exact information to spend them and if you do it right, there’s no extra information left over. This means it is expected that the stack only contains the result at the end of script evaluation, and nothing beyond that. This check includes the name CLEANSTACK.

Final thoughts

Knowing that user’s wallets cannot bypass CLEANSTACK as a way of splitting their coins, and that it is a miner configurable setting, it sheds some light on Bitcoin Cash’s mistake. Before they enforced it, they would have been in the situation we are now — where miners could bypass the setting to retrieve lost Bitcoin Core Segwit funds. Presumably ABC didn’t understand how miners retrieved these coins and ended that option.

There are some notions that it might be good to get rid of CLEANSTACK and you could take the left over computation on the stack, and pass it to the next input in the sequence. But this is just wishful thinking at this point, in reality it cannot help user’s wallets split their coins. As a solution that invalidates the spend in the input, rather than the output, it would have been much cleaner and solid than any output-based alternative.

Well, I guess. I am not a Bitcoin expert. I just have to try and work some of this stuff out on my own. You can discuss things like this on Unwriter’s Slack, or the Metanet.ICU Slack.

Written by

ElectrumSV developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store