I am trying to spend from a branched Simplicity program, but I don't wanna supply the signatures in the untaken branch, so I am trying to prune the program by hand. I have verified that I can take the commitmentRoot of a checkSig with the signature set to undefined.

To make a valid spend, I think I need to construct a pruned program that has the same CommitmentRoot that the full program has. So I boiled by program down to a single case expression:

u :: CommitmentRoot () ()
u = unit

full :: CommitmentRoot (Bit, ()) ()
full = cond u unit

pruned :: CommitmentRoot (Bit, ()) ()
pruned = assertr (commitmentRoot u) unit

But the CommitmentRoots do not have the same hash:

*Main> (encode.fromShort.hash256.commitmentRoot) pruned
*Main> (encode.fromShort.hash256.commitmentRoot) full

What gives? Is my understanding that I need a matching CommitmentRoot incorrect? If it is not correct, how do I prune a case expression correctly?

Furthermore, section " Pruning Unused case Branches" of the Simplicity Technical Report claims that "We can effectively replace any unused branch in a case expression with its commitment Merkle root." But if I do that, I cannot run the Simplicity program with runKleisli. So how is this supposed to work?


The definition of cond is

cond thn els = match (drop els) (drop thn)

Expanding this in your definition of full yields

full = match (drop unit) (drop u)

The correct pruned version should be

pruned = assertl (drop unit) (commitmentRoot (drop u))

which has commitment root that matches:

let full = cond unit unit in (flip Numeric.showHex "".integerHash256.commitmentRoot) (full :: CommitmentRoot (Bit, ()) ())

let pruned = assertl (Simplicity.Term.Core.drop unit) (commitmentRoot (Simplicity.Term.Core.drop unit :: CommitmentRoot ((),()) ())) in (flip Numeric.showHex "".integerHash256.commitmentRoot) (pruned :: CommitmentRoot (Bit, ()) ())

Better library support for pruning expressions is something that will be developed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.