Skip to content

Commit 3897d13

Browse files
committed
Revert "Merge pull request ElementsProject#1390 from ElementsProject/simplicity"
This reverts commit 368010a, reversing changes made to e9a9144.
1 parent c8b08e6 commit 3897d13

40 files changed

+1238
-1364
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ LCOV_FILTER_PATTERN = \
195195
-p "src/crypto/ctaes" \
196196
-p "src/minisketch" \
197197
-p "src/secp256k1" \
198+
-p "src/simplicity/secp256k1" \
198199
-p "depends"
199200

200201
DIR_FUZZ_SEED_CORPUS ?= qa-assets/fuzz_seed_corpus

src/Makefile.elementssimplicity.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ include simplicity/elements-sources.mk
33
LIBELEMENTSSIMPLICITY = libelementssimplicity.la
44
noinst_LTLIBRARIES += $(LIBELEMENTSSIMPLICITY)
55
libelementssimplicity_la_SOURCES = $(ELEMENTS_SIMPLICITY_LIB_SOURCES_INT) $(ELEMENTS_SIMPLICITY_DIST_HEADERS_INT) $(ELEMENTS_SIMPLICITY_LIB_HEADERS_INT)
6-
libelementssimplicity_la_CPPFLAGS = $(AM_CPPFLAGS) $(SHANI_CXXFLAGS) $(SANITIZER_CXXFLAGS) -I$(srcdir)/$(ELEMENTS_SIMPLICITY_INCLUDE_DIR_INT)
6+
libelementssimplicity_la_CPPFLAGS = $(AM_CPPFLAGS) $(SHANI_CXXFLAGS) -I$(srcdir)/$(ELEMENTS_SIMPLICITY_INCLUDE_DIR_INT)

src/script/interpreter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,8 +2660,7 @@ void PrecomputedTransactionData::Init(const T& txTo, std::vector<CTxOut>&& spent
26602660
}
26612661

