6
6
#include < primitives/transaction.h>
7
7
extern " C" {
8
8
#include < simplicity/cmr.h>
9
- #define ReadBE64 simplicity_ReadBE64
10
- #define ReadBE32 simplicity_ReadBE32
11
- #define WriteBE64 simplicity_WriteBE64
12
- #include < simplicity/dag.h>
13
- #undef simplicity_ReadBE64
14
- #undef simplicity_ReadBE32
15
- #undef simplicity_WriteBE64
16
- #include < simplicity/deserialize.h> // simplicity_decodeMallocDag
17
- #include < simplicity/limitations.h> // DAG_LEN_MAX
18
- #include < simplicity/simplicity_alloc.h> // simplicity_free
19
- #include < simplicity/typeInference.h> // simplicity_mallocTypeInference
20
9
#include < simplicity/elements/env.h>
21
10
#include < simplicity/elements/exec.h>
22
11
}
@@ -40,53 +29,11 @@ std::vector<unsigned char> TAPROOT_CONTROL{};
40
29
std::vector<unsigned char > TAPROOT_ANNEX{99 , 0x50 };
41
30
// CMutableTransaction MTX_TEMPLATE{};
42
31
43
- // Copy of computeCmr used for AMR
32
+ // Defined in simplicity_compute_amr.c
33
+ extern " C" {
44
34
bool simplicity_computeAmr ( simplicity_err* error, unsigned char * amr
45
35
, const unsigned char * program, size_t program_len
46
- , const unsigned char * witness, size_t witness_len) {
47
- simplicity_assert (NULL != error);
48
- simplicity_assert (NULL != amr);
49
- simplicity_assert (NULL != program || 0 == program_len);
50
- simplicity_assert (NULL != witness || 0 == witness_len);
51
-
52
- bitstream stream = initializeBitstream (program, program_len);
53
- dag_node* dag = NULL ;
54
- combinator_counters census;
55
- int_fast32_t dag_len = simplicity_decodeMallocDag (&dag, &census, &stream);
56
- if (dag_len <= 0 ) {
57
- simplicity_assert (dag_len < 0 );
58
- *error = (simplicity_err)dag_len;
59
- } else {
60
- simplicity_assert (NULL != dag);
61
- simplicity_assert ((uint_fast32_t )dag_len <= DAG_LEN_MAX);
62
- *error = simplicity_closeBitstream (&stream);
63
-
64
- type* type_dag = NULL ;
65
- if (IS_OK (*error)) {
66
- *error = simplicity_mallocTypeInference (&type_dag, dag, (uint_fast32_t )dag_len, &census);
67
- }
68
- bitstream witness_stream;
69
- if (IS_OK (*error)) {
70
- witness_stream = initializeBitstream (witness, witness_len);
71
- *error = simplicity_fillWitnessData (dag, type_dag, (uint_fast32_t )dag_len, &witness_stream);
72
- }
73
- if (IS_OK (*error)) {
74
- *error = simplicity_closeBitstream (&witness_stream);
75
- if (SIMPLICITY_ERR_BITSTREAM_TRAILING_BYTES == *error) *error = SIMPLICITY_ERR_WITNESS_TRAILING_BYTES;
76
- if (SIMPLICITY_ERR_BITSTREAM_ILLEGAL_PADDING == *error) *error = SIMPLICITY_ERR_WITNESS_ILLEGAL_PADDING;
77
- }
78
- if (IS_OK (*error)) {
79
- analyses *analysis = (analyses*) simplicity_malloc ((size_t )dag_len * sizeof (analyses));
80
- simplicity_assert (NULL != analysis);
81
- simplicity_computeAnnotatedMerkleRoot (analysis, dag, type_dag, (uint_fast32_t )dag_len);
82
- sha256_fromMidstate (amr, analysis[dag_len-1 ].annotatedMerkleRoot .s );
83
- simplicity_free (analysis);
84
- }
85
- simplicity_free (type_dag);
86
- }
87
-
88
- simplicity_free (dag);
89
- return IS_PERMANENT (*error);
36
+ , const unsigned char * witness, size_t witness_len);
90
37
}
91
38
92
39
void initialize_simplicity ()
@@ -163,7 +110,7 @@ FUZZ_TARGET_INIT(simplicity, initialize_simplicity)
163
110
164
111
// printf("OK going\n");
165
112
166
- // 2. Parse the transaction (the program and witness are just raw bytes)
113
+ // 2. Parse the transaction (the program and witness are just raw bytes)
167
114
CMutableTransaction mtx;
168
115
CDataStream txds{Span{tx_data, tx_data_len}, SER_NETWORK, INIT_PROTO_VERSION};
169
116
try {
0 commit comments