From c107487d3b5bcd9680a075ac167b53da50c9cd15 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Wed, 12 Feb 2025 00:32:37 +0000 Subject: [PATCH 1/2] update libsimplicity to c54a8db0e4c69a571aa67c3bc3188eb33ca67dcb This matches Elements d020546243677f8490685cae06da626f971ba4a7. --- .../depend/simplicity-HEAD-revision.txt | 2 +- simplicity-sys/depend/simplicity/ctx8Pruned.c | 4 +- simplicity-sys/depend/simplicity/ctx8Pruned.h | 4 +- .../depend/simplicity/ctx8Unpruned.c | 4 +- .../depend/simplicity/ctx8Unpruned.h | 4 +- simplicity-sys/depend/simplicity/dag.c | 74 +- simplicity-sys/depend/simplicity/dag.h | 8 +- .../depend/simplicity/decodeCoreJets.inc | 1037 ++++++++++++++++ .../depend/simplicity/deserialize.c | 14 +- .../depend/simplicity/deserialize.h | 4 +- .../depend/simplicity/elements-sources.mk | 2 + simplicity-sys/depend/simplicity/hashBlock.c | 4 +- simplicity-sys/depend/simplicity/hashBlock.h | 4 +- .../include/simplicity/elements/env.h | 13 +- .../include/simplicity/elements/exec.h | 9 +- .../include/simplicity/errorCodes.h | 8 +- .../primitive/elements/checkSigHashAllTx1.c | 4 +- .../primitive/elements/checkSigHashAllTx1.h | 4 +- .../primitive/elements/decodeElementsJets.inc | 136 ++ .../simplicity/primitive/elements/env.c | 15 +- .../simplicity/primitive/elements/exec.c | 17 +- .../simplicity/primitive/elements/primitive.c | 1097 +---------------- simplicity-sys/depend/simplicity/schnorr0.c | 4 +- simplicity-sys/depend/simplicity/schnorr0.h | 4 +- simplicity-sys/depend/simplicity/schnorr6.c | 4 +- simplicity-sys/depend/simplicity/schnorr6.h | 4 +- .../simplicity/secp256k1/int128_struct.h | 2 +- .../depend/simplicity/secp256k1/modinv64.h | 16 +- .../simplicity/secp256k1/modinv64_impl.h | 10 +- .../simplicity/secp256k1/precomputed_ecmult.h | 16 +- simplicity-sys/depend/simplicity/test.c | 46 +- .../depend/simplicity/typeSkipTest.c | 4 +- .../depend/simplicity/typeSkipTest.h | 4 +- 33 files changed, 1353 insertions(+), 1229 deletions(-) create mode 100644 simplicity-sys/depend/simplicity/decodeCoreJets.inc create mode 100644 simplicity-sys/depend/simplicity/primitive/elements/decodeElementsJets.inc diff --git a/simplicity-sys/depend/simplicity-HEAD-revision.txt b/simplicity-sys/depend/simplicity-HEAD-revision.txt index 835a99fa..37040a57 100644 --- a/simplicity-sys/depend/simplicity-HEAD-revision.txt +++ b/simplicity-sys/depend/simplicity-HEAD-revision.txt @@ -1,2 +1,2 @@ # This file has been automatically generated. -bdc0b1fceb9109c98e228aa14c7d50c90edb3748 +c54a8db0e4c69a571aa67c3bc3188eb33ca67dcb diff --git a/simplicity-sys/depend/simplicity/ctx8Pruned.c b/simplicity-sys/depend/simplicity/ctx8Pruned.c index cc8488ec..c3963816 100644 --- a/simplicity-sys/depend/simplicity/ctx8Pruned.c +++ b/simplicity-sys/depend/simplicity/ctx8Pruned.c @@ -270,8 +270,8 @@ const uint32_t ctx8Pruned_cmr[] = { 0x7f11746fu, 0xb68fdaedu, 0x3cadda80u, 0xc7cd0245u, 0xa341b927u, 0xe98e60f8u, 0x745dc441u, 0xe11ce1a3u }; -/* The identity Merkle root of the above ctx8Pruned Simplicity expression. */ -const uint32_t ctx8Pruned_imr[] = { +/* The identity hash of the root of the above ctx8Pruned Simplicity expression. */ +const uint32_t ctx8Pruned_ihr[] = { 0x8e8742acu, 0x27f42d29u, 0xd87f5229u, 0x02bc0ae2u, 0xbcfc1298u, 0x1641a2ddu, 0x77091830u, 0xb79bf12du }; diff --git a/simplicity-sys/depend/simplicity/ctx8Pruned.h b/simplicity-sys/depend/simplicity/ctx8Pruned.h index 7b66bdbe..26d107b2 100644 --- a/simplicity-sys/depend/simplicity/ctx8Pruned.h +++ b/simplicity-sys/depend/simplicity/ctx8Pruned.h @@ -18,8 +18,8 @@ extern const size_t sizeof_ctx8Pruned_witness; /* The commitment Merkle root of the above ctx8Pruned Simplicity expression. */ extern const uint32_t ctx8Pruned_cmr[]; -/* The identity Merkle root of the above ctx8Pruned Simplicity expression. */ -extern const uint32_t ctx8Pruned_imr[]; +/* The identity hash of the root of the above ctx8Pruned Simplicity expression. */ +extern const uint32_t ctx8Pruned_ihr[]; /* The annotated Merkle root of the above ctx8Pruned Simplicity expression. */ extern const uint32_t ctx8Pruned_amr[]; diff --git a/simplicity-sys/depend/simplicity/ctx8Unpruned.c b/simplicity-sys/depend/simplicity/ctx8Unpruned.c index b92bc2e4..e9c4a9bb 100644 --- a/simplicity-sys/depend/simplicity/ctx8Unpruned.c +++ b/simplicity-sys/depend/simplicity/ctx8Unpruned.c @@ -260,8 +260,8 @@ const uint32_t ctx8Unpruned_cmr[] = { 0x7f11746fu, 0xb68fdaedu, 0x3cadda80u, 0xc7cd0245u, 0xa341b927u, 0xe98e60f8u, 0x745dc441u, 0xe11ce1a3u }; -/* The identity Merkle root of the above ctx8Unpruned Simplicity expression. */ -const uint32_t ctx8Unpruned_imr[] = { +/* The identity hash of the root of the above ctx8Unpruned Simplicity expression. */ +const uint32_t ctx8Unpruned_ihr[] = { 0x8e8742acu, 0x27f42d29u, 0xd87f5229u, 0x02bc0ae2u, 0xbcfc1298u, 0x1641a2ddu, 0x77091830u, 0xb79bf12du }; diff --git a/simplicity-sys/depend/simplicity/ctx8Unpruned.h b/simplicity-sys/depend/simplicity/ctx8Unpruned.h index 8024e33c..5af8deab 100644 --- a/simplicity-sys/depend/simplicity/ctx8Unpruned.h +++ b/simplicity-sys/depend/simplicity/ctx8Unpruned.h @@ -18,8 +18,8 @@ extern const size_t sizeof_ctx8Unpruned_witness; /* The commitment Merkle root of the above ctx8Unpruned Simplicity expression. */ extern const uint32_t ctx8Unpruned_cmr[]; -/* The identity Merkle root of the above ctx8Unpruned Simplicity expression. */ -extern const uint32_t ctx8Unpruned_imr[]; +/* The identity hash of the root of the above ctx8Unpruned Simplicity expression. */ +extern const uint32_t ctx8Unpruned_ihr[]; /* The annotated Merkle root of the above ctx8Unpruned Simplicity expression. */ extern const uint32_t ctx8Unpruned_amr[]; diff --git a/simplicity-sys/depend/simplicity/dag.c b/simplicity-sys/depend/simplicity/dag.c index 0b604a2a..bfcf561b 100644 --- a/simplicity-sys/depend/simplicity/dag.c +++ b/simplicity-sys/depend/simplicity/dag.c @@ -77,16 +77,16 @@ static sha256_midstate amrIV(tag_t tag) { SIMPLICITY_UNREACHABLE; } -/* Given the IMR of a jet specification, return the CMR for a jet that implements that specification. +/* Given the identity hash of a jet specification, return the CMR for a jet that implements that specification. * - * Precondition: uint32_t imr[8] + * Precondition: uint32_t ih[8] */ -static sha256_midstate mkJetCMR(uint32_t *imr, uint_fast64_t weight) { +static sha256_midstate mkJetCMR(uint32_t *ih, uint_fast64_t weight) { sha256_midstate result = jetIV; uint32_t block[16] = {0}; block[6] = (uint32_t)(weight >> 32); block[7] = (uint32_t)weight; - memcpy(&block[8], imr, sizeof(uint32_t[8])); + memcpy(&block[8], ih, sizeof(uint32_t[8])); simplicity_sha256_compression(result.s, block); return result; @@ -100,7 +100,7 @@ sha256_midstate simplicity_computeWordCMR(const bitstring* value, size_t n) { /* 'stack' is an array of 30 hashes consisting of 8 'uint32_t's each. */ uint32_t stack[8*30] = {0}; uint32_t *stack_ptr = stack; - sha256_midstate imr = identityIV; + sha256_midstate ih = identityIV; simplicity_assert(n < 32); simplicity_assert((size_t)1 << n == value->len); /* Pass 1: Compute the CMR for the expression that writes 'value'. @@ -135,14 +135,14 @@ sha256_midstate simplicity_computeWordCMR(const bitstring* value, size_t n) { /* value->len is a power of 2.*/ simplicity_assert(stack_ptr == stack + 8); - /* Pass 2: Compute the IMR for the expression by adding the type roots of ONE and TWO^(2^n) to the CMR. */ - simplicity_sha256_compression(imr.s, stack); + /* Pass 2: Compute the identity hash for the expression by adding the type roots of ONE and TWO^(2^n) to the CMR. */ + simplicity_sha256_compression(ih.s, stack); memcpy(&stack[0], word_type_root[0].s, sizeof(uint32_t[8])); memcpy(&stack[8], word_type_root[n+1].s, sizeof(uint32_t[8])); - simplicity_sha256_compression(imr.s, stack); + simplicity_sha256_compression(ih.s, stack); - /* Pass 3: Compute the jet's CMR from the specificion's IMR. */ - return mkJetCMR(imr.s, ((uint_fast64_t)1 << n)); + /* Pass 3: Compute the jet's CMR from the specificion's identity hash. */ + return mkJetCMR(ih.s, ((uint_fast64_t)1 << n)); } /* Given a well-formed dag[i + 1], such that for all 'j', 0 <= 'j' < 'i', @@ -192,21 +192,21 @@ void simplicity_computeCommitmentMerkleRoot(dag_node* dag, const uint_fast32_t i } } -/* Computes the identity Merkle roots of every subexpression in a well-typed 'dag' with witnesses. - * 'imr[i]' is set to the identity Merkle root of the subexpression 'dag[i]'. - * When 'HIDDEN == dag[i].tag', then 'imr[i]' is instead set to a hidden root hash for that hidden node. +/* Computes the identity hash roots of every subexpression in a well-typed 'dag' with witnesses. + * 'ihr[i]' is set to the identity hash of the root of the subexpression 'dag[i]'. + * When 'HIDDEN == dag[i].tag', then 'ihr[i]' is instead set to a hidden root hash for that hidden node. * - * Precondition: sha256_midstate imr[len]; + * Precondition: sha256_midstate ihr[len]; * dag_node dag[len] and 'dag' is well-typed with 'type_dag' and contains witnesses. */ -static void computeIdentityMerkleRoot(sha256_midstate* imr, const dag_node* dag, const type* type_dag, const uint_fast32_t len) { +static void computeIdentityHashRoots(sha256_midstate* ihr, const dag_node* dag, const type* type_dag, const uint_fast32_t len) { /* Pass 1 */ for (size_t i = 0; i < len; ++i) { uint32_t block[16] = {0}; size_t j = 8; /* For jets, the first pass identity Merkle root is the same as their commitment Merkle root. */ - imr[i] = HIDDEN == dag[i].tag ? dag[i].cmr + ihr[i] = HIDDEN == dag[i].tag ? dag[i].cmr : JET == dag[i].tag ? dag[i].cmr : WORD == dag[i].tag ? dag[i].cmr : imrIV(dag[i].tag); @@ -214,7 +214,7 @@ static void computeIdentityMerkleRoot(sha256_midstate* imr, const dag_node* dag, case WITNESS: simplicity_sha256_bitstring(block, &dag[i].compactValue); memcpy(block + 8, type_dag[WITNESS_B(dag, type_dag, i)].typeMerkleRoot.s, sizeof(uint32_t[8])); - simplicity_sha256_compression(imr[i].s, block); + simplicity_sha256_compression(ihr[i].s, block); break; case COMP: case ASSERTL: @@ -222,15 +222,15 @@ static void computeIdentityMerkleRoot(sha256_midstate* imr, const dag_node* dag, case CASE: case PAIR: case DISCONNECT: - memcpy(block + j, imr[dag[i].child[1]].s, sizeof(uint32_t[8])); + memcpy(block + j, ihr[dag[i].child[1]].s, sizeof(uint32_t[8])); j = 0; /*@fallthrough@*/ case INJL: case INJR: case TAKE: case DROP: - memcpy(block + j, imr[dag[i].child[0]].s, sizeof(uint32_t[8])); - simplicity_sha256_compression(imr[i].s, block); + memcpy(block + j, ihr[dag[i].child[0]].s, sizeof(uint32_t[8])); + simplicity_sha256_compression(ihr[i].s, block); case IDEN: case UNIT: case HIDDEN: @@ -245,16 +245,16 @@ static void computeIdentityMerkleRoot(sha256_midstate* imr, const dag_node* dag, uint32_t block[16] = {0}; if (HIDDEN == dag[i].tag) { - memcpy(block + 8, imr[i].s, sizeof(uint32_t[8])); - imr[i] = hiddenIV; - simplicity_sha256_compression(imr[i].s, block); + memcpy(block + 8, ihr[i].s, sizeof(uint32_t[8])); + ihr[i] = hiddenIV; + simplicity_sha256_compression(ihr[i].s, block); } else { - memcpy(block + 8, imr[i].s, sizeof(uint32_t[8])); - imr[i] = identityIV; - simplicity_sha256_compression(imr[i].s, block); + memcpy(block + 8, ihr[i].s, sizeof(uint32_t[8])); + ihr[i] = identityIV; + simplicity_sha256_compression(ihr[i].s, block); memcpy(block, type_dag[dag[i].sourceType].typeMerkleRoot.s, sizeof(uint32_t[8])); memcpy(block + 8, type_dag[dag[i].targetType].typeMerkleRoot.s, sizeof(uint32_t[8])); - simplicity_sha256_compression(imr[i].s, block); + simplicity_sha256_compression(ihr[i].s, block); } } } @@ -559,30 +559,30 @@ simplicity_err simplicity_fillWitnessData(dag_node* dag, type* type_dag, const u return SIMPLICITY_NO_ERROR; } -/* Verifies that identity Merkle roots of every subexpression in a well-typed 'dag' with witnesses are all unique, +/* Verifies that identity hash of every subexpression in a well-typed 'dag' with witnesses are all unique, * including that each hidden root hash for every 'HIDDEN' node is unique. * - * if 'imr' is not NULL, then '*imr' is set to the identity Merkle root of the 'dag'. + * if 'ihr' is not NULL, then '*ihr' is set to the identity hash of the root of the 'dag'. * * If malloc fails, returns 'SIMPLICITY_ERR_MALLOC'. - * If all the identity Merkle roots (and hidden roots) are all unique, returns 'SIMPLICITY_NO_ERROR'. + * If all the identity hahes (and hidden roots) are all unique, returns 'SIMPLICITY_NO_ERROR'. * Otherwise returns 'SIMPLICITY_ERR_UNSHARED_SUBEXPRESSION'. * * Precondition: dag_node dag[len] and 'dag' is well-typed with 'type_dag' and contains witnesses. */ -simplicity_err simplicity_verifyNoDuplicateIdentityRoots(sha256_midstate* imr, const dag_node* dag, const type* type_dag, const uint_fast32_t dag_len) { +simplicity_err simplicity_verifyNoDuplicateIdentityHashes(sha256_midstate* ihr, const dag_node* dag, const type* type_dag, const uint_fast32_t dag_len) { simplicity_assert(0 < dag_len); simplicity_assert(dag_len <= DAG_LEN_MAX); - sha256_midstate* imr_buf = simplicity_malloc((size_t)dag_len * sizeof(sha256_midstate)); - if (!imr_buf) return SIMPLICITY_ERR_MALLOC; + sha256_midstate* ih_buf = simplicity_malloc((size_t)dag_len * sizeof(sha256_midstate)); + if (!ih_buf) return SIMPLICITY_ERR_MALLOC; - computeIdentityMerkleRoot(imr_buf, dag, type_dag, dag_len); + computeIdentityHashRoots(ih_buf, dag, type_dag, dag_len); - if (imr) *imr = imr_buf[dag_len-1]; + if (ihr) *ihr = ih_buf[dag_len-1]; - int result = simplicity_hasDuplicates(imr_buf, dag_len); + int result = simplicity_hasDuplicates(ih_buf, dag_len); - simplicity_free(imr_buf); + simplicity_free(ih_buf); switch (result) { case -1: return SIMPLICITY_ERR_MALLOC; diff --git a/simplicity-sys/depend/simplicity/dag.h b/simplicity-sys/depend/simplicity/dag.h index f2f9cd27..afe0d44e 100644 --- a/simplicity-sys/depend/simplicity/dag.h +++ b/simplicity-sys/depend/simplicity/dag.h @@ -377,17 +377,17 @@ simplicity_err simplicity_verifyCanonicalOrder(dag_node* dag, const uint_fast32_ */ simplicity_err simplicity_fillWitnessData(dag_node* dag, type* type_dag, const uint_fast32_t len, bitstream *witness); -/* Verifies that identity Merkle roots of every subexpression in a well-typed 'dag' with witnesses are all unique, +/* Verifies that identity hash of every subexpression in a well-typed 'dag' with witnesses are all unique, * including that each hidden root hash for every 'HIDDEN' node is unique. * - * if 'imr' is not NULL, then '*imr' is set to the identity Merkle root of the 'dag'. + * if 'ihr' is not NULL, then '*ihr' is set to the identity hash of the root of the 'dag'. * * If malloc fails, returns 'SIMPLICITY_ERR_MALLOC'. - * If all the identity Merkle roots (and hidden roots) are all unique, returns 'SIMPLICITY_NO_ERROR'. + * If all the identity hahes (and hidden roots) are all unique, returns 'SIMPLICITY_NO_ERROR'. * Otherwise returns 'SIMPLICITY_ERR_UNSHARED_SUBEXPRESSION'. * * Precondition: dag_node dag[len] and 'dag' is well-typed with 'type_dag' and contains witnesses. */ -simplicity_err simplicity_verifyNoDuplicateIdentityRoots(sha256_midstate* imr, const dag_node* dag, const type* type_dag, const uint_fast32_t dag_len); +simplicity_err simplicity_verifyNoDuplicateIdentityHashes(sha256_midstate* ihr, const dag_node* dag, const type* type_dag, const uint_fast32_t dag_len); #endif diff --git a/simplicity-sys/depend/simplicity/decodeCoreJets.inc b/simplicity-sys/depend/simplicity/decodeCoreJets.inc new file mode 100644 index 00000000..a38932e8 --- /dev/null +++ b/simplicity-sys/depend/simplicity/decodeCoreJets.inc @@ -0,0 +1,1037 @@ +/* This file has been automatically generated. */ + +{ + int32_t code; + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = VERIFY; return SIMPLICITY_NO_ERROR; + case 2: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LOW_1; return SIMPLICITY_NO_ERROR; + case 3: *result = LOW_8; return SIMPLICITY_NO_ERROR; + case 4: *result = LOW_16; return SIMPLICITY_NO_ERROR; + case 5: *result = LOW_32; return SIMPLICITY_NO_ERROR; + case 6: *result = LOW_64; return SIMPLICITY_NO_ERROR; + } + break; + case 3: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = HIGH_1; return SIMPLICITY_NO_ERROR; + case 3: *result = HIGH_8; return SIMPLICITY_NO_ERROR; + case 4: *result = HIGH_16; return SIMPLICITY_NO_ERROR; + case 5: *result = HIGH_32; return SIMPLICITY_NO_ERROR; + case 6: *result = HIGH_64; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = COMPLEMENT_1; return SIMPLICITY_NO_ERROR; + case 3: *result = COMPLEMENT_8; return SIMPLICITY_NO_ERROR; + case 4: *result = COMPLEMENT_16; return SIMPLICITY_NO_ERROR; + case 5: *result = COMPLEMENT_32; return SIMPLICITY_NO_ERROR; + case 6: *result = COMPLEMENT_64; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = AND_1; return SIMPLICITY_NO_ERROR; + case 3: *result = AND_8; return SIMPLICITY_NO_ERROR; + case 4: *result = AND_16; return SIMPLICITY_NO_ERROR; + case 5: *result = AND_32; return SIMPLICITY_NO_ERROR; + case 6: *result = AND_64; return SIMPLICITY_NO_ERROR; + } + break; + case 6: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = OR_1; return SIMPLICITY_NO_ERROR; + case 3: *result = OR_8; return SIMPLICITY_NO_ERROR; + case 4: *result = OR_16; return SIMPLICITY_NO_ERROR; + case 5: *result = OR_32; return SIMPLICITY_NO_ERROR; + case 6: *result = OR_64; return SIMPLICITY_NO_ERROR; + } + break; + case 7: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = XOR_1; return SIMPLICITY_NO_ERROR; + case 3: *result = XOR_8; return SIMPLICITY_NO_ERROR; + case 4: *result = XOR_16; return SIMPLICITY_NO_ERROR; + case 5: *result = XOR_32; return SIMPLICITY_NO_ERROR; + case 6: *result = XOR_64; return SIMPLICITY_NO_ERROR; + } + break; + case 8: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = MAJ_1; return SIMPLICITY_NO_ERROR; + case 3: *result = MAJ_8; return SIMPLICITY_NO_ERROR; + case 4: *result = MAJ_16; return SIMPLICITY_NO_ERROR; + case 5: *result = MAJ_32; return SIMPLICITY_NO_ERROR; + case 6: *result = MAJ_64; return SIMPLICITY_NO_ERROR; + } + break; + case 9: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = XOR_XOR_1; return SIMPLICITY_NO_ERROR; + case 3: *result = XOR_XOR_8; return SIMPLICITY_NO_ERROR; + case 4: *result = XOR_XOR_16; return SIMPLICITY_NO_ERROR; + case 5: *result = XOR_XOR_32; return SIMPLICITY_NO_ERROR; + case 6: *result = XOR_XOR_64; return SIMPLICITY_NO_ERROR; + } + break; + case 10: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = CH_1; return SIMPLICITY_NO_ERROR; + case 3: *result = CH_8; return SIMPLICITY_NO_ERROR; + case 4: *result = CH_16; return SIMPLICITY_NO_ERROR; + case 5: *result = CH_32; return SIMPLICITY_NO_ERROR; + case 6: *result = CH_64; return SIMPLICITY_NO_ERROR; + } + break; + case 11: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = SOME_1; return SIMPLICITY_NO_ERROR; + case 3: *result = SOME_8; return SIMPLICITY_NO_ERROR; + case 4: *result = SOME_16; return SIMPLICITY_NO_ERROR; + case 5: *result = SOME_32; return SIMPLICITY_NO_ERROR; + case 6: *result = SOME_64; return SIMPLICITY_NO_ERROR; + } + break; + case 12: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = ALL_8; return SIMPLICITY_NO_ERROR; + case 4: *result = ALL_16; return SIMPLICITY_NO_ERROR; + case 5: *result = ALL_32; return SIMPLICITY_NO_ERROR; + case 6: *result = ALL_64; return SIMPLICITY_NO_ERROR; + } + break; + case 13: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = EQ_1; return SIMPLICITY_NO_ERROR; + case 3: *result = EQ_8; return SIMPLICITY_NO_ERROR; + case 4: *result = EQ_16; return SIMPLICITY_NO_ERROR; + case 5: *result = EQ_32; return SIMPLICITY_NO_ERROR; + case 6: *result = EQ_64; return SIMPLICITY_NO_ERROR; + case 8: *result = EQ_256; return SIMPLICITY_NO_ERROR; + } + break; + case 14: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = FULL_LEFT_SHIFT_8_1; return SIMPLICITY_NO_ERROR; + case 4: *result = FULL_LEFT_SHIFT_16_1; return SIMPLICITY_NO_ERROR; + case 5: *result = FULL_LEFT_SHIFT_32_1; return SIMPLICITY_NO_ERROR; + case 6: *result = FULL_LEFT_SHIFT_64_1; return SIMPLICITY_NO_ERROR; + } + break; + case 2: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 2: *result = FULL_LEFT_SHIFT_8_2; return SIMPLICITY_NO_ERROR; + case 3: *result = FULL_LEFT_SHIFT_16_2; return SIMPLICITY_NO_ERROR; + case 4: *result = FULL_LEFT_SHIFT_32_2; return SIMPLICITY_NO_ERROR; + case 5: *result = FULL_LEFT_SHIFT_64_2; return SIMPLICITY_NO_ERROR; + } + break; + case 3: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = FULL_LEFT_SHIFT_8_4; return SIMPLICITY_NO_ERROR; + case 2: *result = FULL_LEFT_SHIFT_16_4; return SIMPLICITY_NO_ERROR; + case 3: *result = FULL_LEFT_SHIFT_32_4; return SIMPLICITY_NO_ERROR; + case 4: *result = FULL_LEFT_SHIFT_64_4; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = FULL_LEFT_SHIFT_16_8; return SIMPLICITY_NO_ERROR; + case 2: *result = FULL_LEFT_SHIFT_32_8; return SIMPLICITY_NO_ERROR; + case 3: *result = FULL_LEFT_SHIFT_64_8; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = FULL_LEFT_SHIFT_32_16; return SIMPLICITY_NO_ERROR; + case 2: *result = FULL_LEFT_SHIFT_64_16; return SIMPLICITY_NO_ERROR; + } + break; + case 6: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = FULL_LEFT_SHIFT_64_32; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 15: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = FULL_RIGHT_SHIFT_8_1; return SIMPLICITY_NO_ERROR; + case 4: *result = FULL_RIGHT_SHIFT_16_1; return SIMPLICITY_NO_ERROR; + case 5: *result = FULL_RIGHT_SHIFT_32_1; return SIMPLICITY_NO_ERROR; + case 6: *result = FULL_RIGHT_SHIFT_64_1; return SIMPLICITY_NO_ERROR; + } + break; + case 2: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 2: *result = FULL_RIGHT_SHIFT_8_2; return SIMPLICITY_NO_ERROR; + case 3: *result = FULL_RIGHT_SHIFT_16_2; return SIMPLICITY_NO_ERROR; + case 4: *result = FULL_RIGHT_SHIFT_32_2; return SIMPLICITY_NO_ERROR; + case 5: *result = FULL_RIGHT_SHIFT_64_2; return SIMPLICITY_NO_ERROR; + } + break; + case 3: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = FULL_RIGHT_SHIFT_8_4; return SIMPLICITY_NO_ERROR; + case 2: *result = FULL_RIGHT_SHIFT_16_4; return SIMPLICITY_NO_ERROR; + case 3: *result = FULL_RIGHT_SHIFT_32_4; return SIMPLICITY_NO_ERROR; + case 4: *result = FULL_RIGHT_SHIFT_64_4; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = FULL_RIGHT_SHIFT_16_8; return SIMPLICITY_NO_ERROR; + case 2: *result = FULL_RIGHT_SHIFT_32_8; return SIMPLICITY_NO_ERROR; + case 3: *result = FULL_RIGHT_SHIFT_64_8; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = FULL_RIGHT_SHIFT_32_16; return SIMPLICITY_NO_ERROR; + case 2: *result = FULL_RIGHT_SHIFT_64_16; return SIMPLICITY_NO_ERROR; + } + break; + case 6: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = FULL_RIGHT_SHIFT_64_32; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 16: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = LEFTMOST_8_1; return SIMPLICITY_NO_ERROR; + case 4: *result = LEFTMOST_16_1; return SIMPLICITY_NO_ERROR; + case 5: *result = LEFTMOST_32_1; return SIMPLICITY_NO_ERROR; + case 6: *result = LEFTMOST_64_1; return SIMPLICITY_NO_ERROR; + } + break; + case 2: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 2: *result = LEFTMOST_8_2; return SIMPLICITY_NO_ERROR; + case 3: *result = LEFTMOST_16_2; return SIMPLICITY_NO_ERROR; + case 4: *result = LEFTMOST_32_2; return SIMPLICITY_NO_ERROR; + case 5: *result = LEFTMOST_64_2; return SIMPLICITY_NO_ERROR; + } + break; + case 3: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFTMOST_8_4; return SIMPLICITY_NO_ERROR; + case 2: *result = LEFTMOST_16_4; return SIMPLICITY_NO_ERROR; + case 3: *result = LEFTMOST_32_4; return SIMPLICITY_NO_ERROR; + case 4: *result = LEFTMOST_64_4; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFTMOST_16_8; return SIMPLICITY_NO_ERROR; + case 2: *result = LEFTMOST_32_8; return SIMPLICITY_NO_ERROR; + case 3: *result = LEFTMOST_64_8; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFTMOST_32_16; return SIMPLICITY_NO_ERROR; + case 2: *result = LEFTMOST_64_16; return SIMPLICITY_NO_ERROR; + } + break; + case 6: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFTMOST_64_32; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 17: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = RIGHTMOST_8_1; return SIMPLICITY_NO_ERROR; + case 4: *result = RIGHTMOST_16_1; return SIMPLICITY_NO_ERROR; + case 5: *result = RIGHTMOST_32_1; return SIMPLICITY_NO_ERROR; + case 6: *result = RIGHTMOST_64_1; return SIMPLICITY_NO_ERROR; + } + break; + case 2: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 2: *result = RIGHTMOST_8_2; return SIMPLICITY_NO_ERROR; + case 3: *result = RIGHTMOST_16_2; return SIMPLICITY_NO_ERROR; + case 4: *result = RIGHTMOST_32_2; return SIMPLICITY_NO_ERROR; + case 5: *result = RIGHTMOST_64_2; return SIMPLICITY_NO_ERROR; + } + break; + case 3: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHTMOST_8_4; return SIMPLICITY_NO_ERROR; + case 2: *result = RIGHTMOST_16_4; return SIMPLICITY_NO_ERROR; + case 3: *result = RIGHTMOST_32_4; return SIMPLICITY_NO_ERROR; + case 4: *result = RIGHTMOST_64_4; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHTMOST_16_8; return SIMPLICITY_NO_ERROR; + case 2: *result = RIGHTMOST_32_8; return SIMPLICITY_NO_ERROR; + case 3: *result = RIGHTMOST_64_8; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHTMOST_32_16; return SIMPLICITY_NO_ERROR; + case 2: *result = RIGHTMOST_64_16; return SIMPLICITY_NO_ERROR; + } + break; + case 6: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHTMOST_64_32; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 18: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = LEFT_PAD_LOW_1_8; return SIMPLICITY_NO_ERROR; + case 4: *result = LEFT_PAD_LOW_1_16; return SIMPLICITY_NO_ERROR; + case 5: *result = LEFT_PAD_LOW_1_32; return SIMPLICITY_NO_ERROR; + case 6: *result = LEFT_PAD_LOW_1_64; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFT_PAD_LOW_8_16; return SIMPLICITY_NO_ERROR; + case 2: *result = LEFT_PAD_LOW_8_32; return SIMPLICITY_NO_ERROR; + case 3: *result = LEFT_PAD_LOW_8_64; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFT_PAD_LOW_16_32; return SIMPLICITY_NO_ERROR; + case 2: *result = LEFT_PAD_LOW_16_64; return SIMPLICITY_NO_ERROR; + } + break; + case 6: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFT_PAD_LOW_32_64; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 19: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = LEFT_PAD_HIGH_1_8; return SIMPLICITY_NO_ERROR; + case 4: *result = LEFT_PAD_HIGH_1_16; return SIMPLICITY_NO_ERROR; + case 5: *result = LEFT_PAD_HIGH_1_32; return SIMPLICITY_NO_ERROR; + case 6: *result = LEFT_PAD_HIGH_1_64; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFT_PAD_HIGH_8_16; return SIMPLICITY_NO_ERROR; + case 2: *result = LEFT_PAD_HIGH_8_32; return SIMPLICITY_NO_ERROR; + case 3: *result = LEFT_PAD_HIGH_8_64; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFT_PAD_HIGH_16_32; return SIMPLICITY_NO_ERROR; + case 2: *result = LEFT_PAD_HIGH_16_64; return SIMPLICITY_NO_ERROR; + } + break; + case 6: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFT_PAD_HIGH_32_64; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 20: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = LEFT_EXTEND_1_8; return SIMPLICITY_NO_ERROR; + case 4: *result = LEFT_EXTEND_1_16; return SIMPLICITY_NO_ERROR; + case 5: *result = LEFT_EXTEND_1_32; return SIMPLICITY_NO_ERROR; + case 6: *result = LEFT_EXTEND_1_64; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFT_EXTEND_8_16; return SIMPLICITY_NO_ERROR; + case 2: *result = LEFT_EXTEND_8_32; return SIMPLICITY_NO_ERROR; + case 3: *result = LEFT_EXTEND_8_64; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFT_EXTEND_16_32; return SIMPLICITY_NO_ERROR; + case 2: *result = LEFT_EXTEND_16_64; return SIMPLICITY_NO_ERROR; + } + break; + case 6: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LEFT_EXTEND_32_64; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 21: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = RIGHT_PAD_LOW_1_8; return SIMPLICITY_NO_ERROR; + case 4: *result = RIGHT_PAD_LOW_1_16; return SIMPLICITY_NO_ERROR; + case 5: *result = RIGHT_PAD_LOW_1_32; return SIMPLICITY_NO_ERROR; + case 6: *result = RIGHT_PAD_LOW_1_64; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHT_PAD_LOW_8_16; return SIMPLICITY_NO_ERROR; + case 2: *result = RIGHT_PAD_LOW_8_32; return SIMPLICITY_NO_ERROR; + case 3: *result = RIGHT_PAD_LOW_8_64; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHT_PAD_LOW_16_32; return SIMPLICITY_NO_ERROR; + case 2: *result = RIGHT_PAD_LOW_16_64; return SIMPLICITY_NO_ERROR; + } + break; + case 6: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHT_PAD_LOW_32_64; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 22: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = RIGHT_PAD_HIGH_1_8; return SIMPLICITY_NO_ERROR; + case 4: *result = RIGHT_PAD_HIGH_1_16; return SIMPLICITY_NO_ERROR; + case 5: *result = RIGHT_PAD_HIGH_1_32; return SIMPLICITY_NO_ERROR; + case 6: *result = RIGHT_PAD_HIGH_1_64; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHT_PAD_HIGH_8_16; return SIMPLICITY_NO_ERROR; + case 2: *result = RIGHT_PAD_HIGH_8_32; return SIMPLICITY_NO_ERROR; + case 3: *result = RIGHT_PAD_HIGH_8_64; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHT_PAD_HIGH_16_32; return SIMPLICITY_NO_ERROR; + case 2: *result = RIGHT_PAD_HIGH_16_64; return SIMPLICITY_NO_ERROR; + } + break; + case 6: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHT_PAD_HIGH_32_64; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 23: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHT_EXTEND_8_16; return SIMPLICITY_NO_ERROR; + case 2: *result = RIGHT_EXTEND_8_32; return SIMPLICITY_NO_ERROR; + case 3: *result = RIGHT_EXTEND_8_64; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHT_EXTEND_16_32; return SIMPLICITY_NO_ERROR; + case 2: *result = RIGHT_EXTEND_16_64; return SIMPLICITY_NO_ERROR; + } + break; + case 6: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = RIGHT_EXTEND_32_64; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 24: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = LEFT_SHIFT_WITH_8; return SIMPLICITY_NO_ERROR; + case 4: *result = LEFT_SHIFT_WITH_16; return SIMPLICITY_NO_ERROR; + case 5: *result = LEFT_SHIFT_WITH_32; return SIMPLICITY_NO_ERROR; + case 6: *result = LEFT_SHIFT_WITH_64; return SIMPLICITY_NO_ERROR; + } + break; + case 25: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = RIGHT_SHIFT_WITH_8; return SIMPLICITY_NO_ERROR; + case 4: *result = RIGHT_SHIFT_WITH_16; return SIMPLICITY_NO_ERROR; + case 5: *result = RIGHT_SHIFT_WITH_32; return SIMPLICITY_NO_ERROR; + case 6: *result = RIGHT_SHIFT_WITH_64; return SIMPLICITY_NO_ERROR; + } + break; + case 26: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = LEFT_SHIFT_8; return SIMPLICITY_NO_ERROR; + case 4: *result = LEFT_SHIFT_16; return SIMPLICITY_NO_ERROR; + case 5: *result = LEFT_SHIFT_32; return SIMPLICITY_NO_ERROR; + case 6: *result = LEFT_SHIFT_64; return SIMPLICITY_NO_ERROR; + } + break; + case 27: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = RIGHT_SHIFT_8; return SIMPLICITY_NO_ERROR; + case 4: *result = RIGHT_SHIFT_16; return SIMPLICITY_NO_ERROR; + case 5: *result = RIGHT_SHIFT_32; return SIMPLICITY_NO_ERROR; + case 6: *result = RIGHT_SHIFT_64; return SIMPLICITY_NO_ERROR; + } + break; + case 28: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = LEFT_ROTATE_8; return SIMPLICITY_NO_ERROR; + case 4: *result = LEFT_ROTATE_16; return SIMPLICITY_NO_ERROR; + case 5: *result = LEFT_ROTATE_32; return SIMPLICITY_NO_ERROR; + case 6: *result = LEFT_ROTATE_64; return SIMPLICITY_NO_ERROR; + } + break; + case 29: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = RIGHT_ROTATE_8; return SIMPLICITY_NO_ERROR; + case 4: *result = RIGHT_ROTATE_16; return SIMPLICITY_NO_ERROR; + case 5: *result = RIGHT_ROTATE_32; return SIMPLICITY_NO_ERROR; + case 6: *result = RIGHT_ROTATE_64; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 2: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = ONE_8; return SIMPLICITY_NO_ERROR; + case 4: *result = ONE_16; return SIMPLICITY_NO_ERROR; + case 5: *result = ONE_32; return SIMPLICITY_NO_ERROR; + case 6: *result = ONE_64; return SIMPLICITY_NO_ERROR; + } + break; + case 2: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = FULL_ADD_8; return SIMPLICITY_NO_ERROR; + case 4: *result = FULL_ADD_16; return SIMPLICITY_NO_ERROR; + case 5: *result = FULL_ADD_32; return SIMPLICITY_NO_ERROR; + case 6: *result = FULL_ADD_64; return SIMPLICITY_NO_ERROR; + } + break; + case 3: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = ADD_8; return SIMPLICITY_NO_ERROR; + case 4: *result = ADD_16; return SIMPLICITY_NO_ERROR; + case 5: *result = ADD_32; return SIMPLICITY_NO_ERROR; + case 6: *result = ADD_64; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = FULL_INCREMENT_8; return SIMPLICITY_NO_ERROR; + case 4: *result = FULL_INCREMENT_16; return SIMPLICITY_NO_ERROR; + case 5: *result = FULL_INCREMENT_32; return SIMPLICITY_NO_ERROR; + case 6: *result = FULL_INCREMENT_64; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = INCREMENT_8; return SIMPLICITY_NO_ERROR; + case 4: *result = INCREMENT_16; return SIMPLICITY_NO_ERROR; + case 5: *result = INCREMENT_32; return SIMPLICITY_NO_ERROR; + case 6: *result = INCREMENT_64; return SIMPLICITY_NO_ERROR; + } + break; + case 7: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = FULL_SUBTRACT_8; return SIMPLICITY_NO_ERROR; + case 4: *result = FULL_SUBTRACT_16; return SIMPLICITY_NO_ERROR; + case 5: *result = FULL_SUBTRACT_32; return SIMPLICITY_NO_ERROR; + case 6: *result = FULL_SUBTRACT_64; return SIMPLICITY_NO_ERROR; + } + break; + case 8: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = SUBTRACT_8; return SIMPLICITY_NO_ERROR; + case 4: *result = SUBTRACT_16; return SIMPLICITY_NO_ERROR; + case 5: *result = SUBTRACT_32; return SIMPLICITY_NO_ERROR; + case 6: *result = SUBTRACT_64; return SIMPLICITY_NO_ERROR; + } + break; + case 9: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = NEGATE_8; return SIMPLICITY_NO_ERROR; + case 4: *result = NEGATE_16; return SIMPLICITY_NO_ERROR; + case 5: *result = NEGATE_32; return SIMPLICITY_NO_ERROR; + case 6: *result = NEGATE_64; return SIMPLICITY_NO_ERROR; + } + break; + case 10: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = FULL_DECREMENT_8; return SIMPLICITY_NO_ERROR; + case 4: *result = FULL_DECREMENT_16; return SIMPLICITY_NO_ERROR; + case 5: *result = FULL_DECREMENT_32; return SIMPLICITY_NO_ERROR; + case 6: *result = FULL_DECREMENT_64; return SIMPLICITY_NO_ERROR; + } + break; + case 11: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = DECREMENT_8; return SIMPLICITY_NO_ERROR; + case 4: *result = DECREMENT_16; return SIMPLICITY_NO_ERROR; + case 5: *result = DECREMENT_32; return SIMPLICITY_NO_ERROR; + case 6: *result = DECREMENT_64; return SIMPLICITY_NO_ERROR; + } + break; + case 12: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = FULL_MULTIPLY_8; return SIMPLICITY_NO_ERROR; + case 4: *result = FULL_MULTIPLY_16; return SIMPLICITY_NO_ERROR; + case 5: *result = FULL_MULTIPLY_32; return SIMPLICITY_NO_ERROR; + case 6: *result = FULL_MULTIPLY_64; return SIMPLICITY_NO_ERROR; + } + break; + case 13: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = MULTIPLY_8; return SIMPLICITY_NO_ERROR; + case 4: *result = MULTIPLY_16; return SIMPLICITY_NO_ERROR; + case 5: *result = MULTIPLY_32; return SIMPLICITY_NO_ERROR; + case 6: *result = MULTIPLY_64; return SIMPLICITY_NO_ERROR; + } + break; + case 14: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = IS_ZERO_8; return SIMPLICITY_NO_ERROR; + case 4: *result = IS_ZERO_16; return SIMPLICITY_NO_ERROR; + case 5: *result = IS_ZERO_32; return SIMPLICITY_NO_ERROR; + case 6: *result = IS_ZERO_64; return SIMPLICITY_NO_ERROR; + } + break; + case 15: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = IS_ONE_8; return SIMPLICITY_NO_ERROR; + case 4: *result = IS_ONE_16; return SIMPLICITY_NO_ERROR; + case 5: *result = IS_ONE_32; return SIMPLICITY_NO_ERROR; + case 6: *result = IS_ONE_64; return SIMPLICITY_NO_ERROR; + } + break; + case 16: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = LE_8; return SIMPLICITY_NO_ERROR; + case 4: *result = LE_16; return SIMPLICITY_NO_ERROR; + case 5: *result = LE_32; return SIMPLICITY_NO_ERROR; + case 6: *result = LE_64; return SIMPLICITY_NO_ERROR; + } + break; + case 17: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = LT_8; return SIMPLICITY_NO_ERROR; + case 4: *result = LT_16; return SIMPLICITY_NO_ERROR; + case 5: *result = LT_32; return SIMPLICITY_NO_ERROR; + case 6: *result = LT_64; return SIMPLICITY_NO_ERROR; + } + break; + case 18: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = MIN_8; return SIMPLICITY_NO_ERROR; + case 4: *result = MIN_16; return SIMPLICITY_NO_ERROR; + case 5: *result = MIN_32; return SIMPLICITY_NO_ERROR; + case 6: *result = MIN_64; return SIMPLICITY_NO_ERROR; + } + break; + case 19: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = MAX_8; return SIMPLICITY_NO_ERROR; + case 4: *result = MAX_16; return SIMPLICITY_NO_ERROR; + case 5: *result = MAX_32; return SIMPLICITY_NO_ERROR; + case 6: *result = MAX_64; return SIMPLICITY_NO_ERROR; + } + break; + case 20: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = MEDIAN_8; return SIMPLICITY_NO_ERROR; + case 4: *result = MEDIAN_16; return SIMPLICITY_NO_ERROR; + case 5: *result = MEDIAN_32; return SIMPLICITY_NO_ERROR; + case 6: *result = MEDIAN_64; return SIMPLICITY_NO_ERROR; + } + break; + case 21: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 6: *result = DIV_MOD_128_64; return SIMPLICITY_NO_ERROR; + } + break; + case 22: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = DIV_MOD_8; return SIMPLICITY_NO_ERROR; + case 4: *result = DIV_MOD_16; return SIMPLICITY_NO_ERROR; + case 5: *result = DIV_MOD_32; return SIMPLICITY_NO_ERROR; + case 6: *result = DIV_MOD_64; return SIMPLICITY_NO_ERROR; + } + break; + case 23: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = DIVIDE_8; return SIMPLICITY_NO_ERROR; + case 4: *result = DIVIDE_16; return SIMPLICITY_NO_ERROR; + case 5: *result = DIVIDE_32; return SIMPLICITY_NO_ERROR; + case 6: *result = DIVIDE_64; return SIMPLICITY_NO_ERROR; + } + break; + case 24: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = MODULO_8; return SIMPLICITY_NO_ERROR; + case 4: *result = MODULO_16; return SIMPLICITY_NO_ERROR; + case 5: *result = MODULO_32; return SIMPLICITY_NO_ERROR; + case 6: *result = MODULO_64; return SIMPLICITY_NO_ERROR; + } + break; + case 25: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 3: *result = DIVIDES_8; return SIMPLICITY_NO_ERROR; + case 4: *result = DIVIDES_16; return SIMPLICITY_NO_ERROR; + case 5: *result = DIVIDES_32; return SIMPLICITY_NO_ERROR; + case 6: *result = DIVIDES_64; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 3: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = SHA_256_BLOCK; return SIMPLICITY_NO_ERROR; + case 2: *result = SHA_256_IV; return SIMPLICITY_NO_ERROR; + case 3: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = SHA_256_CTX_8_ADD_1; return SIMPLICITY_NO_ERROR; + case 2: *result = SHA_256_CTX_8_ADD_2; return SIMPLICITY_NO_ERROR; + case 3: *result = SHA_256_CTX_8_ADD_4; return SIMPLICITY_NO_ERROR; + case 4: *result = SHA_256_CTX_8_ADD_8; return SIMPLICITY_NO_ERROR; + case 5: *result = SHA_256_CTX_8_ADD_16; return SIMPLICITY_NO_ERROR; + case 6: *result = SHA_256_CTX_8_ADD_32; return SIMPLICITY_NO_ERROR; + case 7: *result = SHA_256_CTX_8_ADD_64; return SIMPLICITY_NO_ERROR; + case 8: *result = SHA_256_CTX_8_ADD_128; return SIMPLICITY_NO_ERROR; + case 9: *result = SHA_256_CTX_8_ADD_256; return SIMPLICITY_NO_ERROR; + case 10: *result = SHA_256_CTX_8_ADD_512; return SIMPLICITY_NO_ERROR; + } + break; + case 4: *result = SHA_256_CTX_8_ADD_BUFFER_511; return SIMPLICITY_NO_ERROR; + case 5: *result = SHA_256_CTX_8_FINALIZE; return SIMPLICITY_NO_ERROR; + case 6: *result = SHA_256_CTX_8_INIT; return SIMPLICITY_NO_ERROR; + } + break; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = POINT_VERIFY_1; return SIMPLICITY_NO_ERROR; + } + break; + case 2: *result = DECOMPRESS; return SIMPLICITY_NO_ERROR; + case 3: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LINEAR_VERIFY_1; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = LINEAR_COMBINATION_1; return SIMPLICITY_NO_ERROR; + } + break; + case 5: *result = SCALE; return SIMPLICITY_NO_ERROR; + case 6: *result = GENERATE; return SIMPLICITY_NO_ERROR; + case 7: *result = GEJ_INFINITY; return SIMPLICITY_NO_ERROR; + case 8: *result = GEJ_NORMALIZE; return SIMPLICITY_NO_ERROR; + case 9: *result = GEJ_NEGATE; return SIMPLICITY_NO_ERROR; + case 10: *result = GE_NEGATE; return SIMPLICITY_NO_ERROR; + case 11: *result = GEJ_DOUBLE; return SIMPLICITY_NO_ERROR; + case 12: *result = GEJ_ADD; return SIMPLICITY_NO_ERROR; + case 13: *result = GEJ_GE_ADD_EX; return SIMPLICITY_NO_ERROR; + case 14: *result = GEJ_GE_ADD; return SIMPLICITY_NO_ERROR; + case 15: *result = GEJ_RESCALE; return SIMPLICITY_NO_ERROR; + case 16: *result = GEJ_IS_INFINITY; return SIMPLICITY_NO_ERROR; + case 17: *result = GEJ_EQUIV; return SIMPLICITY_NO_ERROR; + case 18: *result = GEJ_GE_EQUIV; return SIMPLICITY_NO_ERROR; + case 19: *result = GEJ_X_EQUIV; return SIMPLICITY_NO_ERROR; + case 20: *result = GEJ_Y_IS_ODD; return SIMPLICITY_NO_ERROR; + case 21: *result = GEJ_IS_ON_CURVE; return SIMPLICITY_NO_ERROR; + case 22: *result = GE_IS_ON_CURVE; return SIMPLICITY_NO_ERROR; + case 23: *result = SCALAR_NORMALIZE; return SIMPLICITY_NO_ERROR; + case 24: *result = SCALAR_NEGATE; return SIMPLICITY_NO_ERROR; + case 25: *result = SCALAR_ADD; return SIMPLICITY_NO_ERROR; + case 26: *result = SCALAR_SQUARE; return SIMPLICITY_NO_ERROR; + case 27: *result = SCALAR_MULTIPLY; return SIMPLICITY_NO_ERROR; + case 28: *result = SCALAR_MULTIPLY_LAMBDA; return SIMPLICITY_NO_ERROR; + case 29: *result = SCALAR_INVERT; return SIMPLICITY_NO_ERROR; + case 30: *result = SCALAR_IS_ZERO; return SIMPLICITY_NO_ERROR; + case 35: *result = FE_NORMALIZE; return SIMPLICITY_NO_ERROR; + case 36: *result = FE_NEGATE; return SIMPLICITY_NO_ERROR; + case 37: *result = FE_ADD; return SIMPLICITY_NO_ERROR; + case 38: *result = FE_SQUARE; return SIMPLICITY_NO_ERROR; + case 39: *result = FE_MULTIPLY; return SIMPLICITY_NO_ERROR; + case 40: *result = FE_MULTIPLY_BETA; return SIMPLICITY_NO_ERROR; + case 41: *result = FE_INVERT; return SIMPLICITY_NO_ERROR; + case 42: *result = FE_SQUARE_ROOT; return SIMPLICITY_NO_ERROR; + case 43: *result = FE_IS_ZERO; return SIMPLICITY_NO_ERROR; + case 44: *result = FE_IS_ODD; return SIMPLICITY_NO_ERROR; + case 46: *result = HASH_TO_CURVE; return SIMPLICITY_NO_ERROR; + case 47: *result = SWU; return SIMPLICITY_NO_ERROR; + } + break; + case 5: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = CHECK_SIG_VERIFY; return SIMPLICITY_NO_ERROR; + case 2: *result = BIP_0340_VERIFY; return SIMPLICITY_NO_ERROR; + } + break; + case 7: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = PARSE_LOCK; return SIMPLICITY_NO_ERROR; + case 2: *result = PARSE_SEQUENCE; return SIMPLICITY_NO_ERROR; + case 3: *result = TAPDATA_INIT; return SIMPLICITY_NO_ERROR; + } + break; + } +} \ No newline at end of file diff --git a/simplicity-sys/depend/simplicity/deserialize.c b/simplicity-sys/depend/simplicity/deserialize.c index 699fc4a2..d65c0d5c 100644 --- a/simplicity-sys/depend/simplicity/deserialize.c +++ b/simplicity-sys/depend/simplicity/deserialize.c @@ -42,8 +42,8 @@ static simplicity_err getHash(sha256_midstate* result, bitstream* stream) { /* Decode a single node of a Simplicity dag from 'stream' into 'dag'['i']. * Returns 'SIMPLICITY_ERR_FAIL_CODE' if the encoding of a fail expression is encountered * (all fail subexpressions ought to have been pruned prior to serialization). - * Returns 'SIMPLICITY_ERR_STOP_CODE' if the encoding of a stop tag is encountered. - * Returns 'SIMPLICITY_ERR_HIDDEN' if the decoded node has illegal HIDDEN children. + * Returns 'SIMPLICITY_ERR_RESERVED_CODE' if a reserved codeword is encountered. + * Returns 'SIMPLICITY_ERR_HIDDEN' if the decoded node has a HIDDEN child in a position where it is not allowed. * Returns 'SIMPLICITY_ERR_DATA_OUT_OF_RANGE' if the node's child isn't a reference to one of the preceding nodes. * or some encoding for a non-existent jet is encountered * or the size of a WORD encoding is greater than 2^31 bits. @@ -114,7 +114,7 @@ static simplicity_err decodeNode(dag_node* dag, uint_fast32_t i, bitstream* stre case 0: dag[i].tag = IDEN; break; case 1: dag[i].tag = UNIT; break; case 2: return SIMPLICITY_ERR_FAIL_CODE; - case 3: return SIMPLICITY_ERR_STOP_CODE; + case 3: return SIMPLICITY_ERR_RESERVED_CODE; } break; case 3: @@ -143,8 +143,8 @@ static simplicity_err decodeNode(dag_node* dag, uint_fast32_t i, bitstream* stre * Returns 'SIMPLICITY_ERR_DATA_OUT_OF_RANGE' if some node's child isn't a reference to one of the preceding nodes. * Returns 'SIMPLICITY_ERR_FAIL_CODE' if the encoding of a fail expression is encountered * (all fail subexpressions ought to have been pruned prior to deserialization). - * Returns 'SIMPLICITY_ERR_STOP_CODE' if the encoding of a stop tag is encountered. - * Returns 'SIMPLICITY_ERR_HIDDEN' if there are illegal HIDDEN children in the DAG. + * Returns 'SIMPLICITY_ERR_RESERVED_CODE' if a reserved codeword is encountered. + * Returns 'SIMPLICITY_ERR_HIDDEN' if the decoded node has a HIDDEN child in a position where it is not allowed. * Returns 'SIMPLICITY_ERR_BITSTRING_EOF' if not enough bits are available in the 'stream'. * In the above error cases, 'dag' may be modified. * Returns 'SIMPLICITY_NO_ERROR' if successful. @@ -168,8 +168,8 @@ static simplicity_err decodeDag(dag_node* dag, const uint_fast32_t len, combinat * Returns 'SIMPLICITY_ERR_DATA_OUT_OF_RANGE' if some node's child isn't a reference to one of the preceding nodes. * Returns 'SIMPLICITY_ERR_FAIL_CODE' if the encoding of a fail expression is encountered * (all fail subexpressions ought to have been pruned prior to deserialization). - * Returns 'SIMPLICITY_ERR_STOP_CODE' if the encoding of a stop tag is encountered. - * Returns 'SIMPLICITY_ERR_HIDDEN' if there are illegal HIDDEN children in the DAG. + * Returns 'SIMPLICITY_ERR_RESERVED_CODE' if a reserved codeword is encountered. + * Returns 'SIMPLICITY_ERR_HIDDEN' if the decoded node has a HIDDEN child in a position where it is not allowed. * Returns 'SIMPLICITY_ERR_HIDDEN_ROOT' if the root of the DAG is a HIDDEN node. * Returns 'SIMPLICITY_ERR_BITSTRING_EOF' if not enough bits are available in the 'stream'. * Returns 'SIMPLICITY_ERR_DATA_OUT_OF_ORDER' if nodes are not serialized in the canonical order. diff --git a/simplicity-sys/depend/simplicity/deserialize.h b/simplicity-sys/depend/simplicity/deserialize.h index d0ebfb54..d20561b0 100644 --- a/simplicity-sys/depend/simplicity/deserialize.h +++ b/simplicity-sys/depend/simplicity/deserialize.h @@ -11,8 +11,8 @@ * Returns 'SIMPLICITY_ERR_DATA_OUT_OF_RANGE' if some node's child isn't a reference to one of the preceding nodes. * Returns 'SIMPLICITY_ERR_FAIL_CODE' if the encoding of a fail expression is encountered * (all fail subexpressions ought to have been pruned prior to deserialization). - * Returns 'SIMPLICITY_ERR_STOP_CODE' if the encoding of a stop tag is encountered. - * Returns 'SIMPLICITY_ERR_HIDDEN' if there are illegal HIDDEN children in the DAG. + * Returns 'SIMPLICITY_ERR_RESERVED_CODE' if a reserved codeword is encountered. + * Returns 'SIMPLICITY_ERR_HIDDEN' if the decoded node has a HIDDEN child in a position where it is not allowed. * Returns 'SIMPLICITY_ERR_HIDDEN_ROOT' if the root of the DAG is a HIDDEN node. * Returns 'SIMPLICITY_ERR_BITSTRING_EOF' if not enough bits are available in the 'stream'. * Returns 'SIMPLICITY_ERR_MALLOC' if malloc fails. diff --git a/simplicity-sys/depend/simplicity/elements-sources.mk b/simplicity-sys/depend/simplicity/elements-sources.mk index 9c06c87a..189a0498 100644 --- a/simplicity-sys/depend/simplicity/elements-sources.mk +++ b/simplicity-sys/depend/simplicity/elements-sources.mk @@ -35,6 +35,7 @@ ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/bitstream.h ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/bitstring.h ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/bounded.h ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/dag.h +ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/decodeCoreJets.inc ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/deserialize.h ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/eval.h ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/frame.h @@ -88,6 +89,7 @@ ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/secp256k1/secp256k1.h ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/secp256k1/secp256k1_impl.h ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/secp256k1/util.h +ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive/elements/decodeElementsJets.inc ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive/elements/elementsJets.h ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive/elements/ops.h ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive/elements/primitive.h diff --git a/simplicity-sys/depend/simplicity/hashBlock.c b/simplicity-sys/depend/simplicity/hashBlock.c index aea64c51..0839a5d1 100644 --- a/simplicity-sys/depend/simplicity/hashBlock.c +++ b/simplicity-sys/depend/simplicity/hashBlock.c @@ -180,8 +180,8 @@ const uint32_t hashBlock_cmr[] = { 0xa07dd7d8u, 0x22aed1adu, 0x40576a7au, 0x69fa1082u, 0x52d3dd89u, 0x539b1e4eu, 0x1f567851u, 0x9abf54e5u }; -/* The identity Merkle root of the above hashBlock Simplicity expression. */ -const uint32_t hashBlock_imr[] = { +/* The identity hash of the root of the above hashBlock Simplicity expression. */ +const uint32_t hashBlock_ihr[] = { 0x609cc145u, 0x9375db72u, 0x8f2172c9u, 0x62807e31u, 0x61df4cceu, 0xd6592d2cu, 0x4e594a77u, 0x79ab3175u }; diff --git a/simplicity-sys/depend/simplicity/hashBlock.h b/simplicity-sys/depend/simplicity/hashBlock.h index c2f7ec62..e4f7d579 100644 --- a/simplicity-sys/depend/simplicity/hashBlock.h +++ b/simplicity-sys/depend/simplicity/hashBlock.h @@ -16,8 +16,8 @@ extern const size_t sizeof_hashBlock_witness; /* The commitment Merkle root of the above hashBlock Simplicity expression. */ extern const uint32_t hashBlock_cmr[]; -/* The identity Merkle root of the above hashBlock Simplicity expression. */ -extern const uint32_t hashBlock_imr[]; +/* The identity hash of the root of the above hashBlock Simplicity expression. */ +extern const uint32_t hashBlock_ihr[]; /* The annotated Merkle root of the above hashBlock Simplicity expression. */ extern const uint32_t hashBlock_amr[]; diff --git a/simplicity-sys/depend/simplicity/include/simplicity/elements/env.h b/simplicity-sys/depend/simplicity/include/simplicity/elements/env.h index 9d070c23..e5c683f9 100644 --- a/simplicity-sys/depend/simplicity/include/simplicity/elements/env.h +++ b/simplicity-sys/depend/simplicity/include/simplicity/elements/env.h @@ -70,7 +70,8 @@ typedef struct rawInput { /* A structure representing data for an Elements transaction, including the TXO data of each output being redeemed. * - * Invariant: rawInput input[numInputs]; + * Invariant: unsigned char txid[32]; + * rawInput input[numInputs]; * rawOutput output[numOutputs]; */ typedef struct rawTransaction { @@ -86,13 +87,17 @@ typedef struct rawTransaction { /* A forward declaration for the structure containing a copy (and digest) of the rawTransaction data */ typedef struct transaction transaction; -/* Allocate and initialize a 'transaction' from a 'rawOutput', copying or hashing the data as needed. +/* Allocate and initialize a 'transaction' from a 'rawTransaction', copying or hashing the data as needed. * Returns NULL if malloc fails (or if malloc cannot be called because we require an allocation larger than SIZE_MAX). * * Precondition: NULL != rawTx */ extern transaction* simplicity_elements_mallocTransaction(const rawTransaction* rawTx); +/* Free a pointer to 'transaction'. + */ +extern void simplicity_elements_freeTransaction(transaction* tx); + /* A structure representing taproot spending data for an Elements transaction. * * Invariant: pathLen <= 128; @@ -114,4 +119,8 @@ typedef struct tapEnv tapEnv; * Precondition: *rawEnv is well-formed (i.e. rawEnv->pathLen <= 128.) */ extern tapEnv* simplicity_elements_mallocTapEnv(const rawTapEnv* rawEnv); + +/* Free a pointer to 'tapEnv'. + */ +extern void simplicity_elements_freeTapEnv(tapEnv* env); #endif diff --git a/simplicity-sys/depend/simplicity/include/simplicity/elements/exec.h b/simplicity-sys/depend/simplicity/include/simplicity/elements/exec.h index f083642f..758df913 100644 --- a/simplicity-sys/depend/simplicity/include/simplicity/elements/exec.h +++ b/simplicity-sys/depend/simplicity/include/simplicity/elements/exec.h @@ -19,19 +19,20 @@ * * Otherwise '*error' is set to 'SIMPLICITY_NO_ERROR'. * - * If 'imr != NULL' and '*error' is set to 'SIMPLICITY_NO_ERROR', then the identity Merkle root of the decoded expression is written to 'imr'. - * Otherwise if 'imr != NULL' and '*error' is not set to 'SIMPLCITY_NO_ERROR', then 'imr' may or may not be written to. + * If 'ihr != NULL' and '*error' is set to 'SIMPLICITY_NO_ERROR', then the identity hash of the root of the decoded expression is written to 'ihr'. + * Otherwise if 'ihr != NULL' and '*error' is not set to 'SIMPLCITY_NO_ERROR', then 'ihr' may or may not be written to. * * Precondition: NULL != error; - * NULL != imr implies unsigned char imr[32] + * NULL != ihr implies unsigned char ihr[32] * NULL != tx; * NULL != taproot; * unsigned char genesisBlockHash[32] + * 0 <= budget; * NULL != amr implies unsigned char amr[32] * unsigned char program[program_len] * unsigned char witness[witness_len] */ -extern bool simplicity_elements_execSimplicity( simplicity_err* error, unsigned char* imr +extern bool simplicity_elements_execSimplicity( simplicity_err* error, unsigned char* ihr , const transaction* tx, uint_fast32_t ix, const tapEnv* taproot , const unsigned char* genesisBlockHash , int64_t budget diff --git a/simplicity-sys/depend/simplicity/include/simplicity/errorCodes.h b/simplicity-sys/depend/simplicity/include/simplicity/errorCodes.h index 8c1548e0..00ffee51 100644 --- a/simplicity-sys/depend/simplicity/include/simplicity/errorCodes.h +++ b/simplicity-sys/depend/simplicity/include/simplicity/errorCodes.h @@ -16,7 +16,7 @@ typedef enum { SIMPLICITY_ERR_DATA_OUT_OF_RANGE = -2, SIMPLICITY_ERR_DATA_OUT_OF_ORDER = -4, SIMPLICITY_ERR_FAIL_CODE = -6, - SIMPLICITY_ERR_STOP_CODE = -8, + SIMPLICITY_ERR_RESERVED_CODE = -8, SIMPLICITY_ERR_HIDDEN = -10, SIMPLICITY_ERR_BITSTREAM_EOF = -12, SIMPLICITY_ERR_BITSTREAM_TRAILING_BYTES = -14, @@ -62,10 +62,10 @@ static inline const char * SIMPLICITY_ERR_MSG(simplicity_err err) { return "Non-canonical order"; case SIMPLICITY_ERR_FAIL_CODE: return "Program has FAIL node"; - case SIMPLICITY_ERR_STOP_CODE: - return "Program has STOP node"; + case SIMPLICITY_ERR_RESERVED_CODE: + return "Program has reserved codeword"; case SIMPLICITY_ERR_HIDDEN: - return "Program has illegal HIDDEN child node"; + return "Program has node with a HIDDEN child in a position where it is not allowed"; case SIMPLICITY_ERR_BITSTREAM_EOF: return "Unexpected end of bitstream"; case SIMPLICITY_ERR_BITSTREAM_TRAILING_BYTES: diff --git a/simplicity-sys/depend/simplicity/primitive/elements/checkSigHashAllTx1.c b/simplicity-sys/depend/simplicity/primitive/elements/checkSigHashAllTx1.c index b32ef07b..c22d6c86 100644 --- a/simplicity-sys/depend/simplicity/primitive/elements/checkSigHashAllTx1.c +++ b/simplicity-sys/depend/simplicity/primitive/elements/checkSigHashAllTx1.c @@ -28,8 +28,8 @@ const uint32_t elementsCheckSigHashAllTx1_cmr[] = { 0xf3cd4537u, 0xd7ebb201u, 0x73220319u, 0x5b30b549u, 0xb8dc0c2cu, 0x6257b3a0u, 0xd53bedb0u, 0x8ea02874u }; -/* The identity Merkle root of the above elementsCheckSigHashAllTx1 Simplicity expression. */ -const uint32_t elementsCheckSigHashAllTx1_imr[] = { +/* The identity hash of the root of the above elementsCheckSigHashAllTx1 Simplicity expression. */ +const uint32_t elementsCheckSigHashAllTx1_ihr[] = { 0xd3a5130du, 0xf6abce06u, 0x51eb717au, 0x6dd04222u, 0xb7517651u, 0x9117ec5cu, 0x07bb9edbu, 0xac335e1bu }; diff --git a/simplicity-sys/depend/simplicity/primitive/elements/checkSigHashAllTx1.h b/simplicity-sys/depend/simplicity/primitive/elements/checkSigHashAllTx1.h index 75dd1eaa..b2bb7c5d 100644 --- a/simplicity-sys/depend/simplicity/primitive/elements/checkSigHashAllTx1.h +++ b/simplicity-sys/depend/simplicity/primitive/elements/checkSigHashAllTx1.h @@ -20,8 +20,8 @@ extern const size_t sizeof_elementsCheckSigHashAllTx1_witness; /* The commitment Merkle root of the above elementsCheckSigHashAllTx1 Simplicity expression. */ extern const uint32_t elementsCheckSigHashAllTx1_cmr[]; -/* The identity Merkle root of the above elementsCheckSigHashAllTx1 Simplicity expression. */ -extern const uint32_t elementsCheckSigHashAllTx1_imr[]; +/* The identity hash of the root of the above elementsCheckSigHashAllTx1 Simplicity expression. */ +extern const uint32_t elementsCheckSigHashAllTx1_ihr[]; /* The annotated Merkle root of the above elementsCheckSigHashAllTx1 Simplicity expression. */ extern const uint32_t elementsCheckSigHashAllTx1_amr[]; diff --git a/simplicity-sys/depend/simplicity/primitive/elements/decodeElementsJets.inc b/simplicity-sys/depend/simplicity/primitive/elements/decodeElementsJets.inc new file mode 100644 index 00000000..b2478e45 --- /dev/null +++ b/simplicity-sys/depend/simplicity/primitive/elements/decodeElementsJets.inc @@ -0,0 +1,136 @@ +/* This file has been automatically generated. */ + +{ + int32_t code; + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = SIG_ALL_HASH; return SIMPLICITY_NO_ERROR; + case 2: *result = TX_HASH; return SIMPLICITY_NO_ERROR; + case 3: *result = TAP_ENV_HASH; return SIMPLICITY_NO_ERROR; + case 4: *result = OUTPUTS_HASH; return SIMPLICITY_NO_ERROR; + case 5: *result = INPUTS_HASH; return SIMPLICITY_NO_ERROR; + case 6: *result = ISSUANCES_HASH; return SIMPLICITY_NO_ERROR; + case 7: *result = INPUT_UTXOS_HASH; return SIMPLICITY_NO_ERROR; + case 8: *result = OUTPUT_HASH; return SIMPLICITY_NO_ERROR; + case 9: *result = OUTPUT_AMOUNTS_HASH; return SIMPLICITY_NO_ERROR; + case 10: *result = OUTPUT_SCRIPTS_HASH; return SIMPLICITY_NO_ERROR; + case 11: *result = OUTPUT_NONCES_HASH; return SIMPLICITY_NO_ERROR; + case 12: *result = OUTPUT_RANGE_PROOFS_HASH; return SIMPLICITY_NO_ERROR; + case 13: *result = OUTPUT_SURJECTION_PROOFS_HASH; return SIMPLICITY_NO_ERROR; + case 14: *result = INPUT_HASH; return SIMPLICITY_NO_ERROR; + case 15: *result = INPUT_OUTPOINTS_HASH; return SIMPLICITY_NO_ERROR; + case 16: *result = INPUT_SEQUENCES_HASH; return SIMPLICITY_NO_ERROR; + case 17: *result = INPUT_ANNEXES_HASH; return SIMPLICITY_NO_ERROR; + case 18: *result = INPUT_SCRIPT_SIGS_HASH; return SIMPLICITY_NO_ERROR; + case 19: *result = ISSUANCE_HASH; return SIMPLICITY_NO_ERROR; + case 20: *result = ISSUANCE_ASSET_AMOUNTS_HASH; return SIMPLICITY_NO_ERROR; + case 21: *result = ISSUANCE_TOKEN_AMOUNTS_HASH; return SIMPLICITY_NO_ERROR; + case 22: *result = ISSUANCE_RANGE_PROOFS_HASH; return SIMPLICITY_NO_ERROR; + case 23: *result = ISSUANCE_BLINDING_ENTROPY_HASH; return SIMPLICITY_NO_ERROR; + case 24: *result = INPUT_UTXO_HASH; return SIMPLICITY_NO_ERROR; + case 25: *result = INPUT_AMOUNTS_HASH; return SIMPLICITY_NO_ERROR; + case 26: *result = INPUT_SCRIPTS_HASH; return SIMPLICITY_NO_ERROR; + case 27: *result = TAPLEAF_HASH; return SIMPLICITY_NO_ERROR; + case 28: *result = TAPPATH_HASH; return SIMPLICITY_NO_ERROR; + case 29: *result = OUTPOINT_HASH; return SIMPLICITY_NO_ERROR; + case 30: *result = ASSET_AMOUNT_HASH; return SIMPLICITY_NO_ERROR; + case 31: *result = NONCE_HASH; return SIMPLICITY_NO_ERROR; + case 32: *result = ANNEX_HASH; return SIMPLICITY_NO_ERROR; + case 33: *result = BUILD_TAPLEAF_SIMPLICITY; return SIMPLICITY_NO_ERROR; + case 34: *result = BUILD_TAPBRANCH; return SIMPLICITY_NO_ERROR; + case 35: *result = BUILD_TAPTWEAK; return SIMPLICITY_NO_ERROR; + } + break; + case 2: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = CHECK_LOCK_HEIGHT; return SIMPLICITY_NO_ERROR; + case 2: *result = CHECK_LOCK_TIME; return SIMPLICITY_NO_ERROR; + case 3: *result = CHECK_LOCK_DISTANCE; return SIMPLICITY_NO_ERROR; + case 4: *result = CHECK_LOCK_DURATION; return SIMPLICITY_NO_ERROR; + case 5: *result = TX_LOCK_HEIGHT; return SIMPLICITY_NO_ERROR; + case 6: *result = TX_LOCK_TIME; return SIMPLICITY_NO_ERROR; + case 7: *result = TX_LOCK_DISTANCE; return SIMPLICITY_NO_ERROR; + case 8: *result = TX_LOCK_DURATION; return SIMPLICITY_NO_ERROR; + case 9: *result = TX_IS_FINAL; return SIMPLICITY_NO_ERROR; + } + break; + case 3: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = ISSUANCE; return SIMPLICITY_NO_ERROR; + case 2: *result = ISSUANCE_ASSET; return SIMPLICITY_NO_ERROR; + case 3: *result = ISSUANCE_TOKEN; return SIMPLICITY_NO_ERROR; + case 4: *result = ISSUANCE_ENTROPY; return SIMPLICITY_NO_ERROR; + case 5: *result = CALCULATE_ISSUANCE_ENTROPY; return SIMPLICITY_NO_ERROR; + case 6: *result = CALCULATE_ASSET; return SIMPLICITY_NO_ERROR; + case 7: *result = CALCULATE_EXPLICIT_TOKEN; return SIMPLICITY_NO_ERROR; + case 8: *result = CALCULATE_CONFIDENTIAL_TOKEN; return SIMPLICITY_NO_ERROR; + case 9: *result = LBTC_ASSET; return SIMPLICITY_NO_ERROR; + } + break; + case 4: + code = simplicity_decodeUptoMaxInt(stream); + if (code < 0) return (simplicity_err)code; + switch (code) { + case 1: *result = SCRIPT_CMR; return SIMPLICITY_NO_ERROR; + case 2: *result = INTERNAL_KEY; return SIMPLICITY_NO_ERROR; + case 3: *result = CURRENT_INDEX; return SIMPLICITY_NO_ERROR; + case 4: *result = NUM_INPUTS; return SIMPLICITY_NO_ERROR; + case 5: *result = NUM_OUTPUTS; return SIMPLICITY_NO_ERROR; + case 6: *result = LOCK_TIME; return SIMPLICITY_NO_ERROR; + case 7: *result = OUTPUT_ASSET; return SIMPLICITY_NO_ERROR; + case 8: *result = OUTPUT_AMOUNT; return SIMPLICITY_NO_ERROR; + case 9: *result = OUTPUT_NONCE; return SIMPLICITY_NO_ERROR; + case 10: *result = OUTPUT_SCRIPT_HASH; return SIMPLICITY_NO_ERROR; + case 11: *result = OUTPUT_NULL_DATUM; return SIMPLICITY_NO_ERROR; + case 12: *result = OUTPUT_IS_FEE; return SIMPLICITY_NO_ERROR; + case 13: *result = OUTPUT_SURJECTION_PROOF; return SIMPLICITY_NO_ERROR; + case 14: *result = OUTPUT_RANGE_PROOF; return SIMPLICITY_NO_ERROR; + case 15: *result = TOTAL_FEE; return SIMPLICITY_NO_ERROR; + case 16: *result = CURRENT_PEGIN; return SIMPLICITY_NO_ERROR; + case 17: *result = CURRENT_PREV_OUTPOINT; return SIMPLICITY_NO_ERROR; + case 18: *result = CURRENT_ASSET; return SIMPLICITY_NO_ERROR; + case 19: *result = CURRENT_AMOUNT; return SIMPLICITY_NO_ERROR; + case 20: *result = CURRENT_SCRIPT_HASH; return SIMPLICITY_NO_ERROR; + case 21: *result = CURRENT_SEQUENCE; return SIMPLICITY_NO_ERROR; + case 22: *result = CURRENT_ANNEX_HASH; return SIMPLICITY_NO_ERROR; + case 23: *result = CURRENT_SCRIPT_SIG_HASH; return SIMPLICITY_NO_ERROR; + case 24: *result = CURRENT_REISSUANCE_BLINDING; return SIMPLICITY_NO_ERROR; + case 25: *result = CURRENT_NEW_ISSUANCE_CONTRACT; return SIMPLICITY_NO_ERROR; + case 26: *result = CURRENT_REISSUANCE_ENTROPY; return SIMPLICITY_NO_ERROR; + case 27: *result = CURRENT_ISSUANCE_ASSET_AMOUNT; return SIMPLICITY_NO_ERROR; + case 28: *result = CURRENT_ISSUANCE_TOKEN_AMOUNT; return SIMPLICITY_NO_ERROR; + case 29: *result = CURRENT_ISSUANCE_ASSET_PROOF; return SIMPLICITY_NO_ERROR; + case 30: *result = CURRENT_ISSUANCE_TOKEN_PROOF; return SIMPLICITY_NO_ERROR; + case 31: *result = INPUT_PEGIN; return SIMPLICITY_NO_ERROR; + case 32: *result = INPUT_PREV_OUTPOINT; return SIMPLICITY_NO_ERROR; + case 33: *result = INPUT_ASSET; return SIMPLICITY_NO_ERROR; + case 34: *result = INPUT_AMOUNT; return SIMPLICITY_NO_ERROR; + case 35: *result = INPUT_SCRIPT_HASH; return SIMPLICITY_NO_ERROR; + case 36: *result = INPUT_SEQUENCE; return SIMPLICITY_NO_ERROR; + case 37: *result = INPUT_ANNEX_HASH; return SIMPLICITY_NO_ERROR; + case 38: *result = INPUT_SCRIPT_SIG_HASH; return SIMPLICITY_NO_ERROR; + case 39: *result = REISSUANCE_BLINDING; return SIMPLICITY_NO_ERROR; + case 40: *result = NEW_ISSUANCE_CONTRACT; return SIMPLICITY_NO_ERROR; + case 41: *result = REISSUANCE_ENTROPY; return SIMPLICITY_NO_ERROR; + case 42: *result = ISSUANCE_ASSET_AMOUNT; return SIMPLICITY_NO_ERROR; + case 43: *result = ISSUANCE_TOKEN_AMOUNT; return SIMPLICITY_NO_ERROR; + case 44: *result = ISSUANCE_ASSET_PROOF; return SIMPLICITY_NO_ERROR; + case 45: *result = ISSUANCE_TOKEN_PROOF; return SIMPLICITY_NO_ERROR; + case 46: *result = TAPLEAF_VERSION; return SIMPLICITY_NO_ERROR; + case 47: *result = TAPPATH; return SIMPLICITY_NO_ERROR; + case 48: *result = VERSION; return SIMPLICITY_NO_ERROR; + case 49: *result = GENESIS_BLOCK_HASH; return SIMPLICITY_NO_ERROR; + case 50: *result = TRANSACTION_ID; return SIMPLICITY_NO_ERROR; + } + break; + } +} \ No newline at end of file diff --git a/simplicity-sys/depend/simplicity/primitive/elements/env.c b/simplicity-sys/depend/simplicity/primitive/elements/env.c index 3c7adee2..e9f03ac6 100644 --- a/simplicity-sys/depend/simplicity/primitive/elements/env.c +++ b/simplicity-sys/depend/simplicity/primitive/elements/env.c @@ -305,7 +305,8 @@ static uint_fast32_t sumFees(sigOutput** feeOutputs, uint_fast32_t numFees) { return result + 1; } -/* Allocate and initialize a 'transaction' from a 'rawOutput', copying or hashing the data as needed. + +/* Allocate and initialize a 'transaction' from a 'rawTransaction', copying or hashing the data as needed. * Returns NULL if malloc fails (or if malloc cannot be called because we require an allocation larger than SIZE_MAX). * * Precondition: NULL != rawTx @@ -568,6 +569,12 @@ extern transaction* simplicity_elements_mallocTransaction(const rawTransaction* return tx; } +/* Free a pointer to 'transaction'. + */ +extern void simplicity_elements_freeTransaction(transaction* tx) { + simplicity_free(tx); +} + /* Allocate and initialize a 'tapEnv' from a 'rawTapEnv', copying or hashing the data as needed. * Returns NULL if malloc fails (or if malloc cannot be called because we require an allocation larger than SIZE_MAX). * @@ -639,6 +646,12 @@ extern tapEnv* simplicity_elements_mallocTapEnv(const rawTapEnv* rawEnv) { return env; } +/* Free a pointer to 'tapEnv'. + */ +extern void simplicity_elements_freeTapEnv(tapEnv* env) { + simplicity_free(env); +} + /* Contstruct a txEnv structure from its components. * This function will precompute any cached values. * diff --git a/simplicity-sys/depend/simplicity/primitive/elements/exec.c b/simplicity-sys/depend/simplicity/primitive/elements/exec.c index aaffd505..e38c9ca4 100644 --- a/simplicity-sys/depend/simplicity/primitive/elements/exec.c +++ b/simplicity-sys/depend/simplicity/primitive/elements/exec.c @@ -22,11 +22,11 @@ * * Otherwise '*error' is set to 'SIMPLICITY_NO_ERROR'. * - * If 'imr != NULL' and '*error' is set to 'SIMPLICITY_NO_ERROR', then the identity Merkle root of the decoded expression is written to 'imr'. - * Otherwise if 'imr != NULL' and '*error' is not set to 'SIMPLCITY_NO_ERROR', then 'imr' may or may not be written to. + * If 'ihr != NULL' and '*error' is set to 'SIMPLICITY_NO_ERROR', then the identity hash of the root of the decoded expression is written to 'ihr'. + * Otherwise if 'ihr != NULL' and '*error' is not set to 'SIMPLCITY_NO_ERROR', then 'ihr' may or may not be written to. * * Precondition: NULL != error; - * NULL != imr implies unsigned char imr[32] + * NULL != ihr implies unsigned char ihr[32] * NULL != tx; * NULL != taproot; * unsigned char genesisBlockHash[32] @@ -35,7 +35,7 @@ * unsigned char program[program_len] * unsigned char witness[witness_len] */ -extern bool simplicity_elements_execSimplicity( simplicity_err* error, unsigned char* imr +extern bool simplicity_elements_execSimplicity( simplicity_err* error, unsigned char* ihr , const transaction* tx, uint_fast32_t ix, const tapEnv* taproot , const unsigned char* genesisBlockHash , int64_t budget @@ -96,12 +96,9 @@ extern bool simplicity_elements_execSimplicity( simplicity_err* error, unsigned } } if (IS_OK(*error)) { - sha256_midstate imr_buf; - static_assert(DAG_LEN_MAX <= SIZE_MAX / sizeof(sha256_midstate), "imr_buf array too large."); - static_assert(1 <= DAG_LEN_MAX, "DAG_LEN_MAX is zero."); - static_assert(DAG_LEN_MAX - 1 <= UINT32_MAX, "imr_buf array index does nto fit in uint32_t."); - *error = simplicity_verifyNoDuplicateIdentityRoots(&imr_buf, dag, type_dag, (uint_fast32_t)dag_len); - if (IS_OK(*error) && imr) sha256_fromMidstate(imr, imr_buf.s); + sha256_midstate ihr_buf; + *error = simplicity_verifyNoDuplicateIdentityHashes(&ihr_buf, dag, type_dag, (uint_fast32_t)dag_len); + if (IS_OK(*error) && ihr) sha256_fromMidstate(ihr, ihr_buf.s); } if (IS_OK(*error) && amr) { static_assert(DAG_LEN_MAX <= SIZE_MAX / sizeof(analyses), "analysis array too large."); diff --git a/simplicity-sys/depend/simplicity/primitive/elements/primitive.c b/simplicity-sys/depend/simplicity/primitive/elements/primitive.c index f14c2319..da08b920 100644 --- a/simplicity-sys/depend/simplicity/primitive/elements/primitive.c +++ b/simplicity-sys/depend/simplicity/primitive/elements/primitive.c @@ -71,1104 +71,11 @@ static simplicity_err decodePrimitive(jetName* result, bitstream* stream) { if (bit < 0) return (simplicity_err)bit; if (!bit) { /* Core jets */ - int32_t code = simplicity_decodeUptoMaxInt(stream); - int32_t code2; - if (code < 0) return (simplicity_err)code; - - switch (code) { - case 1: /* Word jets chapter */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: /* Verify */ - *result = VERIFY; return SIMPLICITY_NO_ERROR; - case 2: /* Low */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = LOW_1; return SIMPLICITY_NO_ERROR; - case 3: *result = LOW_8; return SIMPLICITY_NO_ERROR; - case 4: *result = LOW_16; return SIMPLICITY_NO_ERROR; - case 5: *result = LOW_32; return SIMPLICITY_NO_ERROR; - case 6: *result = LOW_64; return SIMPLICITY_NO_ERROR; - } - break; - case 3: /* High */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = HIGH_1; return SIMPLICITY_NO_ERROR; - case 3: *result = HIGH_8; return SIMPLICITY_NO_ERROR; - case 4: *result = HIGH_16; return SIMPLICITY_NO_ERROR; - case 5: *result = HIGH_32; return SIMPLICITY_NO_ERROR; - case 6: *result = HIGH_64; return SIMPLICITY_NO_ERROR; - } - break; - case 4: /* Complement */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = COMPLEMENT_1; return SIMPLICITY_NO_ERROR; - case 3: *result = COMPLEMENT_8; return SIMPLICITY_NO_ERROR; - case 4: *result = COMPLEMENT_16; return SIMPLICITY_NO_ERROR; - case 5: *result = COMPLEMENT_32; return SIMPLICITY_NO_ERROR; - case 6: *result = COMPLEMENT_64; return SIMPLICITY_NO_ERROR; - } - break; - case 5: /* And */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = AND_1; return SIMPLICITY_NO_ERROR; - case 3: *result = AND_8; return SIMPLICITY_NO_ERROR; - case 4: *result = AND_16; return SIMPLICITY_NO_ERROR; - case 5: *result = AND_32; return SIMPLICITY_NO_ERROR; - case 6: *result = AND_64; return SIMPLICITY_NO_ERROR; - } - break; - case 6: /* Or */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = OR_1; return SIMPLICITY_NO_ERROR; - case 3: *result = OR_8; return SIMPLICITY_NO_ERROR; - case 4: *result = OR_16; return SIMPLICITY_NO_ERROR; - case 5: *result = OR_32; return SIMPLICITY_NO_ERROR; - case 6: *result = OR_64; return SIMPLICITY_NO_ERROR; - } - break; - case 7: /* Xor */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = XOR_1; return SIMPLICITY_NO_ERROR; - case 3: *result = XOR_8; return SIMPLICITY_NO_ERROR; - case 4: *result = XOR_16; return SIMPLICITY_NO_ERROR; - case 5: *result = XOR_32; return SIMPLICITY_NO_ERROR; - case 6: *result = XOR_64; return SIMPLICITY_NO_ERROR; - } - break; - case 8: /* Maj */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = MAJ_1; return SIMPLICITY_NO_ERROR; - case 3: *result = MAJ_8; return SIMPLICITY_NO_ERROR; - case 4: *result = MAJ_16; return SIMPLICITY_NO_ERROR; - case 5: *result = MAJ_32; return SIMPLICITY_NO_ERROR; - case 6: *result = MAJ_64; return SIMPLICITY_NO_ERROR; - } - break; - case 9: /* Xor_Xor */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = XOR_XOR_1; return SIMPLICITY_NO_ERROR; - case 3: *result = XOR_XOR_8; return SIMPLICITY_NO_ERROR; - case 4: *result = XOR_XOR_16; return SIMPLICITY_NO_ERROR; - case 5: *result = XOR_XOR_32; return SIMPLICITY_NO_ERROR; - case 6: *result = XOR_XOR_64; return SIMPLICITY_NO_ERROR; - } - break; - case 10: /* Ch */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = CH_1; return SIMPLICITY_NO_ERROR; - case 3: *result = CH_8; return SIMPLICITY_NO_ERROR; - case 4: *result = CH_16; return SIMPLICITY_NO_ERROR; - case 5: *result = CH_32; return SIMPLICITY_NO_ERROR; - case 6: *result = CH_64; return SIMPLICITY_NO_ERROR; - } - break; - case 11: /* Some */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = SOME_1; return SIMPLICITY_NO_ERROR; - case 3: *result = SOME_8; return SIMPLICITY_NO_ERROR; - case 4: *result = SOME_16; return SIMPLICITY_NO_ERROR; - case 5: *result = SOME_32; return SIMPLICITY_NO_ERROR; - case 6: *result = SOME_64; return SIMPLICITY_NO_ERROR; - } - break; - case 12: /* All */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = ALL_8; return SIMPLICITY_NO_ERROR; - case 4: *result = ALL_16; return SIMPLICITY_NO_ERROR; - case 5: *result = ALL_32; return SIMPLICITY_NO_ERROR; - case 6: *result = ALL_64; return SIMPLICITY_NO_ERROR; - } - break; - case 13: /* Eq */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = EQ_1; return SIMPLICITY_NO_ERROR; - case 3: *result = EQ_8; return SIMPLICITY_NO_ERROR; - case 4: *result = EQ_16; return SIMPLICITY_NO_ERROR; - case 5: *result = EQ_32; return SIMPLICITY_NO_ERROR; - case 6: *result = EQ_64; return SIMPLICITY_NO_ERROR; - case 8: *result = EQ_256; return SIMPLICITY_NO_ERROR; - } - break; - case 14: /* FullLeftShift */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - code2 = simplicity_decodeUptoMaxInt(stream); - if (code2 < 0) return (simplicity_err)code2; - switch (code) { - case 1: - switch (code2) { - case 3: *result = FULL_LEFT_SHIFT_8_1; return SIMPLICITY_NO_ERROR; - case 4: *result = FULL_LEFT_SHIFT_16_1; return SIMPLICITY_NO_ERROR; - case 5: *result = FULL_LEFT_SHIFT_32_1; return SIMPLICITY_NO_ERROR; - case 6: *result = FULL_LEFT_SHIFT_64_1; return SIMPLICITY_NO_ERROR; - } - break; - case 2: - switch (code2) { - case 2: *result = FULL_LEFT_SHIFT_8_2; return SIMPLICITY_NO_ERROR; - case 3: *result = FULL_LEFT_SHIFT_16_2; return SIMPLICITY_NO_ERROR; - case 4: *result = FULL_LEFT_SHIFT_32_2; return SIMPLICITY_NO_ERROR; - case 5: *result = FULL_LEFT_SHIFT_64_2; return SIMPLICITY_NO_ERROR; - } - break; - case 3: - switch (code2) { - case 1: *result = FULL_LEFT_SHIFT_8_4; return SIMPLICITY_NO_ERROR; - case 2: *result = FULL_LEFT_SHIFT_16_4; return SIMPLICITY_NO_ERROR; - case 3: *result = FULL_LEFT_SHIFT_32_4; return SIMPLICITY_NO_ERROR; - case 4: *result = FULL_LEFT_SHIFT_64_4; return SIMPLICITY_NO_ERROR; - } - break; - case 4: - switch (code2) { - case 1: *result = FULL_LEFT_SHIFT_16_8; return SIMPLICITY_NO_ERROR; - case 2: *result = FULL_LEFT_SHIFT_32_8; return SIMPLICITY_NO_ERROR; - case 3: *result = FULL_LEFT_SHIFT_64_8; return SIMPLICITY_NO_ERROR; - } - break; - case 5: - switch (code2) { - case 1: *result = FULL_LEFT_SHIFT_32_16; return SIMPLICITY_NO_ERROR; - case 2: *result = FULL_LEFT_SHIFT_64_16; return SIMPLICITY_NO_ERROR; - } - break; - case 6: - switch (code2) { - case 1: *result = FULL_LEFT_SHIFT_64_32; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 15: /* FullRightShift */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - code2 = simplicity_decodeUptoMaxInt(stream); - if (code2 < 0) return (simplicity_err)code2; - switch (code) { - case 1: - switch (code2) { - case 3: *result = FULL_RIGHT_SHIFT_8_1; return SIMPLICITY_NO_ERROR; - case 4: *result = FULL_RIGHT_SHIFT_16_1; return SIMPLICITY_NO_ERROR; - case 5: *result = FULL_RIGHT_SHIFT_32_1; return SIMPLICITY_NO_ERROR; - case 6: *result = FULL_RIGHT_SHIFT_64_1; return SIMPLICITY_NO_ERROR; - } - break; - case 2: - switch (code2) { - case 2: *result = FULL_RIGHT_SHIFT_8_2; return SIMPLICITY_NO_ERROR; - case 3: *result = FULL_RIGHT_SHIFT_16_2; return SIMPLICITY_NO_ERROR; - case 4: *result = FULL_RIGHT_SHIFT_32_2; return SIMPLICITY_NO_ERROR; - case 5: *result = FULL_RIGHT_SHIFT_64_2; return SIMPLICITY_NO_ERROR; - } - break; - case 3: - switch (code2) { - case 1: *result = FULL_RIGHT_SHIFT_8_4; return SIMPLICITY_NO_ERROR; - case 2: *result = FULL_RIGHT_SHIFT_16_4; return SIMPLICITY_NO_ERROR; - case 3: *result = FULL_RIGHT_SHIFT_32_4; return SIMPLICITY_NO_ERROR; - case 4: *result = FULL_RIGHT_SHIFT_64_4; return SIMPLICITY_NO_ERROR; - } - break; - case 4: - switch (code2) { - case 1: *result = FULL_RIGHT_SHIFT_16_8; return SIMPLICITY_NO_ERROR; - case 2: *result = FULL_RIGHT_SHIFT_32_8; return SIMPLICITY_NO_ERROR; - case 3: *result = FULL_RIGHT_SHIFT_64_8; return SIMPLICITY_NO_ERROR; - } - break; - case 5: - switch (code2) { - case 1: *result = FULL_RIGHT_SHIFT_32_16; return SIMPLICITY_NO_ERROR; - case 2: *result = FULL_RIGHT_SHIFT_64_16; return SIMPLICITY_NO_ERROR; - } - break; - case 6: - switch (code2) { - case 1: *result = FULL_RIGHT_SHIFT_64_32; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 16: /* Leftmost */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - code2 = simplicity_decodeUptoMaxInt(stream); - if (code2 < 0) return (simplicity_err)code2; - switch (code) { - case 1: - switch (code2) { - case 3: *result = LEFTMOST_8_1; return SIMPLICITY_NO_ERROR; - case 4: *result = LEFTMOST_16_1; return SIMPLICITY_NO_ERROR; - case 5: *result = LEFTMOST_32_1; return SIMPLICITY_NO_ERROR; - case 6: *result = LEFTMOST_64_1; return SIMPLICITY_NO_ERROR; - } - break; - case 2: - switch (code2) { - case 2: *result = LEFTMOST_8_2; return SIMPLICITY_NO_ERROR; - case 3: *result = LEFTMOST_16_2; return SIMPLICITY_NO_ERROR; - case 4: *result = LEFTMOST_32_2; return SIMPLICITY_NO_ERROR; - case 5: *result = LEFTMOST_64_2; return SIMPLICITY_NO_ERROR; - } - break; - case 3: - switch (code2) { - case 1: *result = LEFTMOST_8_4; return SIMPLICITY_NO_ERROR; - case 2: *result = LEFTMOST_16_4; return SIMPLICITY_NO_ERROR; - case 3: *result = LEFTMOST_32_4; return SIMPLICITY_NO_ERROR; - case 4: *result = LEFTMOST_64_4; return SIMPLICITY_NO_ERROR; - } - break; - case 4: - switch (code2) { - case 1: *result = LEFTMOST_16_8; return SIMPLICITY_NO_ERROR; - case 2: *result = LEFTMOST_32_8; return SIMPLICITY_NO_ERROR; - case 3: *result = LEFTMOST_64_8; return SIMPLICITY_NO_ERROR; - } - break; - case 5: - switch (code2) { - case 1: *result = LEFTMOST_32_16; return SIMPLICITY_NO_ERROR; - case 2: *result = LEFTMOST_64_16; return SIMPLICITY_NO_ERROR; - } - break; - case 6: - switch (code2) { - case 1: *result = LEFTMOST_64_32; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 17: /* Rightmost */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - code2 = simplicity_decodeUptoMaxInt(stream); - if (code2 < 0) return (simplicity_err)code2; - switch (code) { - case 1: - switch (code2) { - case 3: *result = RIGHTMOST_8_1; return SIMPLICITY_NO_ERROR; - case 4: *result = RIGHTMOST_16_1; return SIMPLICITY_NO_ERROR; - case 5: *result = RIGHTMOST_32_1; return SIMPLICITY_NO_ERROR; - case 6: *result = RIGHTMOST_64_1; return SIMPLICITY_NO_ERROR; - } - break; - case 2: - switch (code2) { - case 2: *result = RIGHTMOST_8_2; return SIMPLICITY_NO_ERROR; - case 3: *result = RIGHTMOST_16_2; return SIMPLICITY_NO_ERROR; - case 4: *result = RIGHTMOST_32_2; return SIMPLICITY_NO_ERROR; - case 5: *result = RIGHTMOST_64_2; return SIMPLICITY_NO_ERROR; - } - break; - case 3: - switch (code2) { - case 1: *result = RIGHTMOST_8_4; return SIMPLICITY_NO_ERROR; - case 2: *result = RIGHTMOST_16_4; return SIMPLICITY_NO_ERROR; - case 3: *result = RIGHTMOST_32_4; return SIMPLICITY_NO_ERROR; - case 4: *result = RIGHTMOST_64_4; return SIMPLICITY_NO_ERROR; - } - break; - case 4: - switch (code2) { - case 1: *result = RIGHTMOST_16_8; return SIMPLICITY_NO_ERROR; - case 2: *result = RIGHTMOST_32_8; return SIMPLICITY_NO_ERROR; - case 3: *result = RIGHTMOST_64_8; return SIMPLICITY_NO_ERROR; - } - break; - case 5: - switch (code2) { - case 1: *result = RIGHTMOST_32_16; return SIMPLICITY_NO_ERROR; - case 2: *result = RIGHTMOST_64_16; return SIMPLICITY_NO_ERROR; - } - break; - case 6: - switch (code2) { - case 1: *result = RIGHTMOST_64_32; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 18: /* LeftPadLow */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - code2 = simplicity_decodeUptoMaxInt(stream); - if (code2 < 0) return (simplicity_err)code2; - switch (code) { - case 1: - switch (code2) { - case 3: *result = LEFT_PAD_LOW_1_8; return SIMPLICITY_NO_ERROR; - case 4: *result = LEFT_PAD_LOW_1_16; return SIMPLICITY_NO_ERROR; - case 5: *result = LEFT_PAD_LOW_1_32; return SIMPLICITY_NO_ERROR; - case 6: *result = LEFT_PAD_LOW_1_64; return SIMPLICITY_NO_ERROR; - } - break; - case 4: - switch (code2) { - case 1: *result = LEFT_PAD_LOW_8_16; return SIMPLICITY_NO_ERROR; - case 2: *result = LEFT_PAD_LOW_8_32; return SIMPLICITY_NO_ERROR; - case 3: *result = LEFT_PAD_LOW_8_64; return SIMPLICITY_NO_ERROR; - } - break; - case 5: - switch (code2) { - case 1: *result = LEFT_PAD_LOW_16_32; return SIMPLICITY_NO_ERROR; - case 2: *result = LEFT_PAD_LOW_16_64; return SIMPLICITY_NO_ERROR; - } - break; - case 6: - switch (code2) { - case 1: *result = LEFT_PAD_LOW_32_64; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 19: /* LeftPadHigh */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - code2 = simplicity_decodeUptoMaxInt(stream); - if (code2 < 0) return (simplicity_err)code2; - switch (code) { - case 1: - switch (code2) { - case 3: *result = LEFT_PAD_HIGH_1_8; return SIMPLICITY_NO_ERROR; - case 4: *result = LEFT_PAD_HIGH_1_16; return SIMPLICITY_NO_ERROR; - case 5: *result = LEFT_PAD_HIGH_1_32; return SIMPLICITY_NO_ERROR; - case 6: *result = LEFT_PAD_HIGH_1_64; return SIMPLICITY_NO_ERROR; - } - break; - case 4: - switch (code2) { - case 1: *result = LEFT_PAD_HIGH_8_16; return SIMPLICITY_NO_ERROR; - case 2: *result = LEFT_PAD_HIGH_8_32; return SIMPLICITY_NO_ERROR; - case 3: *result = LEFT_PAD_HIGH_8_64; return SIMPLICITY_NO_ERROR; - } - break; - case 5: - switch (code2) { - case 1: *result = LEFT_PAD_HIGH_16_32; return SIMPLICITY_NO_ERROR; - case 2: *result = LEFT_PAD_HIGH_16_64; return SIMPLICITY_NO_ERROR; - } - break; - case 6: - switch (code2) { - case 1: *result = LEFT_PAD_HIGH_32_64; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 20: /* LeftExtend */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - code2 = simplicity_decodeUptoMaxInt(stream); - if (code2 < 0) return (simplicity_err)code2; - switch (code) { - case 1: - switch (code2) { - case 3: *result = LEFT_EXTEND_1_8; return SIMPLICITY_NO_ERROR; - case 4: *result = LEFT_EXTEND_1_16; return SIMPLICITY_NO_ERROR; - case 5: *result = LEFT_EXTEND_1_32; return SIMPLICITY_NO_ERROR; - case 6: *result = LEFT_EXTEND_1_64; return SIMPLICITY_NO_ERROR; - } - break; - case 4: - switch (code2) { - case 1: *result = LEFT_EXTEND_8_16; return SIMPLICITY_NO_ERROR; - case 2: *result = LEFT_EXTEND_8_32; return SIMPLICITY_NO_ERROR; - case 3: *result = LEFT_EXTEND_8_64; return SIMPLICITY_NO_ERROR; - } - break; - case 5: - switch (code2) { - case 1: *result = LEFT_EXTEND_16_32; return SIMPLICITY_NO_ERROR; - case 2: *result = LEFT_EXTEND_16_64; return SIMPLICITY_NO_ERROR; - } - break; - case 6: - switch (code2) { - case 1: *result = LEFT_EXTEND_32_64; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 21: /* RightPadLow */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - code2 = simplicity_decodeUptoMaxInt(stream); - if (code2 < 0) return (simplicity_err)code2; - switch (code) { - case 1: - switch (code2) { - case 3: *result = RIGHT_PAD_LOW_1_8; return SIMPLICITY_NO_ERROR; - case 4: *result = RIGHT_PAD_LOW_1_16; return SIMPLICITY_NO_ERROR; - case 5: *result = RIGHT_PAD_LOW_1_32; return SIMPLICITY_NO_ERROR; - case 6: *result = RIGHT_PAD_LOW_1_64; return SIMPLICITY_NO_ERROR; - } - break; - case 4: - switch (code2) { - case 1: *result = RIGHT_PAD_LOW_8_16; return SIMPLICITY_NO_ERROR; - case 2: *result = RIGHT_PAD_LOW_8_32; return SIMPLICITY_NO_ERROR; - case 3: *result = RIGHT_PAD_LOW_8_64; return SIMPLICITY_NO_ERROR; - } - break; - case 5: - switch (code2) { - case 1: *result = RIGHT_PAD_LOW_16_32; return SIMPLICITY_NO_ERROR; - case 2: *result = RIGHT_PAD_LOW_16_64; return SIMPLICITY_NO_ERROR; - } - break; - case 6: - switch (code2) { - case 1: *result = RIGHT_PAD_LOW_32_64; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 22: /* RightPadHigh */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - code2 = simplicity_decodeUptoMaxInt(stream); - if (code2 < 0) return (simplicity_err)code2; - switch (code) { - case 1: - switch (code2) { - case 3: *result = RIGHT_PAD_HIGH_1_8; return SIMPLICITY_NO_ERROR; - case 4: *result = RIGHT_PAD_HIGH_1_16; return SIMPLICITY_NO_ERROR; - case 5: *result = RIGHT_PAD_HIGH_1_32; return SIMPLICITY_NO_ERROR; - case 6: *result = RIGHT_PAD_HIGH_1_64; return SIMPLICITY_NO_ERROR; - } - break; - case 4: - switch (code2) { - case 1: *result = RIGHT_PAD_HIGH_8_16; return SIMPLICITY_NO_ERROR; - case 2: *result = RIGHT_PAD_HIGH_8_32; return SIMPLICITY_NO_ERROR; - case 3: *result = RIGHT_PAD_HIGH_8_64; return SIMPLICITY_NO_ERROR; - } - break; - case 5: - switch (code2) { - case 1: *result = RIGHT_PAD_HIGH_16_32; return SIMPLICITY_NO_ERROR; - case 2: *result = RIGHT_PAD_HIGH_16_64; return SIMPLICITY_NO_ERROR; - } - break; - case 6: - switch (code2) { - case 1: *result = RIGHT_PAD_HIGH_32_64; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 23: /* RightExtend */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - code2 = simplicity_decodeUptoMaxInt(stream); - if (code2 < 0) return (simplicity_err)code2; - switch (code) { - case 4: - switch (code2) { - case 1: *result = RIGHT_EXTEND_8_16; return SIMPLICITY_NO_ERROR; - case 2: *result = RIGHT_EXTEND_8_32; return SIMPLICITY_NO_ERROR; - case 3: *result = RIGHT_EXTEND_8_64; return SIMPLICITY_NO_ERROR; - } - break; - case 5: - switch (code2) { - case 1: *result = RIGHT_EXTEND_16_32; return SIMPLICITY_NO_ERROR; - case 2: *result = RIGHT_EXTEND_16_64; return SIMPLICITY_NO_ERROR; - } - break; - case 6: - switch (code2) { - case 1: *result = RIGHT_EXTEND_32_64; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 24: /* LeftShiftWith */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = LEFT_SHIFT_WITH_8; return SIMPLICITY_NO_ERROR; - case 4: *result = LEFT_SHIFT_WITH_16; return SIMPLICITY_NO_ERROR; - case 5: *result = LEFT_SHIFT_WITH_32; return SIMPLICITY_NO_ERROR; - case 6: *result = LEFT_SHIFT_WITH_64; return SIMPLICITY_NO_ERROR; - } - break; - case 25: /* RightShiftWith */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = RIGHT_SHIFT_WITH_8; return SIMPLICITY_NO_ERROR; - case 4: *result = RIGHT_SHIFT_WITH_16; return SIMPLICITY_NO_ERROR; - case 5: *result = RIGHT_SHIFT_WITH_32; return SIMPLICITY_NO_ERROR; - case 6: *result = RIGHT_SHIFT_WITH_64; return SIMPLICITY_NO_ERROR; - } - break; - case 26: /* LeftShift */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = LEFT_SHIFT_8; return SIMPLICITY_NO_ERROR; - case 4: *result = LEFT_SHIFT_16; return SIMPLICITY_NO_ERROR; - case 5: *result = LEFT_SHIFT_32; return SIMPLICITY_NO_ERROR; - case 6: *result = LEFT_SHIFT_64; return SIMPLICITY_NO_ERROR; - } - break; - case 27: /* RightShift */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = RIGHT_SHIFT_8; return SIMPLICITY_NO_ERROR; - case 4: *result = RIGHT_SHIFT_16; return SIMPLICITY_NO_ERROR; - case 5: *result = RIGHT_SHIFT_32; return SIMPLICITY_NO_ERROR; - case 6: *result = RIGHT_SHIFT_64; return SIMPLICITY_NO_ERROR; - } - break; - case 28: /* LeftRotate */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = LEFT_ROTATE_8; return SIMPLICITY_NO_ERROR; - case 4: *result = LEFT_ROTATE_16; return SIMPLICITY_NO_ERROR; - case 5: *result = LEFT_ROTATE_32; return SIMPLICITY_NO_ERROR; - case 6: *result = LEFT_ROTATE_64; return SIMPLICITY_NO_ERROR; - } - break; - case 29: /* RightRotate */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = RIGHT_ROTATE_8; return SIMPLICITY_NO_ERROR; - case 4: *result = RIGHT_ROTATE_16; return SIMPLICITY_NO_ERROR; - case 5: *result = RIGHT_ROTATE_32; return SIMPLICITY_NO_ERROR; - case 6: *result = RIGHT_ROTATE_64; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 2: /* Arith jets chapter */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - - switch (code) { - case 1: /* One */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = ONE_8; return SIMPLICITY_NO_ERROR; - case 4: *result = ONE_16; return SIMPLICITY_NO_ERROR; - case 5: *result = ONE_32; return SIMPLICITY_NO_ERROR; - case 6: *result = ONE_64; return SIMPLICITY_NO_ERROR; - } - break; - case 2: /* FullAdd */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = FULL_ADD_8; return SIMPLICITY_NO_ERROR; - case 4: *result = FULL_ADD_16; return SIMPLICITY_NO_ERROR; - case 5: *result = FULL_ADD_32; return SIMPLICITY_NO_ERROR; - case 6: *result = FULL_ADD_64; return SIMPLICITY_NO_ERROR; - } - break; - case 3: /* Add */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = ADD_8; return SIMPLICITY_NO_ERROR; - case 4: *result = ADD_16; return SIMPLICITY_NO_ERROR; - case 5: *result = ADD_32; return SIMPLICITY_NO_ERROR; - case 6: *result = ADD_64; return SIMPLICITY_NO_ERROR; - } - break; - case 4: /* FullIncrement */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = FULL_INCREMENT_8; return SIMPLICITY_NO_ERROR; - case 4: *result = FULL_INCREMENT_16; return SIMPLICITY_NO_ERROR; - case 5: *result = FULL_INCREMENT_32; return SIMPLICITY_NO_ERROR; - case 6: *result = FULL_INCREMENT_64; return SIMPLICITY_NO_ERROR; - } - break; - case 5: /* Increment */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = INCREMENT_8; return SIMPLICITY_NO_ERROR; - case 4: *result = INCREMENT_16; return SIMPLICITY_NO_ERROR; - case 5: *result = INCREMENT_32; return SIMPLICITY_NO_ERROR; - case 6: *result = INCREMENT_64; return SIMPLICITY_NO_ERROR; - } - break; - case 7: /* FullSubtract */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = FULL_SUBTRACT_8; return SIMPLICITY_NO_ERROR; - case 4: *result = FULL_SUBTRACT_16; return SIMPLICITY_NO_ERROR; - case 5: *result = FULL_SUBTRACT_32; return SIMPLICITY_NO_ERROR; - case 6: *result = FULL_SUBTRACT_64; return SIMPLICITY_NO_ERROR; - } - break; - case 8: /* Subtract */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = SUBTRACT_8; return SIMPLICITY_NO_ERROR; - case 4: *result = SUBTRACT_16; return SIMPLICITY_NO_ERROR; - case 5: *result = SUBTRACT_32; return SIMPLICITY_NO_ERROR; - case 6: *result = SUBTRACT_64; return SIMPLICITY_NO_ERROR; - } - break; - case 9: /* Negate */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = NEGATE_8; return SIMPLICITY_NO_ERROR; - case 4: *result = NEGATE_16; return SIMPLICITY_NO_ERROR; - case 5: *result = NEGATE_32; return SIMPLICITY_NO_ERROR; - case 6: *result = NEGATE_64; return SIMPLICITY_NO_ERROR; - } - break; - case 10: /* FullDecrement */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = FULL_DECREMENT_8; return SIMPLICITY_NO_ERROR; - case 4: *result = FULL_DECREMENT_16; return SIMPLICITY_NO_ERROR; - case 5: *result = FULL_DECREMENT_32; return SIMPLICITY_NO_ERROR; - case 6: *result = FULL_DECREMENT_64; return SIMPLICITY_NO_ERROR; - } - break; - case 11: /* Decrement */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = DECREMENT_8; return SIMPLICITY_NO_ERROR; - case 4: *result = DECREMENT_16; return SIMPLICITY_NO_ERROR; - case 5: *result = DECREMENT_32; return SIMPLICITY_NO_ERROR; - case 6: *result = DECREMENT_64; return SIMPLICITY_NO_ERROR; - } - break; - case 12: /* FullMultiply */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = FULL_MULTIPLY_8; return SIMPLICITY_NO_ERROR; - case 4: *result = FULL_MULTIPLY_16; return SIMPLICITY_NO_ERROR; - case 5: *result = FULL_MULTIPLY_32; return SIMPLICITY_NO_ERROR; - case 6: *result = FULL_MULTIPLY_64; return SIMPLICITY_NO_ERROR; - } - break; - case 13: /* Multiply */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = MULTIPLY_8; return SIMPLICITY_NO_ERROR; - case 4: *result = MULTIPLY_16; return SIMPLICITY_NO_ERROR; - case 5: *result = MULTIPLY_32; return SIMPLICITY_NO_ERROR; - case 6: *result = MULTIPLY_64; return SIMPLICITY_NO_ERROR; - } - break; - case 14: /* IsZero */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = IS_ZERO_8; return SIMPLICITY_NO_ERROR; - case 4: *result = IS_ZERO_16; return SIMPLICITY_NO_ERROR; - case 5: *result = IS_ZERO_32; return SIMPLICITY_NO_ERROR; - case 6: *result = IS_ZERO_64; return SIMPLICITY_NO_ERROR; - } - break; - case 15: /* IsOne */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = IS_ONE_8; return SIMPLICITY_NO_ERROR; - case 4: *result = IS_ONE_16; return SIMPLICITY_NO_ERROR; - case 5: *result = IS_ONE_32; return SIMPLICITY_NO_ERROR; - case 6: *result = IS_ONE_64; return SIMPLICITY_NO_ERROR; - } - break; - case 16: /* Le */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = LE_8; return SIMPLICITY_NO_ERROR; - case 4: *result = LE_16; return SIMPLICITY_NO_ERROR; - case 5: *result = LE_32; return SIMPLICITY_NO_ERROR; - case 6: *result = LE_64; return SIMPLICITY_NO_ERROR; - } - break; - case 17: /* Lt */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = LT_8; return SIMPLICITY_NO_ERROR; - case 4: *result = LT_16; return SIMPLICITY_NO_ERROR; - case 5: *result = LT_32; return SIMPLICITY_NO_ERROR; - case 6: *result = LT_64; return SIMPLICITY_NO_ERROR; - } - break; - case 18: /* Min */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = MIN_8; return SIMPLICITY_NO_ERROR; - case 4: *result = MIN_16; return SIMPLICITY_NO_ERROR; - case 5: *result = MIN_32; return SIMPLICITY_NO_ERROR; - case 6: *result = MIN_64; return SIMPLICITY_NO_ERROR; - } - break; - case 19: /* Max */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = MAX_8; return SIMPLICITY_NO_ERROR; - case 4: *result = MAX_16; return SIMPLICITY_NO_ERROR; - case 5: *result = MAX_32; return SIMPLICITY_NO_ERROR; - case 6: *result = MAX_64; return SIMPLICITY_NO_ERROR; - } - break; - case 20: /* Median */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = MEDIAN_8; return SIMPLICITY_NO_ERROR; - case 4: *result = MEDIAN_16; return SIMPLICITY_NO_ERROR; - case 5: *result = MEDIAN_32; return SIMPLICITY_NO_ERROR; - case 6: *result = MEDIAN_64; return SIMPLICITY_NO_ERROR; - } - break; - case 21: /* Div2n1n */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 6: *result = DIV_MOD_128_64; return SIMPLICITY_NO_ERROR; - } - break; - case 22: /* DivMod */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = DIV_MOD_8; return SIMPLICITY_NO_ERROR; - case 4: *result = DIV_MOD_16; return SIMPLICITY_NO_ERROR; - case 5: *result = DIV_MOD_32; return SIMPLICITY_NO_ERROR; - case 6: *result = DIV_MOD_64; return SIMPLICITY_NO_ERROR; - } - break; - case 23: /* Divide */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = DIVIDE_8; return SIMPLICITY_NO_ERROR; - case 4: *result = DIVIDE_16; return SIMPLICITY_NO_ERROR; - case 5: *result = DIVIDE_32; return SIMPLICITY_NO_ERROR; - case 6: *result = DIVIDE_64; return SIMPLICITY_NO_ERROR; - } - break; - case 24: /* Modulo */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = MODULO_8; return SIMPLICITY_NO_ERROR; - case 4: *result = MODULO_16; return SIMPLICITY_NO_ERROR; - case 5: *result = MODULO_32; return SIMPLICITY_NO_ERROR; - case 6: *result = MODULO_64; return SIMPLICITY_NO_ERROR; - } - break; - case 25: /* Divides */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 3: *result = DIVIDES_8; return SIMPLICITY_NO_ERROR; - case 4: *result = DIVIDES_16; return SIMPLICITY_NO_ERROR; - case 5: *result = DIVIDES_32; return SIMPLICITY_NO_ERROR; - case 6: *result = DIVIDES_64; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 3: /* Hash jets chapter */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: /* SHA-256 section */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = SHA_256_BLOCK; return SIMPLICITY_NO_ERROR; - case 2: *result = SHA_256_IV; return SIMPLICITY_NO_ERROR; - case 3: /* SHA-256-CTX-8-ADD-n subsection */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = SHA_256_CTX_8_ADD_1; return SIMPLICITY_NO_ERROR; - case 2: *result = SHA_256_CTX_8_ADD_2; return SIMPLICITY_NO_ERROR; - case 3: *result = SHA_256_CTX_8_ADD_4; return SIMPLICITY_NO_ERROR; - case 4: *result = SHA_256_CTX_8_ADD_8; return SIMPLICITY_NO_ERROR; - case 5: *result = SHA_256_CTX_8_ADD_16; return SIMPLICITY_NO_ERROR; - case 6: *result = SHA_256_CTX_8_ADD_32; return SIMPLICITY_NO_ERROR; - case 7: *result = SHA_256_CTX_8_ADD_64; return SIMPLICITY_NO_ERROR; - case 8: *result = SHA_256_CTX_8_ADD_128; return SIMPLICITY_NO_ERROR; - case 9: *result = SHA_256_CTX_8_ADD_256; return SIMPLICITY_NO_ERROR; - case 10: *result = SHA_256_CTX_8_ADD_512; return SIMPLICITY_NO_ERROR; - } - break; - case 4: *result = SHA_256_CTX_8_ADD_BUFFER_511; return SIMPLICITY_NO_ERROR; - case 5: *result = SHA_256_CTX_8_FINALIZE; return SIMPLICITY_NO_ERROR; - case 6: *result = SHA_256_CTX_8_INIT; return SIMPLICITY_NO_ERROR; - } - break; - } - break; - case 4: /* Secp256k1 jets chapter */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: /* point-verify */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = POINT_VERIFY_1; return SIMPLICITY_NO_ERROR; - } - break; - case 2: *result = DECOMPRESS; return SIMPLICITY_NO_ERROR; - case 3: /* linear-verify */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = LINEAR_VERIFY_1; return SIMPLICITY_NO_ERROR; - } - break; - case 4: /* linear-combination */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = LINEAR_COMBINATION_1; return SIMPLICITY_NO_ERROR; - } - break; - case 5: *result = SCALE; return SIMPLICITY_NO_ERROR; - case 6: *result = GENERATE; return SIMPLICITY_NO_ERROR; - case 7: *result = GEJ_INFINITY; return SIMPLICITY_NO_ERROR; - case 8: *result = GEJ_NORMALIZE; return SIMPLICITY_NO_ERROR; - case 9: *result = GEJ_NEGATE; return SIMPLICITY_NO_ERROR; - case 10: *result = GE_NEGATE; return SIMPLICITY_NO_ERROR; - case 11: *result = GEJ_DOUBLE; return SIMPLICITY_NO_ERROR; - case 12: *result = GEJ_ADD; return SIMPLICITY_NO_ERROR; - case 13: *result = GEJ_GE_ADD_EX; return SIMPLICITY_NO_ERROR; - case 14: *result = GEJ_GE_ADD; return SIMPLICITY_NO_ERROR; - case 15: *result = GEJ_RESCALE; return SIMPLICITY_NO_ERROR; - case 16: *result = GEJ_IS_INFINITY; return SIMPLICITY_NO_ERROR; - case 17: *result = GEJ_EQUIV; return SIMPLICITY_NO_ERROR; - case 18: *result = GEJ_GE_EQUIV; return SIMPLICITY_NO_ERROR; - case 19: *result = GEJ_X_EQUIV; return SIMPLICITY_NO_ERROR; - case 20: *result = GEJ_Y_IS_ODD; return SIMPLICITY_NO_ERROR; - case 21: *result = GEJ_IS_ON_CURVE; return SIMPLICITY_NO_ERROR; - case 22: *result = GE_IS_ON_CURVE; return SIMPLICITY_NO_ERROR; - case 23: *result = SCALAR_NORMALIZE; return SIMPLICITY_NO_ERROR; - case 24: *result = SCALAR_NEGATE; return SIMPLICITY_NO_ERROR; - case 25: *result = SCALAR_ADD; return SIMPLICITY_NO_ERROR; - case 26: *result = SCALAR_SQUARE; return SIMPLICITY_NO_ERROR; - case 27: *result = SCALAR_MULTIPLY; return SIMPLICITY_NO_ERROR; - case 28: *result = SCALAR_MULTIPLY_LAMBDA; return SIMPLICITY_NO_ERROR; - case 29: *result = SCALAR_INVERT; return SIMPLICITY_NO_ERROR; - case 30: *result = SCALAR_IS_ZERO; return SIMPLICITY_NO_ERROR; - - case 35: *result = FE_NORMALIZE; return SIMPLICITY_NO_ERROR; - case 36: *result = FE_NEGATE; return SIMPLICITY_NO_ERROR; - case 37: *result = FE_ADD; return SIMPLICITY_NO_ERROR; - case 38: *result = FE_SQUARE; return SIMPLICITY_NO_ERROR; - case 39: *result = FE_MULTIPLY; return SIMPLICITY_NO_ERROR; - case 40: *result = FE_MULTIPLY_BETA; return SIMPLICITY_NO_ERROR; - case 41: *result = FE_INVERT; return SIMPLICITY_NO_ERROR; - case 42: *result = FE_SQUARE_ROOT; return SIMPLICITY_NO_ERROR; - case 43: *result = FE_IS_ZERO; return SIMPLICITY_NO_ERROR; - case 44: *result = FE_IS_ODD; return SIMPLICITY_NO_ERROR; - - case 46: *result = HASH_TO_CURVE; return SIMPLICITY_NO_ERROR; - case 47: *result = SWU; return SIMPLICITY_NO_ERROR; - } - break; - case 5: /* Signature jets chapter */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = CHECK_SIG_VERIFY; return SIMPLICITY_NO_ERROR; - case 2: *result = BIP_0340_VERIFY; return SIMPLICITY_NO_ERROR; - } - break; - case 7: /* Bitcoin jets chapter */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = PARSE_LOCK; return SIMPLICITY_NO_ERROR; - case 2: *result = PARSE_SEQUENCE; return SIMPLICITY_NO_ERROR; - case 3: *result = TAPDATA_INIT; return SIMPLICITY_NO_ERROR; - } - break; - } +#include "../../decodeCoreJets.inc" return SIMPLICITY_ERR_DATA_OUT_OF_RANGE; } else { /* Elements jets */ - int32_t code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: /* SigHash jets chapter */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = SIG_ALL_HASH; return SIMPLICITY_NO_ERROR; - case 2: *result = TX_HASH; return SIMPLICITY_NO_ERROR; - case 3: *result = TAP_ENV_HASH; return SIMPLICITY_NO_ERROR; - case 4: *result = OUTPUTS_HASH; return SIMPLICITY_NO_ERROR; - case 5: *result = INPUTS_HASH; return SIMPLICITY_NO_ERROR; - case 6: *result = ISSUANCES_HASH; return SIMPLICITY_NO_ERROR; - case 7: *result = INPUT_UTXOS_HASH; return SIMPLICITY_NO_ERROR; - case 8: *result = OUTPUT_HASH; return SIMPLICITY_NO_ERROR; - case 9: *result = OUTPUT_AMOUNTS_HASH; return SIMPLICITY_NO_ERROR; - case 10: *result = OUTPUT_SCRIPTS_HASH; return SIMPLICITY_NO_ERROR; - case 11: *result = OUTPUT_NONCES_HASH; return SIMPLICITY_NO_ERROR; - case 12: *result = OUTPUT_RANGE_PROOFS_HASH; return SIMPLICITY_NO_ERROR; - case 13: *result = OUTPUT_SURJECTION_PROOFS_HASH; return SIMPLICITY_NO_ERROR; - case 14: *result = INPUT_HASH; return SIMPLICITY_NO_ERROR; - case 15: *result = INPUT_OUTPOINTS_HASH; return SIMPLICITY_NO_ERROR; - case 16: *result = INPUT_SEQUENCES_HASH; return SIMPLICITY_NO_ERROR; - case 17: *result = INPUT_ANNEXES_HASH; return SIMPLICITY_NO_ERROR; - case 18: *result = INPUT_SCRIPT_SIGS_HASH; return SIMPLICITY_NO_ERROR; - case 19: *result = ISSUANCE_HASH; return SIMPLICITY_NO_ERROR; - case 20: *result = ISSUANCE_ASSET_AMOUNTS_HASH; return SIMPLICITY_NO_ERROR; - case 21: *result = ISSUANCE_TOKEN_AMOUNTS_HASH; return SIMPLICITY_NO_ERROR; - case 22: *result = ISSUANCE_RANGE_PROOFS_HASH; return SIMPLICITY_NO_ERROR; - case 23: *result = ISSUANCE_BLINDING_ENTROPY_HASH; return SIMPLICITY_NO_ERROR; - case 24: *result = INPUT_UTXO_HASH; return SIMPLICITY_NO_ERROR; - case 25: *result = INPUT_AMOUNTS_HASH; return SIMPLICITY_NO_ERROR; - case 26: *result = INPUT_SCRIPTS_HASH; return SIMPLICITY_NO_ERROR; - case 27: *result = TAPLEAF_HASH; return SIMPLICITY_NO_ERROR; - case 28: *result = TAPPATH_HASH; return SIMPLICITY_NO_ERROR; - case 29: *result = OUTPOINT_HASH; return SIMPLICITY_NO_ERROR; - case 30: *result = ASSET_AMOUNT_HASH; return SIMPLICITY_NO_ERROR; - case 31: *result = NONCE_HASH; return SIMPLICITY_NO_ERROR; - case 32: *result = ANNEX_HASH; return SIMPLICITY_NO_ERROR; - case 33: *result = BUILD_TAPLEAF_SIMPLICITY; return SIMPLICITY_NO_ERROR; - case 34: *result = BUILD_TAPBRANCH; return SIMPLICITY_NO_ERROR; - case 35: *result = BUILD_TAPTWEAK; return SIMPLICITY_NO_ERROR; - } - break; - case 2: /* Timelock jets chapter */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = CHECK_LOCK_HEIGHT; return SIMPLICITY_NO_ERROR; - case 2: *result = CHECK_LOCK_TIME; return SIMPLICITY_NO_ERROR; - case 3: *result = CHECK_LOCK_DISTANCE; return SIMPLICITY_NO_ERROR; - case 4: *result = CHECK_LOCK_DURATION; return SIMPLICITY_NO_ERROR; - case 5: *result = TX_LOCK_HEIGHT; return SIMPLICITY_NO_ERROR; - case 6: *result = TX_LOCK_TIME; return SIMPLICITY_NO_ERROR; - case 7: *result = TX_LOCK_DISTANCE; return SIMPLICITY_NO_ERROR; - case 8: *result = TX_LOCK_DURATION; return SIMPLICITY_NO_ERROR; - case 9: *result = TX_IS_FINAL; return SIMPLICITY_NO_ERROR; - } - break; - case 3: /* Issuance jets chapter */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = ISSUANCE; return SIMPLICITY_NO_ERROR; - case 2: *result = ISSUANCE_ASSET; return SIMPLICITY_NO_ERROR; - case 3: *result = ISSUANCE_TOKEN; return SIMPLICITY_NO_ERROR; - case 4: *result = ISSUANCE_ENTROPY; return SIMPLICITY_NO_ERROR; - case 5: *result = CALCULATE_ISSUANCE_ENTROPY; return SIMPLICITY_NO_ERROR; - case 6: *result = CALCULATE_ASSET; return SIMPLICITY_NO_ERROR; - case 7: *result = CALCULATE_EXPLICIT_TOKEN; return SIMPLICITY_NO_ERROR; - case 8: *result = CALCULATE_CONFIDENTIAL_TOKEN; return SIMPLICITY_NO_ERROR; - case 9: *result = LBTC_ASSET; return SIMPLICITY_NO_ERROR; - } - break; - case 4: /* Transaction jets chapter */ - code = simplicity_decodeUptoMaxInt(stream); - if (code < 0) return (simplicity_err)code; - switch (code) { - case 1: *result = SCRIPT_CMR; return SIMPLICITY_NO_ERROR; - case 2: *result = INTERNAL_KEY; return SIMPLICITY_NO_ERROR; - case 3: *result = CURRENT_INDEX; return SIMPLICITY_NO_ERROR; - case 4: *result = NUM_INPUTS; return SIMPLICITY_NO_ERROR; - case 5: *result = NUM_OUTPUTS; return SIMPLICITY_NO_ERROR; - case 6: *result = LOCK_TIME; return SIMPLICITY_NO_ERROR; - case 7: *result = OUTPUT_ASSET; return SIMPLICITY_NO_ERROR; - case 8: *result = OUTPUT_AMOUNT; return SIMPLICITY_NO_ERROR; - case 9: *result = OUTPUT_NONCE; return SIMPLICITY_NO_ERROR; - case 10: *result = OUTPUT_SCRIPT_HASH; return SIMPLICITY_NO_ERROR; - case 11: *result = OUTPUT_NULL_DATUM; return SIMPLICITY_NO_ERROR; - case 12: *result = OUTPUT_IS_FEE; return SIMPLICITY_NO_ERROR; - case 13: *result = OUTPUT_SURJECTION_PROOF; return SIMPLICITY_NO_ERROR; - case 14: *result = OUTPUT_RANGE_PROOF; return SIMPLICITY_NO_ERROR; - case 15: *result = TOTAL_FEE; return SIMPLICITY_NO_ERROR; - case 16: *result = CURRENT_PEGIN; return SIMPLICITY_NO_ERROR; - case 17: *result = CURRENT_PREV_OUTPOINT; return SIMPLICITY_NO_ERROR; - case 18: *result = CURRENT_ASSET; return SIMPLICITY_NO_ERROR; - case 19: *result = CURRENT_AMOUNT; return SIMPLICITY_NO_ERROR; - case 20: *result = CURRENT_SCRIPT_HASH; return SIMPLICITY_NO_ERROR; - case 21: *result = CURRENT_SEQUENCE; return SIMPLICITY_NO_ERROR; - case 22: *result = CURRENT_ANNEX_HASH; return SIMPLICITY_NO_ERROR; - case 23: *result = CURRENT_SCRIPT_SIG_HASH; return SIMPLICITY_NO_ERROR; - case 24: *result = CURRENT_REISSUANCE_BLINDING; return SIMPLICITY_NO_ERROR; - case 25: *result = CURRENT_NEW_ISSUANCE_CONTRACT; return SIMPLICITY_NO_ERROR; - case 26: *result = CURRENT_REISSUANCE_ENTROPY; return SIMPLICITY_NO_ERROR; - case 27: *result = CURRENT_ISSUANCE_ASSET_AMOUNT; return SIMPLICITY_NO_ERROR; - case 28: *result = CURRENT_ISSUANCE_TOKEN_AMOUNT; return SIMPLICITY_NO_ERROR; - case 29: *result = CURRENT_ISSUANCE_ASSET_PROOF; return SIMPLICITY_NO_ERROR; - case 30: *result = CURRENT_ISSUANCE_TOKEN_PROOF; return SIMPLICITY_NO_ERROR; - case 31: *result = INPUT_PEGIN; return SIMPLICITY_NO_ERROR; - case 32: *result = INPUT_PREV_OUTPOINT; return SIMPLICITY_NO_ERROR; - case 33: *result = INPUT_ASSET; return SIMPLICITY_NO_ERROR; - case 34: *result = INPUT_AMOUNT; return SIMPLICITY_NO_ERROR; - case 35: *result = INPUT_SCRIPT_HASH; return SIMPLICITY_NO_ERROR; - case 36: *result = INPUT_SEQUENCE; return SIMPLICITY_NO_ERROR; - case 37: *result = INPUT_ANNEX_HASH; return SIMPLICITY_NO_ERROR; - case 38: *result = INPUT_SCRIPT_SIG_HASH; return SIMPLICITY_NO_ERROR; - case 39: *result = REISSUANCE_BLINDING; return SIMPLICITY_NO_ERROR; - case 40: *result = NEW_ISSUANCE_CONTRACT; return SIMPLICITY_NO_ERROR; - case 41: *result = REISSUANCE_ENTROPY; return SIMPLICITY_NO_ERROR; - case 42: *result = ISSUANCE_ASSET_AMOUNT; return SIMPLICITY_NO_ERROR; - case 43: *result = ISSUANCE_TOKEN_AMOUNT; return SIMPLICITY_NO_ERROR; - case 44: *result = ISSUANCE_ASSET_PROOF; return SIMPLICITY_NO_ERROR; - case 45: *result = ISSUANCE_TOKEN_PROOF; return SIMPLICITY_NO_ERROR; - case 46: *result = TAPLEAF_VERSION; return SIMPLICITY_NO_ERROR; - case 47: *result = TAPPATH; return SIMPLICITY_NO_ERROR; - case 48: *result = VERSION; return SIMPLICITY_NO_ERROR; - case 49: *result = GENESIS_BLOCK_HASH; return SIMPLICITY_NO_ERROR; - case 50: *result = TRANSACTION_ID; return SIMPLICITY_NO_ERROR; - } - break; - } +#include "decodeElementsJets.inc" return SIMPLICITY_ERR_DATA_OUT_OF_RANGE; } } diff --git a/simplicity-sys/depend/simplicity/schnorr0.c b/simplicity-sys/depend/simplicity/schnorr0.c index 9064f313..bf0a4753 100644 --- a/simplicity-sys/depend/simplicity/schnorr0.c +++ b/simplicity-sys/depend/simplicity/schnorr0.c @@ -29,8 +29,8 @@ const uint32_t schnorr0_cmr[] = { 0x8a9e9767u, 0x6b24be77u, 0x97d9ee0bu, 0xf32dd76bu, 0xcd78028eu, 0x973025f7u, 0x85eae8dcu, 0x91c8a0dau }; -/* The identity Merkle root of the above schnorr0 Simplicity expression. */ -const uint32_t schnorr0_imr[] = { +/* The identity hash of the root of the above schnorr0 Simplicity expression. */ +const uint32_t schnorr0_ihr[] = { 0xad7c38b1u, 0x6b912964u, 0x6dc89b52u, 0xcff144deu, 0x94a80e38u, 0x3c4983b5u, 0x3de65e35u, 0x75abcf38u }; diff --git a/simplicity-sys/depend/simplicity/schnorr0.h b/simplicity-sys/depend/simplicity/schnorr0.h index 6ead60e5..1513d31d 100644 --- a/simplicity-sys/depend/simplicity/schnorr0.h +++ b/simplicity-sys/depend/simplicity/schnorr0.h @@ -20,8 +20,8 @@ extern const size_t sizeof_schnorr0_witness; /* The commitment Merkle root of the above schnorr0 Simplicity expression. */ extern const uint32_t schnorr0_cmr[]; -/* The identity Merkle root of the above schnorr0 Simplicity expression. */ -extern const uint32_t schnorr0_imr[]; +/* The identity hash of the root of the above schnorr0 Simplicity expression. */ +extern const uint32_t schnorr0_ihr[]; /* The annotated Merkle root of the above schnorr0 Simplicity expression. */ extern const uint32_t schnorr0_amr[]; diff --git a/simplicity-sys/depend/simplicity/schnorr6.c b/simplicity-sys/depend/simplicity/schnorr6.c index d02059d2..9b6a11d3 100644 --- a/simplicity-sys/depend/simplicity/schnorr6.c +++ b/simplicity-sys/depend/simplicity/schnorr6.c @@ -29,8 +29,8 @@ const uint32_t schnorr6_cmr[] = { 0x83b6b5bcu, 0xc9bdc956u, 0xaf326376u, 0xf201aa7au, 0x2e65bb9eu, 0xedca6a06u, 0x65976452u, 0x5203cf68u }; -/* The identity Merkle root of the above schnorr6 Simplicity expression. */ -const uint32_t schnorr6_imr[] = { +/* The identity hash of the root of the above schnorr6 Simplicity expression. */ +const uint32_t schnorr6_ihr[] = { 0x53acece2u, 0xa5e61e36u, 0xd6c57f92u, 0x4cff9c45u, 0x0a283badu, 0x853aab59u, 0xebdf384du, 0x26264fefu }; diff --git a/simplicity-sys/depend/simplicity/schnorr6.h b/simplicity-sys/depend/simplicity/schnorr6.h index a90bbd69..8ad66a7b 100644 --- a/simplicity-sys/depend/simplicity/schnorr6.h +++ b/simplicity-sys/depend/simplicity/schnorr6.h @@ -20,8 +20,8 @@ extern const size_t sizeof_schnorr6_witness; /* The commitment Merkle root of the above schnorr6 Simplicity expression. */ extern const uint32_t schnorr6_cmr[]; -/* The identity Merkle root of the above schnorr6 Simplicity expression. */ -extern const uint32_t schnorr6_imr[]; +/* The identity hash of the root of the above schnorr6 Simplicity expression. */ +extern const uint32_t schnorr6_ihr[]; /* The annotated Merkle root of the above schnorr6 Simplicity expression. */ extern const uint32_t schnorr6_amr[]; diff --git a/simplicity-sys/depend/simplicity/secp256k1/int128_struct.h b/simplicity-sys/depend/simplicity/secp256k1/int128_struct.h index 6156f82c..e835062a 100644 --- a/simplicity-sys/depend/simplicity/secp256k1/int128_struct.h +++ b/simplicity-sys/depend/simplicity/secp256k1/int128_struct.h @@ -4,7 +4,7 @@ #include #include "util.h" -typedef struct { +typedef struct secp256k1_uint128 { uint64_t lo; uint64_t hi; } secp256k1_uint128; diff --git a/simplicity-sys/depend/simplicity/secp256k1/modinv64.h b/simplicity-sys/depend/simplicity/secp256k1/modinv64.h index dda494f0..fc263edf 100644 --- a/simplicity-sys/depend/simplicity/secp256k1/modinv64.h +++ b/simplicity-sys/depend/simplicity/secp256k1/modinv64.h @@ -16,11 +16,11 @@ /* A signed 62-bit limb representation of integers. * * Its value is sum(v[i] * 2^(62*i), i=0..4). */ -typedef struct { +typedef struct secp256k1_modinv64_signed62 { int64_t v[5]; } secp256k1_modinv64_signed62; -typedef struct { +typedef struct secp256k1_modinv64_modinfo { /* The modulus in signed62 notation, must be odd and in [3, 2^256]. */ secp256k1_modinv64_signed62 modulus; @@ -28,6 +28,18 @@ typedef struct { uint64_t modulus_inv62; } secp256k1_modinv64_modinfo; +static inline void secp256k1_modinv64_signed62_assign(secp256k1_modinv64_signed62 *dst, const secp256k1_modinv64_signed62 *src) { +#ifdef VST + dst->v[0] = src->v[0]; + dst->v[1] = src->v[1]; + dst->v[2] = src->v[2]; + dst->v[3] = src->v[3]; + dst->v[4] = src->v[4]; +#else + *dst = *src; +#endif +} + /* Replace x with its modular inverse mod modinfo->modulus. x must be in range [0, modulus). * If x is zero, the result will be zero as well. If not, the inverse must exist (i.e., the gcd of * x and modulus must be 1). These rules are automatically satisfied if the modulus is prime. diff --git a/simplicity-sys/depend/simplicity/secp256k1/modinv64_impl.h b/simplicity-sys/depend/simplicity/secp256k1/modinv64_impl.h index 13e2c693..191de31f 100644 --- a/simplicity-sys/depend/simplicity/secp256k1/modinv64_impl.h +++ b/simplicity-sys/depend/simplicity/secp256k1/modinv64_impl.h @@ -22,7 +22,7 @@ * t = [ u v ] * [ q r ] */ -typedef struct { +typedef struct secp256k1_modinv64_trans2x2 { int64_t u, v, q, r; } secp256k1_modinv64_trans2x2; @@ -651,8 +651,10 @@ static void secp256k1_modinv64_var(secp256k1_modinv64_signed62 *x, const secp256 /* Start with d=0, e=1, f=modulus, g=x, eta=-1. */ secp256k1_modinv64_signed62 d = {{0, 0, 0, 0, 0}}; secp256k1_modinv64_signed62 e = {{1, 0, 0, 0, 0}}; - secp256k1_modinv64_signed62 f = modinfo->modulus; - secp256k1_modinv64_signed62 g = *x; + secp256k1_modinv64_signed62 f, g; + secp256k1_modinv64_signed62_assign(&(f), &(modinfo->modulus)); + secp256k1_modinv64_signed62_assign(&(g), &(*x)); + #ifdef VERIFY int i = 0; #endif @@ -723,7 +725,7 @@ static void secp256k1_modinv64_var(secp256k1_modinv64_signed62 *x, const secp256 /* Optionally negate d, normalize to [0,modulus), and return it. */ secp256k1_modinv64_normalize_62(&d, f.v[len - 1], modinfo); - *x = d; + secp256k1_modinv64_signed62_assign(&(*x), &(d)); } #if 0 diff --git a/simplicity-sys/depend/simplicity/secp256k1/precomputed_ecmult.h b/simplicity-sys/depend/simplicity/secp256k1/precomputed_ecmult.h index d04a45c3..a80bc498 100644 --- a/simplicity-sys/depend/simplicity/secp256k1/precomputed_ecmult.h +++ b/simplicity-sys/depend/simplicity/secp256k1/precomputed_ecmult.h @@ -18,7 +18,9 @@ # error Cannot compile precomputed_ecmult.c in exhaustive test mode #endif /* EXHAUSTIVE_TEST_ORDER */ #define WINDOW_G ECMULT_WINDOW_SIZE -static const secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)] = { +static const secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)] +#ifndef VST + = { S(79be667e,f9dcbbac,55a06295,ce870b07,29bfcdb,2dce28d9,59f2815b,16f81798,483ada77,26a3c465,5da4fbfc,e1108a8,fd17b448,a6855419,9c47d08f,fb10d4b8) #if WINDOW_G > 2 ,S(f9308a01,9258c310,49344f85,f89d5229,b531c845,836f99b0,8601f113,bce036f9,388f7b0f,632de814,fe337e6,2a37f356,6500a999,34c2231b,6cb9fd75,84b8e672) @@ -8237,8 +8239,12 @@ static const secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)] = ,S(20990660,f1055420,b885fb0a,38824740,3b141c37,5aa20dce,8a29191a,e77bbb16,7d434476,9e302e38,9e14c02e,f5fd8a5c,64cfcf3d,e9813f1c,f53bc6d3,4da93559) ,S(1e70619c,381a6adc,e5d925e0,c9c74f97,3c02ff64,ff2662d7,34efc485,d2bce895,c923f771,f543ffed,42935c28,8474aaaf,80a46ad4,3c579ce0,bb5e663d,668b24b3) #endif -}; -static const secp256k1_ge_storage secp256k1_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)] = { +} +#endif +; +static const secp256k1_ge_storage secp256k1_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)] +#ifndef VST + = { S(8f68b9d2,f63b5f33,9239c1ad,981f162e,e88c5678,723ea335,1b7b444c,9ec4c0da,662a9f2d,ba063986,de1d90c2,b6be215d,bbea2cfe,95510bfd,f23cbf79,501fff82) #if WINDOW_G > 2 ,S(38381dbe,2e509f22,8ba93363,f2451f08,fd845cb3,51d954be,18e2b8ed,d23809fa,e4a32d0a,fb917dc,b09405a5,520eb1cc,3681fccb,32d8f24d,bd707518,331fed52) @@ -16457,7 +16463,9 @@ static const secp256k1_ge_storage secp256k1_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G ,S(15a1ae40,b4fc51dc,554b75d4,db0c2bfd,62dfbbfc,dede18e1,4edbb689,91525cff,4f0453b7,e4e0e99d,9663e5c6,bb018007,b52c8e14,d78a28d,c4a888e4,8c4326c2) ,S(1b9a142f,fc4d03ea,4b079f2d,b05fad98,8ddb2d32,b359967f,c173801f,63320825,59bda7ed,5b691c20,4fc8f8ac,f53be298,ae628954,a8134d0f,dd097e67,be9ff9b6) #endif -}; +} +#endif +; #undef S #endif /* SECP256K1_PRECOMPUTED_ECMULT_H */ diff --git a/simplicity-sys/depend/simplicity/test.c b/simplicity-sys/depend/simplicity/test.c index b5033bd5..445b5726 100644 --- a/simplicity-sys/depend/simplicity/test.c +++ b/simplicity-sys/depend/simplicity/test.c @@ -127,13 +127,13 @@ static void test_hashBlock(void) { } } { - sha256_midstate imr; - if (IS_OK(simplicity_verifyNoDuplicateIdentityRoots(&imr, dag, type_dag, (uint_fast32_t)len)) && - 0 == memcmp(hashBlock_imr, imr.s, sizeof(uint32_t[8]))) { + sha256_midstate ihr; + if (IS_OK(simplicity_verifyNoDuplicateIdentityHashes(&ihr, dag, type_dag, (uint_fast32_t)len)) && + 0 == memcmp(hashBlock_ihr, ihr.s, sizeof(uint32_t[8]))) { successes++; } else { failures++; - printf("Unexpected IMR of hashblock\n"); + printf("Unexpected IHR of hashblock\n"); } } @@ -187,7 +187,7 @@ static void test_hashBlock(void) { static void test_program(char* name, const unsigned char* program, size_t program_len, const unsigned char* witness, size_t witness_len, simplicity_err expectedResult, const uint32_t* expectedCMR, - const uint32_t* expectedIMR, const uint32_t* expectedAMR, const ubounded *expectedCost) { + const uint32_t* expectedIHR, const uint32_t* expectedAMR, const ubounded *expectedCost) { printf("Test %s\n", name); dag_node* dag; combinator_counters census; @@ -253,13 +253,13 @@ static void test_program(char* name, const unsigned char* program, size_t progra } } { - sha256_midstate imr; - if (IS_OK(simplicity_verifyNoDuplicateIdentityRoots(&imr, dag, type_dag, (uint_fast32_t)len)) && - (!expectedIMR || 0 == memcmp(expectedIMR, imr.s, sizeof(uint32_t[8])))) { + sha256_midstate ihr; + if (IS_OK(simplicity_verifyNoDuplicateIdentityHashes(&ihr, dag, type_dag, (uint_fast32_t)len)) && + (!expectedIHR || 0 == memcmp(expectedIHR, ihr.s, sizeof(uint32_t[8])))) { successes++; } else { failures++; - printf("Unexpected IMR.\n"); + printf("Unexpected IHR.\n"); } } if (expectedCost) { @@ -404,15 +404,15 @@ static void test_elements(void) { } } { - unsigned char imrResult[32]; - if (simplicity_elements_execSimplicity(&execResult, imrResult, tx1, 0, taproot, genesisHash, (elementsCheckSigHashAllTx1_cost + 999)/1000, amr, elementsCheckSigHashAllTx1, sizeof_elementsCheckSigHashAllTx1, elementsCheckSigHashAllTx1_witness, sizeof_elementsCheckSigHashAllTx1_witness) && IS_OK(execResult)) { - sha256_midstate imr; - sha256_toMidstate(imr.s, imrResult); - if (0 == memcmp(imr.s, elementsCheckSigHashAllTx1_imr, sizeof(uint32_t[8]))) { + unsigned char ihrResult[32]; + if (simplicity_elements_execSimplicity(&execResult, ihrResult, tx1, 0, taproot, genesisHash, (elementsCheckSigHashAllTx1_cost + 999)/1000, amr, elementsCheckSigHashAllTx1, sizeof_elementsCheckSigHashAllTx1, elementsCheckSigHashAllTx1_witness, sizeof_elementsCheckSigHashAllTx1_witness) && IS_OK(execResult)) { + sha256_midstate ihr; + sha256_toMidstate(ihr.s, ihrResult); + if (0 == memcmp(ihr.s, elementsCheckSigHashAllTx1_ihr, sizeof(uint32_t[8]))) { successes++; } else { failures++; - printf("Unexpected IMR of elementsCheckSigHashAllTx1\n"); + printf("Unexpected IHR of elementsCheckSigHashAllTx1\n"); } } else { failures++; @@ -421,7 +421,7 @@ static void test_elements(void) { if (elementsCheckSigHashAllTx1_cost){ /* test the same transaction without adequate budget. */ simplicity_assert(elementsCheckSigHashAllTx1_cost); - if (simplicity_elements_execSimplicity(&execResult, imrResult, tx1, 0, taproot, genesisHash, (elementsCheckSigHashAllTx1_cost - 1)/1000, amr, elementsCheckSigHashAllTx1, sizeof_elementsCheckSigHashAllTx1, elementsCheckSigHashAllTx1_witness, sizeof_elementsCheckSigHashAllTx1_witness) && SIMPLICITY_ERR_EXEC_BUDGET == execResult) { + if (simplicity_elements_execSimplicity(&execResult, ihrResult, tx1, 0, taproot, genesisHash, (elementsCheckSigHashAllTx1_cost - 1)/1000, amr, elementsCheckSigHashAllTx1, sizeof_elementsCheckSigHashAllTx1, elementsCheckSigHashAllTx1_witness, sizeof_elementsCheckSigHashAllTx1_witness) && SIMPLICITY_ERR_EXEC_BUDGET == execResult) { successes++; } else { failures++; @@ -445,7 +445,7 @@ static void test_elements(void) { printf("mallocTransaction(&rawTx1) failed\n"); failures++; } - simplicity_free(tx1); + simplicity_elements_freeTransaction(tx1); } /* test a modified transaction with the same signature. */ { @@ -494,9 +494,9 @@ static void test_elements(void) { printf("mallocTransaction(&testTx2) failed\n"); failures++; } - simplicity_free(tx2); + simplicity_elements_freeTransaction(tx2); } - simplicity_free(taproot); + simplicity_elements_freeTapEnv(taproot); } static sha256_midstate hashint(uint_fast32_t n) { @@ -664,16 +664,16 @@ int main(int argc, char **argv) { test_hasDuplicates("hasDuplicates one duplicate testcase", 1, rsort_one_duplicate, 10000); test_hasDuplicates("hasDuplicates diagonal testcase", 0, rsort_diagonal, 33); - test_program("ctx8Pruned", ctx8Pruned, sizeof_ctx8Pruned, ctx8Pruned_witness, sizeof_ctx8Pruned_witness, SIMPLICITY_NO_ERROR, ctx8Pruned_cmr, ctx8Pruned_imr, ctx8Pruned_amr, &ctx8Pruned_cost); - test_program("ctx8Unpruned", ctx8Unpruned, sizeof_ctx8Unpruned, ctx8Unpruned_witness, sizeof_ctx8Unpruned_witness, SIMPLICITY_ERR_ANTIDOS, ctx8Unpruned_cmr, ctx8Unpruned_imr, ctx8Unpruned_amr, &ctx8Unpruned_cost); + test_program("ctx8Pruned", ctx8Pruned, sizeof_ctx8Pruned, ctx8Pruned_witness, sizeof_ctx8Pruned_witness, SIMPLICITY_NO_ERROR, ctx8Pruned_cmr, ctx8Pruned_ihr, ctx8Pruned_amr, &ctx8Pruned_cost); + test_program("ctx8Unpruned", ctx8Unpruned, sizeof_ctx8Unpruned, ctx8Unpruned_witness, sizeof_ctx8Unpruned_witness, SIMPLICITY_ERR_ANTIDOS, ctx8Unpruned_cmr, ctx8Unpruned_ihr, ctx8Unpruned_amr, &ctx8Unpruned_cost); if (0 == memcmp(ctx8Pruned_cmr, ctx8Unpruned_cmr, sizeof(uint32_t[8]))) { successes++; } else { failures++; printf("Pruned and Unpruned CMRs are not the same.\n"); } - test_program("schnorr0", schnorr0, sizeof_schnorr0, schnorr0_witness, sizeof_schnorr0_witness, SIMPLICITY_NO_ERROR, schnorr0_cmr, schnorr0_imr, schnorr0_amr, &schnorr0_cost); - test_program("schnorr6", schnorr6, sizeof_schnorr6, schnorr6_witness, sizeof_schnorr6_witness, SIMPLICITY_ERR_EXEC_JET, schnorr6_cmr, schnorr6_imr, schnorr6_amr, &schnorr0_cost); + test_program("schnorr0", schnorr0, sizeof_schnorr0, schnorr0_witness, sizeof_schnorr0_witness, SIMPLICITY_NO_ERROR, schnorr0_cmr, schnorr0_ihr, schnorr0_amr, &schnorr0_cost); + test_program("schnorr6", schnorr6, sizeof_schnorr6, schnorr6_witness, sizeof_schnorr6_witness, SIMPLICITY_ERR_EXEC_JET, schnorr6_cmr, schnorr6_ihr, schnorr6_amr, &schnorr0_cost); test_program("typeSkipTest", typeSkipTest, sizeof_typeSkipTest, typeSkipTest_witness, sizeof_typeSkipTest_witness, SIMPLICITY_NO_ERROR, NULL, NULL, NULL, NULL); test_elements(); regression_tests(); diff --git a/simplicity-sys/depend/simplicity/typeSkipTest.c b/simplicity-sys/depend/simplicity/typeSkipTest.c index 1a8ac83a..0629f164 100644 --- a/simplicity-sys/depend/simplicity/typeSkipTest.c +++ b/simplicity-sys/depend/simplicity/typeSkipTest.c @@ -48,8 +48,8 @@ const uint32_t typeSkipTest_cmr[] = { 0x2a791cd8u, 0xf1e2beeau, 0x883e53f2u, 0xce36db2bu, 0x246b3156u, 0xcc40f91bu, 0xb2f59059u, 0xb601ac4au }; -/* The identity Merkle root of the above typeSkipTest Simplicity expression. */ -const uint32_t typeSkipTest_imr[] = { +/* The identity hash of the root of the above typeSkipTest Simplicity expression. */ +const uint32_t typeSkipTest_ihr[] = { 0xbadac773u, 0x19e9cabau, 0x7fe49174u, 0x54d0e25eu, 0x7d4c4a7eu, 0x4867c392u, 0x20bf409au, 0xc6e6bf10u }; diff --git a/simplicity-sys/depend/simplicity/typeSkipTest.h b/simplicity-sys/depend/simplicity/typeSkipTest.h index 73b308b5..61230c10 100644 --- a/simplicity-sys/depend/simplicity/typeSkipTest.h +++ b/simplicity-sys/depend/simplicity/typeSkipTest.h @@ -38,8 +38,8 @@ extern const size_t sizeof_typeSkipTest_witness; /* The commitment Merkle root of the above typeSkipTest Simplicity expression. */ extern const uint32_t typeSkipTest_cmr[]; -/* The identity Merkle root of the above typeSkipTest Simplicity expression. */ -extern const uint32_t typeSkipTest_imr[]; +/* The identity hash of the root of the above typeSkipTest Simplicity expression. */ +extern const uint32_t typeSkipTest_ihr[]; /* The annotated Merkle root of the above typeSkipTest Simplicity expression. */ extern const uint32_t typeSkipTest_amr[]; From 5c348123ad52e7d5167ee82ee1dfbbe1c1b67531 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Wed, 12 Feb 2025 00:48:37 +0000 Subject: [PATCH 2/2] simplicity-sys: rename IMR to IHR everywhere --- simplicity-sys/src/tests/ffi.rs | 16 ++++++------ simplicity-sys/src/tests/mod.rs | 46 ++++++++++++++++----------------- src/node/mod.rs | 2 +- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/simplicity-sys/src/tests/ffi.rs b/simplicity-sys/src/tests/ffi.rs index 16fa4adf..a47d99d4 100644 --- a/simplicity-sys/src/tests/ffi.rs +++ b/simplicity-sys/src/tests/ffi.rs @@ -309,8 +309,8 @@ pub mod dag { ) -> SimplicityErr; /// Computes the identity Merkle roots of every subexpression in a well-typed 'dag' with witnesses . - pub fn simplicity_verifyNoDuplicateIdentityRoots( - imr: *mut CSha256Midstate, + pub fn simplicity_verifyNoDuplicateIdentityHashes( + ihr: *mut CSha256Midstate, dag: *const CDagNode, type_dag: *const CType, len: c_size_t, @@ -476,7 +476,7 @@ extern "C" { pub static ctx8Pruned_witness: [u8; 0]; pub static ctx8Pruned_amr: [u32; 8]; pub static ctx8Pruned_cmr: [u32; 8]; - pub static ctx8Pruned_imr: [u32; 8]; + pub static ctx8Pruned_ihr: [u32; 8]; pub static ctx8Pruned_cost: ubounded; pub static sizeof_ctx8Unpruned: c_size_t; @@ -485,7 +485,7 @@ extern "C" { pub static ctx8Unpruned_witness: [u8; 0]; pub static ctx8Unpruned_amr: [u32; 8]; pub static ctx8Unpruned_cmr: [u32; 8]; - pub static ctx8Unpruned_imr: [u32; 8]; + pub static ctx8Unpruned_ihr: [u32; 8]; pub static ctx8Unpruned_cost: ubounded; pub static sizeof_schnorr0: c_size_t; @@ -494,7 +494,7 @@ extern "C" { pub static schnorr0_witness: [u8; 64]; pub static schnorr0_amr: [u32; 8]; pub static schnorr0_cmr: [u32; 8]; - pub static schnorr0_imr: [u32; 8]; + pub static schnorr0_ihr: [u32; 8]; pub static schnorr0_cost: ubounded; pub static sizeof_schnorr6: c_size_t; @@ -503,7 +503,7 @@ extern "C" { pub static schnorr6_witness: [u8; 64]; pub static schnorr6_amr: [u32; 8]; pub static schnorr6_cmr: [u32; 8]; - pub static schnorr6_imr: [u32; 8]; + pub static schnorr6_ihr: [u32; 8]; pub static schnorr6_cost: ubounded; /* @@ -512,13 +512,13 @@ extern "C" { pub static hashBlock: [u8; 3259]; pub static hashBlock_amr: [u32; 8]; pub static hashBlock_cmr: [u32; 8]; - pub static hashBlock_imr: [u32; 8]; + pub static hashBlock_ihr: [u32; 8]; // FIXME enable this test; requires a little but of extra work to set up an Elements env pub static elementsCheckSigHashAllTx1: [u8; 1151]; pub static elementsCheckSigHashAllTx1_amr: [u32; 8]; pub static elementsCheckSigHashAllTx1_cmr: [u32; 8]; - pub static elementsCheckSigHashAllTx1_imr: [u32; 8]; + pub static elementsCheckSigHashAllTx1_ihr: [u32; 8]; */ } diff --git a/simplicity-sys/src/tests/mod.rs b/simplicity-sys/src/tests/mod.rs index fa68bf7c..47078a77 100644 --- a/simplicity-sys/src/tests/mod.rs +++ b/simplicity-sys/src/tests/mod.rs @@ -9,7 +9,7 @@ use crate::tests::ffi::{ bitstream::{simplicity_closeBitstream, CBitstream}, dag::{ simplicity_computeAnnotatedMerkleRoot, simplicity_fillWitnessData, - simplicity_verifyNoDuplicateIdentityRoots, CAnalyses, CCombinatorCounters, + simplicity_verifyNoDuplicateIdentityHashes, CAnalyses, CCombinatorCounters, }, deserialize::simplicity_decodeMallocDag, eval::{simplicity_analyseBounds, simplicity_evalTCOProgram}, @@ -25,8 +25,8 @@ pub struct TestOutput { pub amr: CSha256Midstate, /// The CMR of the root node pub cmr: CSha256Midstate, - /// The IMR of the root node - pub imr: CSha256Midstate, + /// The IHR of the root node + pub ihr: CSha256Midstate, /// The cost bound of the program pub cost_bound: ubounded, /// Whether or not evaluation succeded @@ -46,8 +46,8 @@ pub enum TestUpTo { FillWitnessData, /// Compute and retrieve the root AMR. ComputeAmr, - /// Compute and retrieve the root IMR; check that all IMRs are unique - ComputeImr, + /// Compute and retrieve the root IHR; check that all IHRs are unique + ComputeIhr, /// Compute and retrieve the expected cost without any bounds ComputeCostUnbounded, /// Compute and retrieve the expected cost with strict bounds @@ -57,7 +57,7 @@ pub enum TestUpTo { /// Fail the analysis if insufficient budget is provided CheckBudget, /// Check that the program is 1-1. This will exclude arbitrary expressions, so - /// you may want to stop at `ComputeImr` to get the maximum merkle root coverage. + /// you may want to stop at `ComputeIhr` to get the maximum merkle root coverage. CheckOneOne, /// Evaluate the program and retrieve whether it succeded. Everything, @@ -69,13 +69,13 @@ pub fn run_test( witness: &[u8], target_amr: &[u32; 8], target_cmr: &[u32; 8], - target_imr: &[u32; 8], + target_ihr: &[u32; 8], cost_bound: ubounded, ) { let result = run_program(program, witness, TestUpTo::Everything).expect("running program"); assert_eq!(result.amr, CSha256Midstate { s: *target_amr }); assert_eq!(result.cmr, CSha256Midstate { s: *target_cmr }); - assert_eq!(result.imr, CSha256Midstate { s: *target_imr }); + assert_eq!(result.ihr, CSha256Midstate { s: *target_ihr }); assert_eq!(result.cost_bound, cost_bound); assert_eq!(result.eval_result, SimplicityErr::NoError); } @@ -87,13 +87,13 @@ pub fn run_test_fail( target_result: SimplicityErr, target_amr: &[u32; 8], target_cmr: &[u32; 8], - target_imr: &[u32; 8], + target_ihr: &[u32; 8], cost_bound: ubounded, ) { let result = run_program(program, witness, TestUpTo::Everything).expect("running program"); assert_eq!(result.amr, CSha256Midstate { s: *target_amr }); assert_eq!(result.cmr, CSha256Midstate { s: *target_cmr }); - assert_eq!(result.imr, CSha256Midstate { s: *target_imr }); + assert_eq!(result.ihr, CSha256Midstate { s: *target_ihr }); assert_eq!(result.cost_bound, cost_bound); assert_eq!(result.eval_result, target_result); } @@ -118,7 +118,7 @@ pub fn run_program( let mut result = TestOutput { amr: CSha256Midstate::default(), cmr: CSha256Midstate::default(), - imr: CSha256Midstate::default(), + ihr: CSha256Midstate::default(), cost_bound: 0, eval_result: SimplicityErr::NoError, }; @@ -169,10 +169,10 @@ pub fn run_program( return Ok(result); } - // 6. Check IMR - simplicity_verifyNoDuplicateIdentityRoots(&mut result.imr, dag, type_dag, len) + // 6. Check IHR + simplicity_verifyNoDuplicateIdentityHashes(&mut result.ihr, dag, type_dag, len) .into_result()?; - if test_up_to <= TestUpTo::ComputeImr { + if test_up_to <= TestUpTo::ComputeIhr { return Ok(result); } @@ -289,7 +289,7 @@ pub fn parse_root(ptr: &[u32; 8]) -> [u8; 32] { pub struct TestData { pub cmr: [u8; 32], pub amr: [u8; 32], - pub imr: [u8; 32], + pub ihr: [u8; 32], pub prog: Vec, pub witness: Vec, pub cost: ubounded, @@ -304,7 +304,7 @@ mod test_data { TestData { cmr: parse_root(&ffi::schnorr0_cmr), amr: parse_root(&ffi::schnorr0_amr), - imr: parse_root(&ffi::schnorr0_imr), + ihr: parse_root(&ffi::schnorr0_ihr), prog: slice::from_raw_parts(ffi::schnorr0.as_ptr(), ffi::sizeof_schnorr0).into(), witness: slice::from_raw_parts( ffi::schnorr0_witness.as_ptr(), @@ -321,7 +321,7 @@ mod test_data { TestData { cmr: parse_root(&ffi::schnorr6_cmr), amr: parse_root(&ffi::schnorr6_amr), - imr: parse_root(&ffi::schnorr6_imr), + ihr: parse_root(&ffi::schnorr6_ihr), prog: slice::from_raw_parts(ffi::schnorr6.as_ptr(), ffi::sizeof_schnorr6).into(), witness: slice::from_raw_parts( ffi::schnorr6_witness.as_ptr(), @@ -338,7 +338,7 @@ mod test_data { TestData { cmr: parse_root(&ffi::ctx8Pruned_cmr), amr: parse_root(&ffi::ctx8Pruned_amr), - imr: parse_root(&ffi::ctx8Pruned_imr), + ihr: parse_root(&ffi::ctx8Pruned_ihr), prog: slice::from_raw_parts(ffi::ctx8Pruned.as_ptr(), ffi::sizeof_ctx8Pruned) .into(), witness: slice::from_raw_parts( @@ -356,7 +356,7 @@ mod test_data { TestData { cmr: parse_root(&ffi::ctx8Unpruned_cmr), amr: parse_root(&ffi::ctx8Unpruned_amr), - imr: parse_root(&ffi::ctx8Unpruned_imr), + ihr: parse_root(&ffi::ctx8Unpruned_ihr), prog: slice::from_raw_parts(ffi::ctx8Unpruned.as_ptr(), ffi::sizeof_ctx8Unpruned) .into(), witness: slice::from_raw_parts( @@ -390,7 +390,7 @@ mod test_code { &ffi::ctx8Pruned_witness, &ffi::ctx8Pruned_amr, &ffi::ctx8Pruned_cmr, - &ffi::ctx8Pruned_imr, + &ffi::ctx8Pruned_ihr, ffi::ctx8Pruned_cost, ); } @@ -410,7 +410,7 @@ mod test_code { SimplicityErr::AntiDoS, &ffi::ctx8Unpruned_amr, &ffi::ctx8Unpruned_cmr, - &ffi::ctx8Unpruned_imr, + &ffi::ctx8Unpruned_ihr, ffi::ctx8Unpruned_cost, ); } @@ -426,7 +426,7 @@ mod test_code { &ffi::schnorr0_witness, &ffi::schnorr0_amr, &ffi::schnorr0_cmr, - &ffi::schnorr0_imr, + &ffi::schnorr0_ihr, ffi::schnorr0_cost, ); } @@ -443,7 +443,7 @@ mod test_code { SimplicityErr::ExecJet, &ffi::schnorr6_amr, &ffi::schnorr6_cmr, - &ffi::schnorr6_imr, + &ffi::schnorr6_ihr, ffi::schnorr6_cost, ); } diff --git a/src/node/mod.rs b/src/node/mod.rs index ea8a459f..e0a8e645 100644 --- a/src/node/mod.rs +++ b/src/node/mod.rs @@ -728,7 +728,7 @@ mod tests { let prog = RedeemNode::::decode(prog, witness).unwrap(); assert_eq!(prog.cmr().to_byte_array(), test.cmr); assert_eq!(prog.amr().to_byte_array(), test.amr); - assert_eq!(prog.imr().to_byte_array(), test.imr); + assert_eq!(prog.imr().to_byte_array(), test.ihr); assert_eq!(prog.bounds().cost, Cost::from_milliweight(test.cost)) }