@@ -292,6 +292,8 @@ def default_witness_taproot(ctx):
292
292
suffix_annex = [annex ]
293
293
if get (ctx , "leaf" ) is None :
294
294
return get (ctx , "inputs_keypath" ) + suffix_annex
295
+ elif get (ctx , "leafversion" ) == LEAF_VERSION_TAPSIMPLICITY :
296
+ return [bytes (get (ctx , "simplicity_program" )), bytes (get (ctx , "script_taproot" )), get (ctx , "controlblock" )] + suffix_annex
295
297
else :
296
298
return get (ctx , "inputs" ) + [bytes (get (ctx , "script_taproot" )), get (ctx , "controlblock" )] + suffix_annex
297
299
@@ -358,6 +360,8 @@ def default_scriptsig(ctx):
358
360
"tapleaf" : default_tapleaf ,
359
361
# The script to push, and include in the sighash, for a taproot script path spend.
360
362
"script_taproot" : default_script_taproot ,
363
+ # The simplicity program for a taproot simplicity spend.
364
+ "simplicity_program" : [],
361
365
# The internal pubkey for a taproot script path spend (32 bytes).
362
366
"pubkey_internal" : default_pubkey_internal ,
363
367
# The negation flag of the internal pubkey for a taproot script path spend.
@@ -592,6 +596,8 @@ def byte_popper(expr):
592
596
ERR_NO_SUCCESS = {"err_msg" : "Script evaluated without error but finished with a false/empty top stack element" }
593
597
ERR_EMPTY_WITNESS = {"err_msg" : "Witness program was passed an empty witness" }
594
598
ERR_CHECKSIGVERIFY = {"err_msg" : "Script failed an OP_CHECKSIGVERIFY operation" }
599
+ ERR_SIMPLICITY_BITSTREAM_EOF = {"err_msg" : "Unexpected end of bitstream" }
600
+ ERR_SIMPLICITY_BITSTREAM_UNUSED_BITS = {"err_msg" : "Unused bits at the end of the program" }
595
601
596
602
VALID_SIGHASHES_ECDSA = [
597
603
SIGHASH_ALL ,
@@ -1116,6 +1122,13 @@ def predict_sigops_ratio(n, dummy_size):
1116
1122
tap = taproot_construct (pubs [0 ], scripts )
1117
1123
add_spender (spenders , "alwaysvalid/notsuccessx" , tap = tap , leaf = "op_success" , inputs = [], standard = False , failure = {"leaf" : "normal" }) # err_msg differs based on opcode
1118
1124
1125
+ # == Simplicity tests ==
1126
+
1127
+ tap = taproot_construct (pubs [0 ], [("simplicity_iden" , bytes .fromhex ("dbfefcfc7796acfc86b435c1f81ed8a165dab2649dc48b0f35f832647868fb5e" ), LEAF_VERSION_TAPSIMPLICITY )])
1128
+ add_spender (spenders , "simplicity/empty_program" , tap = tap , leaf = "simplicity_iden" , simplicity_program = bytes .fromhex ("20" ), failure = {"simplicity_program" : b'' }, ** ERR_SIMPLICITY_BITSTREAM_EOF )
1129
+ # tempoarily removed because random bit errors will cause differt sorts of Simplicity errors.
1130
+ # add_spender(spenders, "simplicity/iden", tap=tap, leaf="simplicity_iden", simplicity_program=bytes.fromhex("20"), failure={"simplicity_program": bitflipper(bytes.fromhex("20"))}, **ERR_SIMPLICITY_BITSTREAM_UNUSED_BITS)
1131
+
1119
1132
# == Legacy tests ==
1120
1133
1121
1134
# Also add a few legacy spends into the mix, so that transactions which combine taproot and pre-taproot spends get tested too.
0 commit comments