MCPcopy Create free account
hub / github.com/ElementsProject/elements / simplicity_computeCommitmentMerkleRoot

Function simplicity_computeCommitmentMerkleRoot

src/simplicity/dag.c:158–193  ·  view source on GitHub ↗

Given a well-formed dag[i + 1], such that for all 'j', 0 <= 'j' < 'i', * 'dag[j].cmr' is the CMR of the subexpression denoted by the slice * * (dag_nodes[j + 1])dag, * * then we set the value of 'dag[i].cmr' to be the CMR of the subexpression denoted by 'dag'. * * Precondition: dag_node dag[i + 1] and 'dag' is well-formed. * dag[i].'tag' \notin {HIDDEN, JET, WORD} */

Source from the content-addressed store, hash-verified

156 * dag[i].'tag' \notin {HIDDEN, JET, WORD}
157 */
158void simplicity_computeCommitmentMerkleRoot(dag_node* dag, const uint_fast32_t i) {
159 uint32_t block[16] = {0};
160 size_t j = 8;
161
162 simplicity_assert(HIDDEN != dag[i].tag);
163 simplicity_assert(JET != dag[i].tag);
164 simplicity_assert(WORD != dag[i].tag);
165
166 dag[i].cmr = cmrIV(dag[i].tag);
167
168 /* Hash the child sub-expression's CMRs (if there are any children). */
169 switch (dag[i].tag) {
170 case COMP:
171 case ASSERTL:
172 case ASSERTR:
173 case CASE:
174 case PAIR:
175 memcpy(block + j, dag[dag[i].child[1]].cmr.s, sizeof(uint32_t[8]));
176 j = 0;
177 /*@fallthrough@*/
178 case DISCONNECT: /* Only the first child is used in the CMR. */
179 case INJL:
180 case INJR:
181 case TAKE:
182 case DROP:
183 memcpy(block + j, dag[dag[i].child[0]].cmr.s, sizeof(uint32_t[8]));
184 simplicity_sha256_compression(dag[i].cmr.s, block);
185 case IDEN:
186 case UNIT:
187 case WITNESS:
188 case HIDDEN:
189 case JET:
190 case WORD:
191 break;
192 }
193}
194
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]'.

Callers 1

decodeNodeFunction · 0.85

Calls 1

cmrIVFunction · 0.85

Tested by

no test coverage detected