@@ -77,16 +77,16 @@ static sha256_midstate amrIV(tag_t tag) {
77
77
SIMPLICITY_UNREACHABLE ;
78
78
}
79
79
80
- /* Given the IMR of a jet specification, return the CMR for a jet that implements that specification.
80
+ /* Given the identity hash of a jet specification, return the CMR for a jet that implements that specification.
81
81
*
82
- * Precondition: uint32_t imr [8]
82
+ * Precondition: uint32_t ih [8]
83
83
*/
84
- static sha256_midstate mkJetCMR (uint32_t * imr , uint_fast64_t weight ) {
84
+ static sha256_midstate mkJetCMR (uint32_t * ih , uint_fast64_t weight ) {
85
85
sha256_midstate result = jetIV ;
86
86
uint32_t block [16 ] = {0 };
87
87
block [6 ] = (uint32_t )(weight >> 32 );
88
88
block [7 ] = (uint32_t )weight ;
89
- memcpy (& block [8 ], imr , sizeof (uint32_t [8 ]));
89
+ memcpy (& block [8 ], ih , sizeof (uint32_t [8 ]));
90
90
simplicity_sha256_compression (result .s , block );
91
91
92
92
return result ;
@@ -100,7 +100,7 @@ sha256_midstate simplicity_computeWordCMR(const bitstring* value, size_t n) {
100
100
/* 'stack' is an array of 30 hashes consisting of 8 'uint32_t's each. */
101
101
uint32_t stack [8 * 30 ] = {0 };
102
102
uint32_t * stack_ptr = stack ;
103
- sha256_midstate imr = identityIV ;
103
+ sha256_midstate ih = identityIV ;
104
104
simplicity_assert (n < 32 );
105
105
simplicity_assert ((size_t )1 << n == value -> len );
106
106
/* 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) {
135
135
/* value->len is a power of 2.*/
136
136
simplicity_assert (stack_ptr == stack + 8 );
137
137
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 );
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 );
140
140
memcpy (& stack [0 ], word_type_root [0 ].s , sizeof (uint32_t [8 ]));
141
141
memcpy (& stack [8 ], word_type_root [n + 1 ].s , sizeof (uint32_t [8 ]));
142
- simplicity_sha256_compression (imr .s , stack );
142
+ simplicity_sha256_compression (ih .s , stack );
143
143
144
- /* Pass 3: Compute the jet's CMR from the specificion's IMR . */
145
- return mkJetCMR (imr .s , ((uint_fast64_t )1 << n ));
144
+ /* Pass 3: Compute the jet's CMR from the specificion's identity hash . */
145
+ return mkJetCMR (ih .s , ((uint_fast64_t )1 << n ));
146
146
}
147
147
148
148
/* 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
192
192
}
193
193
}
194
194
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.
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.
198
198
*
199
- * Precondition: sha256_midstate imr [len];
199
+ * Precondition: sha256_midstate ihr [len];
200
200
* dag_node dag[len] and 'dag' is well-typed with 'type_dag' and contains witnesses.
201
201
*/
202
- static void computeIdentityMerkleRoot (sha256_midstate * imr , const dag_node * dag , const type * type_dag , const uint_fast32_t len ) {
202
+ static void computeIdentityHashRoots (sha256_midstate * ihr , const dag_node * dag , const type * type_dag , const uint_fast32_t len ) {
203
203
/* Pass 1 */
204
204
for (size_t i = 0 ; i < len ; ++ i ) {
205
205
uint32_t block [16 ] = {0 };
206
206
size_t j = 8 ;
207
207
208
208
/* For jets, the first pass identity Merkle root is the same as their commitment Merkle root. */
209
- imr [i ] = HIDDEN == dag [i ].tag ? dag [i ].cmr
209
+ ihr [i ] = HIDDEN == dag [i ].tag ? dag [i ].cmr
210
210
: JET == dag [i ].tag ? dag [i ].cmr
211
211
: WORD == dag [i ].tag ? dag [i ].cmr
212
212
: imrIV (dag [i ].tag );
213
213
switch (dag [i ].tag ) {
214
214
case WITNESS :
215
215
simplicity_sha256_bitstring (block , & dag [i ].compactValue );
216
216
memcpy (block + 8 , type_dag [WITNESS_B (dag , type_dag , i )].typeMerkleRoot .s , sizeof (uint32_t [8 ]));
217
- simplicity_sha256_compression (imr [i ].s , block );
217
+ simplicity_sha256_compression (ihr [i ].s , block );
218
218
break ;
219
219
case COMP :
220
220
case ASSERTL :
221
221
case ASSERTR :
222
222
case CASE :
223
223
case PAIR :
224
224
case DISCONNECT :
225
- memcpy (block + j , imr [dag [i ].child [1 ]].s , sizeof (uint32_t [8 ]));
225
+ memcpy (block + j , ihr [dag [i ].child [1 ]].s , sizeof (uint32_t [8 ]));
226
226
j = 0 ;
227
227
/*@fallthrough@*/
228
228
case INJL :
229
229
case INJR :
230
230
case TAKE :
231
231
case DROP :
232
- memcpy (block + j , imr [dag [i ].child [0 ]].s , sizeof (uint32_t [8 ]));
233
- simplicity_sha256_compression (imr [i ].s , block );
232
+ memcpy (block + j , ihr [dag [i ].child [0 ]].s , sizeof (uint32_t [8 ]));
233
+ simplicity_sha256_compression (ihr [i ].s , block );
234
234
case IDEN :
235
235
case UNIT :
236
236
case HIDDEN :
@@ -245,16 +245,16 @@ static void computeIdentityMerkleRoot(sha256_midstate* imr, const dag_node* dag,
245
245
uint32_t block [16 ] = {0 };
246
246
247
247
if (HIDDEN == dag [i ].tag ) {
248
- memcpy (block + 8 , imr [i ].s , sizeof (uint32_t [8 ]));
249
- imr [i ] = hiddenIV ;
250
- simplicity_sha256_compression (imr [i ].s , block );
248
+ memcpy (block + 8 , ihr [i ].s , sizeof (uint32_t [8 ]));
249
+ ihr [i ] = hiddenIV ;
250
+ simplicity_sha256_compression (ihr [i ].s , block );
251
251
} else {
252
- memcpy (block + 8 , imr [i ].s , sizeof (uint32_t [8 ]));
253
- imr [i ] = identityIV ;
254
- simplicity_sha256_compression (imr [i ].s , block );
252
+ memcpy (block + 8 , ihr [i ].s , sizeof (uint32_t [8 ]));
253
+ ihr [i ] = identityIV ;
254
+ simplicity_sha256_compression (ihr [i ].s , block );
255
255
memcpy (block , type_dag [dag [i ].sourceType ].typeMerkleRoot .s , sizeof (uint32_t [8 ]));
256
256
memcpy (block + 8 , type_dag [dag [i ].targetType ].typeMerkleRoot .s , sizeof (uint32_t [8 ]));
257
- simplicity_sha256_compression (imr [i ].s , block );
257
+ simplicity_sha256_compression (ihr [i ].s , block );
258
258
}
259
259
}
260
260
}
@@ -559,30 +559,30 @@ simplicity_err simplicity_fillWitnessData(dag_node* dag, type* type_dag, const u
559
559
return SIMPLICITY_NO_ERROR ;
560
560
}
561
561
562
- /* Verifies that identity Merkle roots of every subexpression in a well-typed 'dag' with witnesses are all unique,
562
+ /* Verifies that identity hash of every subexpression in a well-typed 'dag' with witnesses are all unique,
563
563
* including that each hidden root hash for every 'HIDDEN' node is unique.
564
564
*
565
- * if 'imr ' is not NULL, then '*imr ' is set to the identity Merkle root of the 'dag'.
565
+ * if 'ihr ' is not NULL, then '*ihr ' is set to the identity hash of the root of the 'dag'.
566
566
*
567
567
* If malloc fails, returns 'SIMPLICITY_ERR_MALLOC'.
568
- * If all the identity Merkle roots (and hidden roots) are all unique, returns 'SIMPLICITY_NO_ERROR'.
568
+ * If all the identity hahes (and hidden roots) are all unique, returns 'SIMPLICITY_NO_ERROR'.
569
569
* Otherwise returns 'SIMPLICITY_ERR_UNSHARED_SUBEXPRESSION'.
570
570
*
571
571
* Precondition: dag_node dag[len] and 'dag' is well-typed with 'type_dag' and contains witnesses.
572
572
*/
573
- simplicity_err simplicity_verifyNoDuplicateIdentityRoots (sha256_midstate * imr , const dag_node * dag , const type * type_dag , const uint_fast32_t dag_len ) {
573
+ simplicity_err simplicity_verifyNoDuplicateIdentityHashes (sha256_midstate * ihr , const dag_node * dag , const type * type_dag , const uint_fast32_t dag_len ) {
574
574
simplicity_assert (0 < dag_len );
575
575
simplicity_assert (dag_len <= DAG_LEN_MAX );
576
- sha256_midstate * imr_buf = simplicity_malloc ((size_t )dag_len * sizeof (sha256_midstate ));
577
- if (!imr_buf ) return SIMPLICITY_ERR_MALLOC ;
576
+ sha256_midstate * ih_buf = simplicity_malloc ((size_t )dag_len * sizeof (sha256_midstate ));
577
+ if (!ih_buf ) return SIMPLICITY_ERR_MALLOC ;
578
578
579
- computeIdentityMerkleRoot ( imr_buf , dag , type_dag , dag_len );
579
+ computeIdentityHashRoots ( ih_buf , dag , type_dag , dag_len );
580
580
581
- if (imr ) * imr = imr_buf [dag_len - 1 ];
581
+ if (ihr ) * ihr = ih_buf [dag_len - 1 ];
582
582
583
- int result = simplicity_hasDuplicates (imr_buf , dag_len );
583
+ int result = simplicity_hasDuplicates (ih_buf , dag_len );
584
584
585
- simplicity_free (imr_buf );
585
+ simplicity_free (ih_buf );
586
586
587
587
switch (result ) {
588
588
case -1 : return SIMPLICITY_ERR_MALLOC ;
0 commit comments