Skip to content

Commit f41af64

Browse files
Merge commit 'aef3f5a7e581883e18df6793eb6dbc8286aeb8dc' into simplicity
2 parents 956797f + aef3f5a commit f41af64

31 files changed

+430
-263
lines changed

src/simplicity/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
OBJS := bitstream.o cmr.o dag.o deserialize.o eval.o frame.o jets.o jets-secp256k1.o rsort.o sha256.o type.o typeInference.o primitive/elements/env.o primitive/elements/exec.o primitive/elements/ops.o primitive/elements/elementsJets.o primitive/elements/primitive.o
2-
TEST_OBJS := test.o ctx8Pruned.o ctx8Unpruned.o hashBlock.o regression4.o schnorr0.o schnorr6.o typeSkipTest.o primitive/elements/checkSigHashAllTx1.o
1+
OBJS := bitstream.o dag.o deserialize.o eval.o frame.o jets.o jets-secp256k1.o rsort.o sha256.o type.o typeInference.o elements/env.o elements/exec.o elements/ops.o elements/elementsJets.o elements/primitive.o elements/cmr.o elements/txEnv.o
2+
TEST_OBJS := test.o ctx8Pruned.o ctx8Unpruned.o hashBlock.o regression4.o schnorr0.o schnorr6.o typeSkipTest.o elements/checkSigHashAllTx1.o
33

44
# From https://fastcompression.blogspot.com/2019/01/compiler-warnings.html
55
CWARN := -Werror -Wall -Wextra -Wcast-qual -Wcast-align -Wstrict-aliasing -Wpointer-arith -Winit-self -Wshadow -Wswitch-enum -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wfloat-equal -Wundef -Wconversion
@@ -14,7 +14,7 @@ CFLAGS := $(CFLAGS) -I include
1414
jets-secp256k1.o: jets-secp256k1.c
1515
$(CC) -c $(CFLAGS) $(CWARN) -Wno-conversion $(CPPFLAGS) -o $@ $<
1616

17-
primitive/elements/elementsJets.o: primitive/elements/elementsJets.c
17+
elements/elementsJets.o: elements/elementsJets.c
1818
$(CC) -c $(CFLAGS) $(CWARN) -Wno-switch-enum -Wswitch $(CPPFLAGS) -o $@ $<
1919

2020
sha256.o: sha256.c

src/simplicity/deserialize.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <limits.h>
44
#include "limitations.h"
5-
#include "primitive.h"
65
#include "simplicity_alloc.h"
76
#include "simplicity_assert.h"
87