26622662
rawTransaction simplicityRawTx;
2663-
uint256 rawHash = txTo.GetHash();
2664-
simplicityRawTx.txid = rawHash.begin();
2663+
simplicityRawTx.txid = txTo.GetHash().begin();
26652664
simplicityRawTx.input = simplicityRawInput.data();
26662665
simplicityRawTx.numInputs = simplicityRawInput.size();
26672666
simplicityRawTx.output = simplicityRawOutput.data();
@@ -3124,7 +3123,7 @@ bool GenericTransactionSignatureChecker<T>::CheckSimplicity(const valtype& progr
31243123
if (!simplicity_elements_execSimplicity(&error, 0, txdata->m_simplicity_tx_data, nIn, simplicityTapEnv, txdata->m_hash_genesis_block.data(), budget, 0, program.data(), program.size(), witness.data(), witness.size())) {
31253124
assert(!"simplicity_elements_execSimplicity internal error");
31263125
}
3127-
simplicity_elements_freeTapEnv(simplicityTapEnv);
3126+
free(simplicityTapEnv);
31283127
switch (error) {
31293128
case SIMPLICITY_NO_ERROR: return set_success(serror);
31303129
case SIMPLICITY_ERR_MALLOC:
@@ -3134,7 +3133,7 @@ bool GenericTransactionSignatureChecker<T>::CheckSimplicity(const valtype& progr
31343133
case SIMPLICITY_ERR_DATA_OUT_OF_RANGE: return set_error(serror, SCRIPT_ERR_SIMPLICITY_DATA_OUT_OF_RANGE);
31353134
case SIMPLICITY_ERR_DATA_OUT_OF_ORDER: return set_error(serror, SCRIPT_ERR_SIMPLICITY_DATA_OUT_OF_ORDER);
31363135
case SIMPLICITY_ERR_FAIL_CODE: return set_error(serror, SCRIPT_ERR_SIMPLICITY_FAIL_CODE);
3137-
case SIMPLICITY_ERR_RESERVED_CODE: return set_error(serror, SCRIPT_ERR_SIMPLICITY_RESERVED_CODE);
3136+
case SIMPLICITY_ERR_STOP_CODE: return set_error(serror, SCRIPT_ERR_SIMPLICITY_STOP_CODE);
31383137
case SIMPLICITY_ERR_HIDDEN: return set_error(serror, SCRIPT_ERR_SIMPLICITY_HIDDEN);
31393138
case SIMPLICITY_ERR_BITSTREAM_EOF: return set_error(serror, SCRIPT_ERR_SIMPLICITY_BITSTREAM_EOF);
31403139
case SIMPLICITY_ERR_BITSTREAM_TRAILING_BYTES: return set_error(serror, SCRIPT_ERR_SIMPLICITY_BITSTREAM_TRAILING_BYTES);

src/script/interpreter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ struct PrecomputedTransactionData
222222
template <class T>
223223
explicit PrecomputedTransactionData(const T& tx);
224224
~PrecomputedTransactionData() {
225-
simplicity_elements_freeTransaction(m_simplicity_tx_data);
225+
free(m_simplicity_tx_data);
226226
}
227227
};
228228

src/script/script_error.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ std::string ScriptErrorString(const ScriptError serror)
140140
return SIMPLICITY_ERR_MSG(SIMPLICITY_ERR_DATA_OUT_OF_ORDER);
141141
case SCRIPT_ERR_SIMPLICITY_FAIL_CODE:
142142
return SIMPLICITY_ERR_MSG(SIMPLICITY_ERR_FAIL_CODE);
143-
case SCRIPT_ERR_SIMPLICITY_RESERVED_CODE:
144-
return SIMPLICITY_ERR_MSG(SIMPLICITY_ERR_RESERVED_CODE);
143+
case SCRIPT_ERR_SIMPLICITY_STOP_CODE:
144+
return SIMPLICITY_ERR_MSG(SIMPLICITY_ERR_STOP_CODE);
145145
case SCRIPT_ERR_SIMPLICITY_HIDDEN:
146146
return SIMPLICITY_ERR_MSG(SIMPLICITY_ERR_HIDDEN);
147147
case SCRIPT_ERR_SIMPLICITY_BITSTREAM_EOF:

src/script/script_error.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ typedef enum ScriptError_t
102102
SCRIPT_ERR_SIMPLICITY_DATA_OUT_OF_RANGE,
103103
SCRIPT_ERR_SIMPLICITY_DATA_OUT_OF_ORDER,
104104
SCRIPT_ERR_SIMPLICITY_FAIL_CODE,
105-
SCRIPT_ERR_SIMPLICITY_RESERVED_CODE,
105+
SCRIPT_ERR_SIMPLICITY_STOP_CODE,
106106
SCRIPT_ERR_SIMPLICITY_HIDDEN,
107107
SCRIPT_ERR_SIMPLICITY_BITSTREAM_EOF,
108108
SCRIPT_ERR_SIMPLICITY_BITSTREAM_TRAILING_BYTES,

src/simplicity/ctx8Pruned.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ const uint32_t ctx8Pruned_cmr[] = {
270270
0x7f11746fu, 0xb68fdaedu, 0x3cadda80u, 0xc7cd0245u, 0xa341b927u, 0xe98e60f8u, 0x745dc441u, 0xe11ce1a3u
271271
};
272272

273-
/* The identity hash of the root of the above ctx8Pruned Simplicity expression. */
274-
const uint32_t ctx8Pruned_ihr[] = {
273+
/* The identity Merkle root of the above ctx8Pruned Simplicity expression. */
274+
const uint32_t ctx8Pruned_imr[] = {
275275
0x8e8742acu, 0x27f42d29u, 0xd87f5229u, 0x02bc0ae2u, 0xbcfc1298u, 0x1641a2ddu, 0x77091830u, 0xb79bf12du
276276
};
277277

src/simplicity/ctx8Pruned.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ extern const size_t sizeof_ctx8Pruned_witness;
1818
/* The commitment Merkle root of the above ctx8Pruned Simplicity expression. */
1919
extern const uint32_t ctx8Pruned_cmr[];
2020

21-
/* The identity hash of the root of the above ctx8Pruned Simplicity expression. */
22-
extern const uint32_t ctx8Pruned_ihr[];
21+
/* The identity Merkle root of the above ctx8Pruned Simplicity expression. */
22+
extern const uint32_t ctx8Pruned_imr[];
2323

2424
/* The annotated Merkle root of the above ctx8Pruned Simplicity expression. */
2525
extern const uint32_t ctx8Pruned_amr[];

src/simplicity/ctx8Unpruned.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ const uint32_t ctx8Unpruned_cmr[] = {
260260
0x7f11746fu, 0xb68fdaedu, 0x3cadda80u, 0xc7cd0245u, 0xa341b927u, 0xe98e60f8u, 0x745dc441u, 0xe11ce1a3u
261261
};
262262

263-
/* The identity hash of the root of the above ctx8Unpruned Simplicity expression. */
264-
const uint32_t ctx8Unpruned_ihr[] = {
263+
/* The identity Merkle root of the above ctx8Unpruned Simplicity expression. */
264+
const uint32_t ctx8Unpruned_imr[] = {
265265
0x8e8742acu, 0x27f42d29u, 0xd87f5229u, 0x02bc0ae2u, 0xbcfc1298u, 0x1641a2ddu, 0x77091830u, 0xb79bf12du
266266
};
267267

src/simplicity/ctx8Unpruned.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ extern const size_t sizeof_ctx8Unpruned_witness;
1818
/* The commitment Merkle root of the above ctx8Unpruned Simplicity expression. */
1919
extern const uint32_t ctx8Unpruned_cmr[];
2020

21-
/* The identity hash of the root of the above ctx8Unpruned Simplicity expression. */
22-
extern const uint32_t ctx8Unpruned_ihr[];
21+
/* The identity Merkle root of the above ctx8Unpruned Simplicity expression. */
22+
extern const uint32_t ctx8Unpruned_imr[];
2323

2424
/* The annotated Merkle root of the above ctx8Unpruned Simplicity expression. */
2525
extern const uint32_t ctx8Unpruned_amr[];

src/simplicity/dag.c

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ static sha256_midstate amrIV(tag_t tag) {
7777
SIMPLICITY_UNREACHABLE;
7878
}
7979

80-
/* Given the identity hash of a jet specification, return the CMR for a jet that implements that specification.
80+
/* Given the IMR of a jet specification, return the CMR for a jet that implements that specification.
8181
*
82-
* Precondition: uint32_t ih[8]
82+
* Precondition: uint32_t imr[8]
8383
*/
84-
static sha256_midstate mkJetCMR(uint32_t *ih, uint_fast64_t weight) {
84+
static sha256_midstate mkJetCMR(uint32_t *imr, uint_fast64_t weight) {
8585
sha256_midstate result = jetIV;
8686
uint32_t block[16] = {0};
8787
block[6] = (uint32_t)(weight >> 32);
8888
block[7] = (uint32_t)weight;
89-
memcpy(&block[8], ih, sizeof(uint32_t[8]));
89+
memcpy(&block[8], imr, sizeof(uint32_t[8]));
9090
simplicity_sha256_compression(result.s, block);
9191

9292
return result;
@@ -100,7 +100,7 @@ sha256_midstate simplicity_computeWordCMR(const bitstring* value, size_t n) {
100100
/* 'stack' is an array of 30 hashes consisting of 8 'uint32_t's each. */
101101
uint32_t stack[8*30] = {0};
102102
uint32_t *stack_ptr = stack;
103-
sha256_midstate ih = identityIV;
103+
sha256_midstate imr = identityIV;
104104
simplicity_assert(n < 32);
105105
simplicity_assert((size_t)1 << n == value->len);
106106
/* 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) {
135135
/* value->len is a power of 2.*/
136136
simplicity_assert(stack_ptr == stack + 8);
137137

138-
/* Pass 2: Compute the identity hash for the expression by adding the type roots of ONE and TWO^(2^n) to the CMR. */
139-
simplicity_sha256_compression(ih.s, stack);
138+
/* Pass 2: Compute the IMR for the expression by adding the type roots of ONE and TWO^(2^n) to the CMR. */
139+
simplicity_sha256_compression(imr.s, stack);
140140
memcpy(&stack[0], word_type_root[0].s, sizeof(uint32_t[8]));
141141
memcpy(&stack[8], word_type_root[n+1].s, sizeof(uint32_t[8]));
142-
simplicity_sha256_compression(ih.s, stack);
142+
simplicity_sha256_compression(imr.s, stack);
143143

144-
/* Pass 3: Compute the jet's CMR from the specificion's identity hash. */
145-
return mkJetCMR(ih.s, ((uint_fast64_t)1 << n));
144+
/* Pass 3: Compute the jet's CMR from the specificion's IMR. */
145+
return mkJetCMR(imr.s, ((uint_fast64_t)1 << n));
146146
}
147147

148148
/* Given a well-formed dag[i + 1], such that for all 'j', 0 <= 'j' < 'i',
@@ -192,45 +192,45 @@ void simplicity_computeCommitmentMerkleRoot(dag_node* dag, const uint_fast32_t i
192192
}
193193
}
194194

195-
/* Computes the identity hash roots of every subexpression in a well-typed 'dag' with witnesses.
196-
* 'ihr[i]' is set to the identity hash of the root of the subexpression 'dag[i]'.
197-
* When 'HIDDEN == dag[i].tag', then 'ihr[i]' is instead set to a hidden root hash for that hidden node.
195+
/* Computes the identity Merkle roots of every subexpression in a well-typed 'dag' with witnesses.
196+
* 'imr[i]' is set to the identity Merkle root of the subexpression 'dag[i]'.
197+
* When 'HIDDEN == dag[i].tag', then 'imr[i]' is instead set to a hidden root hash for that hidden node.
198198
*
199-
* Precondition: sha256_midstate ihr[len];
199+
* Precondition: sha256_midstate imr[len];
200200
* dag_node dag[len] and 'dag' is well-typed with 'type_dag' and contains witnesses.
201201
*/
202-
static void computeIdentityHashRoots(sha256_midstate* ihr, const dag_node* dag, const type* type_dag, const uint_fast32_t len) {
202+
static void computeIdentityMerkleRoot(sha256_midstate* imr, const dag_node* dag, const type* type_dag, const uint_fast32_t len) {
203203
/* Pass 1 */
204204
for (size_t i = 0; i < len; ++i) {
205205
uint32_t block[16] = {0};
206206
size_t j = 8;
207207

208208
/* For jets, the first pass identity Merkle root is the same as their commitment Merkle root. */
209-
ihr[i] = HIDDEN == dag[i].tag ? dag[i].cmr
209+
imr[i] = HIDDEN == dag[i].tag ? dag[i].cmr
210210
: JET == dag[i].tag ? dag[i].cmr
211211
: WORD == dag[i].tag ? dag[i].cmr
212212
: imrIV(dag[i].tag);
213213
switch (dag[i].tag) {
214214
case WITNESS:
215215
simplicity_sha256_bitstring(block, &dag[i].compactValue);
216216
memcpy(block + 8, type_dag[WITNESS_B(dag, type_dag, i)].typeMerkleRoot.s, sizeof(uint32_t[8]));
217-
simplicity_sha256_compression(ihr[i].s, block);
217+
simplicity_sha256_compression(imr[i].s, block);
218218
break;
219219
case COMP:
220220
case ASSERTL:
221221
case ASSERTR:
222222
case CASE:
223223
case PAIR:
224224
case DISCONNECT:
225-
memcpy(block + j, ihr[dag[i].child[1]].s, sizeof(uint32_t[8]));
225+
memcpy(block + j, imr[dag[i].child[1]].s, sizeof(uint32_t[8]));
226226
j = 0;
227227
/*@fallthrough@*/
228228
case INJL:
229229
case INJR:
230230
case TAKE:
231231
case DROP:
232-
memcpy(block + j, ihr[dag[i].child[0]].s, sizeof(uint32_t[8]));
233-
simplicity_sha256_compression(ihr[i].s, block);
232+
memcpy(block + j, imr[dag[i].child[0]].s, sizeof(uint32_t[8]));
233+
simplicity_sha256_compression(imr[i].s, block);
234234
case IDEN:
235235
case UNIT:
236236
case HIDDEN:
@@ -245,16 +245,16 @@ static void computeIdentityHashRoots(sha256_midstate* ihr, const dag_node* dag,
245245
uint32_t block[16] = {0};
246246

247247
if (HIDDEN == dag[i].tag) {
248-
memcpy(block + 8, ihr[i].s, sizeof(uint32_t[8]));
249-
ihr[i] = hiddenIV;
250-
simplicity_sha256_compression(ihr[i].s, block);
248+
memcpy(block + 8, imr[i].s, sizeof(uint32_t[8]));
249+
imr[i] = hiddenIV;
250+
simplicity_sha256_compression(imr[i].s, block);
251251
} else {
252-
memcpy(block + 8, ihr[i].s, sizeof(uint32_t[8]));
253-
ihr[i] = identityIV;
254-
simplicity_sha256_compression(ihr[i].s, block);
252+
memcpy(block + 8, imr[i].s, sizeof(uint32_t[8]));
253+
imr[i] = identityIV;
254+
simplicity_sha256_compression(imr[i].s, block);
255255
memcpy(block, type_dag[dag[i].sourceType].typeMerkleRoot.s, sizeof(uint32_t[8]));
256256
memcpy(block + 8, type_dag[dag[i].targetType].typeMerkleRoot.s, sizeof(uint32_t[8]));
257-
simplicity_sha256_compression(ihr[i].s, block);
257+
simplicity_sha256_compression(imr[i].s, block);
258258
}
259259
}
260260
}
@@ -559,30 +559,30 @@ simplicity_err simplicity_fillWitnessData(dag_node* dag, type* type_dag, const u
559559
return SIMPLICITY_NO_ERROR;
560560
}
561561

562-
/* Verifies that identity hash of every subexpression in a well-typed 'dag' with witnesses are all unique,
562+
/* Verifies that identity Merkle roots of every subexpression in a well-typed 'dag' with witnesses are all unique,
563563
* including that each hidden root hash for every 'HIDDEN' node is unique.
564564
*
565-
* if 'ihr' is not NULL, then '*ihr' is set to the identity hash of the root of the 'dag'.
565+
* if 'imr' is not NULL, then '*imr' is set to the identity Merkle root of the 'dag'.
566566
*
567567
* If malloc fails, returns 'SIMPLICITY_ERR_MALLOC'.
568-
* If all the identity hahes (and hidden roots) are all unique, returns 'SIMPLICITY_NO_ERROR'.
568+
* If all the identity Merkle roots (and hidden roots) are all unique, returns 'SIMPLICITY_NO_ERROR'.
569569
* Otherwise returns 'SIMPLICITY_ERR_UNSHARED_SUBEXPRESSION'.
570570
*
571571
* Precondition: dag_node dag[len] and 'dag' is well-typed with 'type_dag' and contains witnesses.
572572
*/
573-
simplicity_err simplicity_verifyNoDuplicateIdentityHashes(sha256_midstate* ihr, const dag_node* dag, const type* type_dag, const uint_fast32_t dag_len) {
573+
simplicity_err simplicity_verifyNoDuplicateIdentityRoots(sha256_midstate* imr, const dag_node* dag, const type* type_dag, const uint_fast32_t dag_len) {
574574
simplicity_assert(0 < dag_len);
575575
simplicity_assert(dag_len <= DAG_LEN_MAX);
576-
sha256_midstate* ih_buf = simplicity_malloc((size_t)dag_len * sizeof(sha256_midstate));
577-
if (!ih_buf) return SIMPLICITY_ERR_MALLOC;
576+
sha256_midstate* imr_buf = simplicity_malloc((size_t)dag_len * sizeof(sha256_midstate));
577+
if (!imr_buf) return SIMPLICITY_ERR_MALLOC;
578578

579-
computeIdentityHashRoots(ih_buf, dag, type_dag, dag_len);
579+
computeIdentityMerkleRoot(imr_buf, dag, type_dag, dag_len);
580580

581-
if (ihr) *ihr = ih_buf[dag_len-1];
581+
if (imr) *imr = imr_buf[dag_len-1];
582582

583-
int result = simplicity_hasDuplicates(ih_buf, dag_len);
583+
int result = simplicity_hasDuplicates(imr_buf, dag_len);
584584

585-
simplicity_free(ih_buf);
585+
simplicity_free(imr_buf);
586586

587587
switch (result) {
588588
case -1: return SIMPLICITY_ERR_MALLOC;

src/simplicity/dag.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,17 +377,17 @@ simplicity_err simplicity_verifyCanonicalOrder(dag_node* dag, const uint_fast32_
377377
*/
378378
simplicity_err simplicity_fillWitnessData(dag_node* dag, type* type_dag, const uint_fast32_t len, bitstream *witness);
379379

380-
/* Verifies that identity hash of every subexpression in a well-typed 'dag' with witnesses are all unique,
380+
/* Verifies that identity Merkle roots of every subexpression in a well-typed 'dag' with witnesses are all unique,
381381
* including that each hidden root hash for every 'HIDDEN' node is unique.
382382
*
383-
* if 'ihr' is not NULL, then '*ihr' is set to the identity hash of the root of the 'dag'.
383+
* if 'imr' is not NULL, then '*imr' is set to the identity Merkle root of the 'dag'.
384384
*
385385
* If malloc fails, returns 'SIMPLICITY_ERR_MALLOC'.
386-
* If all the identity hahes (and hidden roots) are all unique, returns 'SIMPLICITY_NO_ERROR'.
386+
* If all the identity Merkle roots (and hidden roots) are all unique, returns 'SIMPLICITY_NO_ERROR'.
387387
* Otherwise returns 'SIMPLICITY_ERR_UNSHARED_SUBEXPRESSION'.
388388
*
389389
* Precondition: dag_node dag[len] and 'dag' is well-typed with 'type_dag' and contains witnesses.
390390
*/
391-
simplicity_err simplicity_verifyNoDuplicateIdentityHashes(sha256_midstate* ihr, const dag_node* dag, const type* type_dag, const uint_fast32_t dag_len);
391+
simplicity_err simplicity_verifyNoDuplicateIdentityRoots(sha256_midstate* imr, const dag_node* dag, const type* type_dag, const uint_fast32_t dag_len);
392392

393393
#endif

0 commit comments

Comments
 (0)