@@ -55,15 +54,15 @@ static simplicity_err getHash(sha256_midstate* result, bitstream* stream) {
5554
* i < 2^31 - 1
5655
* NULL != stream
5756
*/
58-
static simplicity_err decodeNode(dag_node* dag, uint_fast32_t i, bitstream* stream) {
57+
static simplicity_err decodeNode(dag_node* dag, simplicity_callback_decodeJet decodeJet, uint_fast32_t i, bitstream* stream) {
5958
int32_t bit = read1Bit(stream);
6059
if (bit < 0) return (simplicity_err)bit;
6160
dag[i] = (dag_node){0};
6261
if (bit) {
6362
bit = read1Bit(stream);
6463
if (bit < 0) return (simplicity_err)bit;
6564
if (bit) {
66-
return simplicity_decodeJet(&dag[i], stream);
65+
return decodeJet(&dag[i], stream);
6766
} else {
6867
/* Decode WORD. */
6968
int32_t depth = simplicity_decodeUptoMaxInt(stream);
@@ -153,9 +152,9 @@ static simplicity_err decodeNode(dag_node* dag, uint_fast32_t i, bitstream* stre
153152
* len < 2^31
154153
* NULL != stream
155154
*/
156-
static simplicity_err decodeDag(dag_node* dag, const uint_fast32_t len, combinator_counters* census, bitstream* stream) {
155+
static simplicity_err decodeDag(dag_node* dag, simplicity_callback_decodeJet decodeJet, const uint_fast32_t len, combinator_counters* census, bitstream* stream) {
157156
for (uint_fast32_t i = 0; i < len; ++i) {
158-
simplicity_err error = decodeNode(dag, i, stream);
157+
simplicity_err error = decodeNode(dag, decodeJet, i, stream);
159158
if (!IS_OK(error)) return error;
160159

161160
enumerator(census, dag[i].tag);
@@ -186,7 +185,7 @@ static simplicity_err decodeDag(dag_node* dag, const uint_fast32_t len, combinat
186185
* of the function is positive and when NULL != census;
187186
* NULL == *dag when the return value is negative.
188187
*/
189-
int_fast32_t simplicity_decodeMallocDag(dag_node** dag, combinator_counters* census, bitstream* stream) {
188+
int_fast32_t simplicity_decodeMallocDag(dag_node** dag, simplicity_callback_decodeJet decodeJet, combinator_counters* census, bitstream* stream) {
190189
*dag = NULL;
191190
int32_t dagLen = simplicity_decodeUptoMaxInt(stream);
192191
if (dagLen <= 0) return dagLen;
@@ -199,7 +198,7 @@ int_fast32_t simplicity_decodeMallocDag(dag_node** dag, combinator_counters* cen
199198
if (!*dag) return SIMPLICITY_ERR_MALLOC;
200199

201200
if (census) *census = (combinator_counters){0};
202-
simplicity_err error = decodeDag(*dag, (uint_fast32_t)dagLen, census, stream);
201+
simplicity_err error = decodeDag(*dag, decodeJet, (uint_fast32_t)dagLen, census, stream);
203202

204203
if (IS_OK(error)) {
205204
error = HIDDEN == (*dag)[dagLen - 1].tag

src/simplicity/deserialize.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
#include "bitstream.h"
77
#include "dag.h"
88

9+
/* Decode an application specific jet from 'stream' into 'node'.
10+
* All jets begin with a bit prefix of '1' which needs to have already been consumed from the 'stream'.
11+
* Returns 'SIMPLICITY_ERR_DATA_OUT_OF_RANGE' if the stream's prefix doesn't match any valid code for a jet.
12+
* Returns 'SIMPLICITY_ERR_BITSTRING_EOF' if not enough bits are available in the 'stream'.
13+
* In the above error cases, 'dag' may be modified.
14+
* Returns 'SIMPLICITY_NO_ERROR' if successful.
15+
*
16+
* Precondition: NULL != node
17+
* NULL != stream
18+
*/
19+
typedef simplicity_err (*simplicity_callback_decodeJet)(dag_node* node, bitstream* stream);
20+
921
/* Decode a length-prefixed Simplicity DAG from 'stream'.
1022
* Returns 'SIMPLICITY_ERR_DATA_OUT_OF_RANGE' the length prefix's value is too large.
1123
* Returns 'SIMPLICITY_ERR_DATA_OUT_OF_RANGE' if some node's child isn't a reference to one of the preceding nodes.
@@ -28,6 +40,6 @@
2840
* of the function is positive and when NULL != census;
2941
* NULL == *dag when the return value is negative.
3042
*/
31-
int_fast32_t simplicity_decodeMallocDag(dag_node** dag, combinator_counters* census, bitstream* stream);
43+
int_fast32_t simplicity_decodeMallocDag(dag_node** dag, simplicity_callback_decodeJet decodeJet, combinator_counters* census, bitstream* stream);
3244

3345
#endif

src/simplicity/elements-sources.mk

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
ELEMENTS_SIMPLICITY_INCLUDE_DIR_INT = %reldir%/include
66

77
ELEMENTS_SIMPLICITY_DIST_HEADERS_INT =
8-
ELEMENTS_SIMPLICITY_DIST_HEADERS_INT += %reldir%/include/simplicity/cmr.h
98
ELEMENTS_SIMPLICITY_DIST_HEADERS_INT += %reldir%/include/simplicity/errorCodes.h
9+
ELEMENTS_SIMPLICITY_DIST_HEADERS_INT += %reldir%/include/simplicity/elements/cmr.h
1010
ELEMENTS_SIMPLICITY_DIST_HEADERS_INT += %reldir%/include/simplicity/elements/env.h
1111
ELEMENTS_SIMPLICITY_DIST_HEADERS_INT += %reldir%/include/simplicity/elements/exec.h
1212

1313
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT =
1414
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/bitstream.c
15-
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/cmr.c
1615
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/dag.c
1716
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/deserialize.c
1817
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/eval.c
@@ -24,11 +23,13 @@ ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/sha256.c
2423
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/type.c
2524
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/typeInference.c
2625

27-
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/primitive/elements/env.c
28-
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/primitive/elements/exec.c
29-
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/primitive/elements/elementsJets.c
30-
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/primitive/elements/ops.c
31-
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/primitive/elements/primitive.c
26+
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/elements/cmr.c
27+
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/elements/env.c
28+
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/elements/exec.c
29+
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/elements/elementsJets.c
30+
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/elements/ops.c
31+
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/elements/primitive.c
32+
ELEMENTS_SIMPLICITY_LIB_SOURCES_INT += %reldir%/elements/txEnv.c
3233

3334
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT =
3435
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/bitstream.h
@@ -42,7 +43,6 @@ ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/frame.h
4243
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/jets.h
4344
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/limitations.h
4445
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/precomputed.h
45-
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive.h
4646
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/rsort.h
4747
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/sha256.h
4848
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/sha256_x86.inc
@@ -89,11 +89,12 @@ ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/secp256k1/secp256k1.h
8989
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/secp256k1/secp256k1_impl.h
9090
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/secp256k1/util.h
9191

92-
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive/elements/decodeElementsJets.inc
93-
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive/elements/elementsJets.h
94-
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive/elements/ops.h
95-
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive/elements/primitive.h
96-
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive/elements/primitiveEnumJet.inc
97-
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive/elements/primitiveEnumTy.inc
98-
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive/elements/primitiveInitTy.inc
99-
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/primitive/elements/primitiveJetNode.inc
92+
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/elements/decodeElementsJets.inc
93+
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/elements/elementsJets.h
94+
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/elements/ops.h
95+
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/elements/primitive.h
96+
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/elements/primitiveEnumJet.inc
97+
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/elements/primitiveEnumTy.inc
98+
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/elements/primitiveInitTy.inc
99+
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/elements/primitiveJetNode.inc
100+
ELEMENTS_SIMPLICITY_LIB_HEADERS_INT += %reldir%/elements/txEnv.h

src/simplicity/primitive/elements/checkSigHashAllTx1.h renamed to src/simplicity/elements/checkSigHashAllTx1.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#ifndef SIMPLICITY_PRIMITIVE_ELEMENTS_CHECKSIGHASHALLTX1_H
2-
#define SIMPLICITY_PRIMITIVE_ELEMENTS_CHECKSIGHASHALLTX1_H
1+
#ifndef SIMPLICITY_ELEMENTS_CHECKSIGHASHALLTX1_H
2+
#define SIMPLICITY_ELEMENTS_CHECKSIGHASHALLTX1_H
33

44
#include <stddef.h>
55
#include <stdint.h>
6-
#include "../../bounded.h"
6+
#include "../bounded.h"
77

88
/* A length-prefixed encoding of the following Simplicity program:
99
* Simplicity.Programs.CheckSig.Lib.checkSigVerify' Simplicity.Elements.Programs.SigHash.Lib.sigAllHash

src/simplicity/cmr.c renamed to src/simplicity/elements/cmr.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include <simplicity/cmr.h>
1+
#include <simplicity/elements/cmr.h>
22

3-
#include "deserialize.h"
4-
#include "limitations.h"
5-
#include "simplicity_alloc.h"
6-
#include "simplicity_assert.h"
3+
#include "../deserialize.h"
4+
#include "../limitations.h"
5+
#include "../simplicity_alloc.h"
6+
#include "../simplicity_assert.h"
7+
#include "primitive.h"
78

89
/* Deserialize a Simplicity 'program' and compute its CMR.
910
*
@@ -18,15 +19,15 @@
1819
* unsigned char cmr[32]
1920
* unsigned char program[program_len]
2021
*/
21-
bool simplicity_computeCmr( simplicity_err* error, unsigned char* cmr
22-
, const unsigned char* program, size_t program_len) {
22+
bool simplicity_elements_computeCmr( simplicity_err* error, unsigned char* cmr
23+
, const unsigned char* program, size_t program_len) {
2324
simplicity_assert(NULL != error);
2425
simplicity_assert(NULL != cmr);
2526
simplicity_assert(NULL != program || 0 == program_len);
2627

2728
bitstream stream = initializeBitstream(program, program_len);
2829
dag_node* dag = NULL;
29-
int_fast32_t dag_len = simplicity_decodeMallocDag(&dag, NULL, &stream);
30+
int_fast32_t dag_len = simplicity_decodeMallocDag(&dag, simplicity_elements_decodeJet, NULL, &stream);
3031
if (dag_len <= 0) {
3132
simplicity_assert(dag_len < 0);
3233
*error = (simplicity_err)dag_len;

src/simplicity/primitive/elements/elementsJets.c renamed to src/simplicity/elements/elementsJets.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "elementsJets.h"
22

33
#include "ops.h"
4-
#include "primitive.h"
5-
#include "../../taptweak.h"
6-
#include "../../simplicity_assert.h"
4+
#include "txEnv.h"
5+
#include "../taptweak.h"
6+
#include "../simplicity_assert.h"
77

88
/* Read a 256-bit hash value from the 'src' frame, advancing the cursor 256 cells.
99
*
@@ -145,19 +145,19 @@ static void issuanceTokenAmt(frameItem* dst, const assetIssuance* issuance) {
145145
}
146146
}
147147

148-
static uint_fast32_t lockHeight(const transaction* tx) {
148+
static uint_fast32_t lockHeight(const elementsTransaction* tx) {
149149
return !tx->isFinal && tx->lockTime < 500000000U ? tx->lockTime : 0;
150150
}
151151

152-
static uint_fast32_t lockTime(const transaction* tx) {
152+
static uint_fast32_t lockTime(const elementsTransaction* tx) {
153153
return !tx->isFinal && 500000000U <= tx->lockTime ? tx->lockTime : 0;
154154
}
155155

156-
static uint_fast16_t lockDistance(const transaction* tx) {
156+
static uint_fast16_t lockDistance(const elementsTransaction* tx) {
157157
return 2 <= tx->version ? tx->lockDistance : 0;
158158
}
159159

160-
static uint_fast16_t lockDuration(const transaction* tx) {
160+
static uint_fast16_t lockDuration(const elementsTransaction* tx) {
161161
return 2 <= tx->version ? tx->lockDuration : 0;
162162
}
163163

src/simplicity/primitive/elements/elementsJets.h renamed to src/simplicity/elements/elementsJets.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* This module defines primitives and jets that are specific to the Elements application for Simplicity.
22
*/
3-
#ifndef SIMPLICITY_PRIMITIVE_ELEMENTS_JETS_H
4-
#define SIMPLICITY_PRIMITIVE_ELEMENTS_JETS_H
3+
#ifndef SIMPLICITY_ELEMENTS_ELEMENTSJETS_H
4+
#define SIMPLICITY_ELEMENTS_ELEMENTSJETS_H
55

6-
#include "../../jets.h"
6+
#include "../jets.h"
77

88
/* Jets for the Elements application of Simplicity. */
99
bool simplicity_version(frameItem* dst, frameItem src, const txEnv* env);

0 commit comments

Comments
 (0)