Skip to content

Commit f154a83

Browse files
committed
Merge #297: simplicity-sys: separate out linker symbols in C library by version name
901127b simplicity-sys: add links= field to the Cargo.toml file (Andrew Poelstra) ee46600 simplicity-sys: add versions to jet prefixes (Andrew Poelstra) 985be76 simplicity-sys: add versions to jets_ffi code (Andrew Poelstra) d298887 simplicity-sys: prefix all simplicity_ symbols with the version (Andrew Poelstra) Pull request description: First several commits (all the ones that don't update libsimplicity) from #296. ACKs for top commit: canndrew: ACK 901127b Tree-SHA512: 8e4919605b216cebe75816c4d8451a4a9354ce8141cf2e2e884b01f1f6631893f19de5325b80482d63e3333855ffcf4c818b84cb1ebeec763377ca87f30c4599
2 parents b4758ad + 901127b commit f154a83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2519
-2450
lines changed

simplicity-sys/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ documentation = "https://docs.rs/simplicity-sys/"
88
description = "FFI bindings to libsimplicity"
99
edition = "2021"
1010
rust-version = "1.78.0"
11+
build = "build.rs"
12+
links = "rustsimplicity_0_4"
1113

1214
[build-dependencies]
1315
cc = "1.0.83"

simplicity-sys/depend/env.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@
33
#include "simplicity/elements/env.h"
44
#include "simplicity/primitive/elements/primitive.h"
55

6-
const size_t c_sizeof_rawBuffer = sizeof(rawBuffer);
7-
const size_t c_sizeof_rawOutput = sizeof(rawOutput);
8-
const size_t c_sizeof_rawInput = sizeof(rawInput);
9-
const size_t c_sizeof_rawTransaction = sizeof(rawTransaction);
10-
const size_t c_sizeof_rawTapEnv = sizeof(rawTapEnv);
11-
const size_t c_sizeof_txEnv = sizeof(txEnv);
6+
const size_t rustsimplicity_0_4_c_sizeof_rawBuffer = sizeof(rawBuffer);
7+
const size_t rustsimplicity_0_4_c_sizeof_rawOutput = sizeof(rawOutput);
8+
const size_t rustsimplicity_0_4_c_sizeof_rawInput = sizeof(rawInput);
9+
const size_t rustsimplicity_0_4_c_sizeof_rawTransaction = sizeof(rawTransaction);
10+
const size_t rustsimplicity_0_4_c_sizeof_rawTapEnv = sizeof(rawTapEnv);
11+
const size_t rustsimplicity_0_4_c_sizeof_txEnv = sizeof(txEnv);
1212

13-
const size_t c_alignof_rawBuffer = alignof(rawBuffer);
14-
const size_t c_alignof_rawOutput = alignof(rawOutput);
15-
const size_t c_alignof_rawInput = alignof(rawInput);
16-
const size_t c_alignof_rawTransaction = alignof(rawTransaction);
17-
const size_t c_alignof_rawTapEnv = alignof(rawTapEnv);
18-
const size_t c_alignof_txEnv = alignof(txEnv);
13+
const size_t rustsimplicity_0_4_c_alignof_rawBuffer = alignof(rawBuffer);
14+
const size_t rustsimplicity_0_4_c_alignof_rawOutput = alignof(rawOutput);
15+
const size_t rustsimplicity_0_4_c_alignof_rawInput = alignof(rawInput);
16+
const size_t rustsimplicity_0_4_c_alignof_rawTransaction = alignof(rawTransaction);
17+
const size_t rustsimplicity_0_4_c_alignof_rawTapEnv = alignof(rawTapEnv);
18+
const size_t rustsimplicity_0_4_c_alignof_txEnv = alignof(txEnv);
1919

20-
void c_set_rawBuffer(rawBuffer *result, const unsigned char *buf, unsigned int len)
20+
void rustsimplicity_0_4_c_set_rawBuffer(rawBuffer *result, const unsigned char *buf, unsigned int len)
2121
{
2222
*result = (rawBuffer){.buf = buf, .len = len};
2323
}
2424

25-
void c_set_rawOutput(rawOutput *result, const unsigned char *asset, const unsigned char *value, const unsigned char *nonce, const rawBuffer *scriptPubKey,
25+
void rustsimplicity_0_4_c_set_rawOutput(rawOutput *result, const unsigned char *asset, const unsigned char *value, const unsigned char *nonce, const rawBuffer *scriptPubKey,
2626
const rawBuffer *surjectionProof, const rawBuffer *rangeProof)
2727
{
2828
*result = (rawOutput){.asset = asset, .value = value, .nonce = nonce, .scriptPubKey = *scriptPubKey, .surjectionProof = *surjectionProof, .rangeProof = *rangeProof};
2929
}
3030

31-
void c_set_rawInput(rawInput *result, const rawBuffer *annex, const unsigned char *pegin, const rawBuffer *scriptSig,
31+
void rustsimplicity_0_4_c_set_rawInput(rawInput *result, const rawBuffer *annex, const unsigned char *pegin, const rawBuffer *scriptSig,
3232
const unsigned char *prevTxid, unsigned int prevIx,
3333
const unsigned char *asset, const unsigned char *value, const rawBuffer *scriptPubKey,
3434
unsigned int sequence,
@@ -38,7 +38,7 @@ void c_set_rawInput(rawInput *result, const rawBuffer *annex, const unsigned cha
3838
*result = (rawInput){.annex = annex, .scriptSig = *scriptSig, .prevTxid = prevTxid, .pegin = pegin, .issuance = {.blindingNonce = blindingNonce, .assetEntropy = assetEntropy, .amount = amount, .inflationKeys = inflationKeys, .amountRangePrf = *amountRangePrf, .inflationKeysRangePrf = *inflationKeysRangePrf}, .txo = {.asset = asset, .value = value, .scriptPubKey = *scriptPubKey}, .prevIx = prevIx, .sequence = sequence};
3939
}
4040

41-
void c_set_rawTransaction(rawTransaction *result, unsigned int version,
41+
void rustsimplicity_0_4_c_set_rawTransaction(rawTransaction *result, unsigned int version,
4242
const unsigned char *txid,
4343
const rawInput *input, unsigned int numInputs,
4444
const rawOutput *output, unsigned int numOutputs,
@@ -55,14 +55,14 @@ void c_set_rawTransaction(rawTransaction *result, unsigned int version,
5555
};
5656
}
5757

58-
void c_set_rawTapEnv(rawTapEnv *result, const unsigned char *controlBlock, unsigned char pathLen, const unsigned char *scriptCMR)
58+
void rustsimplicity_0_4_c_set_rawTapEnv(rawTapEnv *result, const unsigned char *controlBlock, unsigned char pathLen, const unsigned char *scriptCMR)
5959
{
6060
*result = (rawTapEnv){.controlBlock = controlBlock, .pathLen = pathLen, .scriptCMR = scriptCMR};
6161
}
6262

63-
void c_set_txEnv(txEnv *result, const transaction *tx, const tapEnv *taproot, const unsigned char *genesisHash, unsigned int ix)
63+
void rustsimplicity_0_4_c_set_txEnv(txEnv *result, const transaction *tx, const tapEnv *taproot, const unsigned char *genesisHash, unsigned int ix)
6464
{
6565
sha256_midstate genesis;
6666
sha256_toMidstate(genesis.s, genesisHash);
67-
*result = simplicity_build_txEnv(tx, taproot, &genesis, ix);
67+
*result = rustsimplicity_0_4_build_txEnv(tx, taproot, &genesis, ix);
6868
}

simplicity-sys/depend/simplicity/bitstream.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* Precondition: NULL != stream
1212
*/
13-
simplicity_err simplicity_closeBitstream(bitstream* stream) {
13+
simplicity_err rustsimplicity_0_4_closeBitstream(bitstream* stream) {
1414
if (1 < stream->len) return SIMPLICITY_ERR_BITSTREAM_TRAILING_BYTES; /* If there is more than one byte remaining. */
1515
if (1 == stream->len) {
1616
if (0 == stream->offset) return SIMPLICITY_ERR_BITSTREAM_TRAILING_BYTES; /* If there is one byte remaining */
@@ -30,8 +30,8 @@ simplicity_err simplicity_closeBitstream(bitstream* stream) {
3030
* Precondition: 0 <= n < 32
3131
* NULL != stream
3232
*/
33-
int32_t simplicity_readNBits(int n, bitstream* stream) {
34-
simplicity_assert(0 <= n && n < 32);
33+
int32_t rustsimplicity_0_4_readNBits(int n, bitstream* stream) {
34+
rustsimplicity_0_4_assert(0 <= n && n < 32);
3535

3636
uint32_t result = 0;
3737
while (CHAR_BIT <= stream->offset + n) {
@@ -109,7 +109,7 @@ static int32_t decodeUpto3Bits(int32_t* result, bitstream* stream) {
109109
} else {
110110
int32_t n = decodeUpto3(stream);
111111
if (0 <= n) {
112-
*result = simplicity_readNBits(n, stream);
112+
*result = rustsimplicity_0_4_readNBits(n, stream);
113113
if (*result < 0) return *result;
114114
}
115115
return n;
@@ -153,7 +153,7 @@ static int32_t decodeUpto15Bits(int32_t* result, bitstream* stream) {
153153
} else {
154154
int32_t n = decodeUpto15(stream);
155155
if (0 <= n) {
156-
*result = simplicity_readNBits(n, stream);
156+
*result = rustsimplicity_0_4_readNBits(n, stream);
157157
if (*result < 0) return *result;
158158
}
159159
return n;
@@ -184,7 +184,7 @@ static int32_t decodeUpto65535(bitstream* stream) {
184184
*
185185
* Precondition: NULL != stream
186186
*/
187-
int32_t simplicity_decodeUptoMaxInt(bitstream* stream) {
187+
int32_t rustsimplicity_0_4_decodeUptoMaxInt(bitstream* stream) {
188188
int32_t bit = read1Bit(stream);
189189
if (bit < 0) return bit;
190190
if (0 == bit) {
@@ -194,7 +194,7 @@ int32_t simplicity_decodeUptoMaxInt(bitstream* stream) {
194194
if (n < 0) return n;
195195
if (30 < n) return SIMPLICITY_ERR_DATA_OUT_OF_RANGE;
196196
{
197-
int32_t result = simplicity_readNBits(n, stream);
197+
int32_t result = rustsimplicity_0_4_readNBits(n, stream);
198198
if (result < 0) return result;
199199
return ((1 << n) | result);
200200
}
@@ -211,9 +211,9 @@ int32_t simplicity_decodeUptoMaxInt(bitstream* stream) {
211211
* n <= 2^31
212212
* NULL != stream
213213
*/
214-
simplicity_err simplicity_readBitstring(bitstring* result, size_t n, bitstream* stream) {
214+
simplicity_err rustsimplicity_0_4_readBitstring(bitstring* result, size_t n, bitstream* stream) {
215215
static_assert(0x80000000u + 2*(CHAR_BIT - 1) <= SIZE_MAX, "size_t needs to be at least 32-bits");
216-
simplicity_assert(n <= 0x80000000u);
216+
rustsimplicity_0_4_assert(n <= 0x80000000u);
217217
size_t total_offset = n + stream->offset;
218218
/* |= stream->len * CHAR_BIT < total_offset iff stream->len < (total_offset + (CHAR_BIT - 1)) / CHAR_BIT */
219219
if (stream->len < (total_offset + (CHAR_BIT - 1)) / CHAR_BIT) return SIMPLICITY_ERR_BITSTREAM_EOF;

simplicity-sys/depend/simplicity/bitstream.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static inline bitstream initializeBitstream(const unsigned char* arr, size_t len
3636
*
3737
* Precondition: NULL != stream
3838
*/
39-
simplicity_err simplicity_closeBitstream(bitstream* stream);
39+
simplicity_err rustsimplicity_0_4_closeBitstream(bitstream* stream);
4040

4141
/* Fetches up to 31 bits from 'stream' as the 'n' least significant bits of return value.
4242
* The 'n' bits are set from the MSB to the LSB.
@@ -45,15 +45,15 @@ simplicity_err simplicity_closeBitstream(bitstream* stream);
4545
* Precondition: 0 <= n < 32
4646
* NULL != stream
4747
*/
48-
int32_t simplicity_readNBits(int n, bitstream* stream);
48+
int32_t rustsimplicity_0_4_readNBits(int n, bitstream* stream);
4949

5050
/* Returns one bit from 'stream', 0 or 1.
5151
* Returns 'SIMPLICITY_ERR_BITSTREAM_EOF' if no bits are available.
5252
*
5353
* Precondition: NULL != stream
5454
*/
5555
static inline int32_t read1Bit(bitstream* stream) {
56-
return simplicity_readNBits(1, stream);
56+
return rustsimplicity_0_4_readNBits(1, stream);
5757
}
5858

5959
/* Decode an encoded number between 1 and 2^31 - 1 inclusive.
@@ -64,7 +64,7 @@ static inline int32_t read1Bit(bitstream* stream) {
6464
*
6565
* Precondition: NULL != stream
6666
*/
67-
int32_t simplicity_decodeUptoMaxInt(bitstream* stream);
67+
int32_t rustsimplicity_0_4_decodeUptoMaxInt(bitstream* stream);
6868

6969
/* Fills a 'bitstring' containing 'n' bits from 'stream'.
7070
* Returns 'SIMPLICITY_ERR_BITSTREAM_EOF' if not enough bits are available.
@@ -76,5 +76,5 @@ int32_t simplicity_decodeUptoMaxInt(bitstream* stream);
7676
* n <= 2^31
7777
* NULL != stream
7878
*/
79-
simplicity_err simplicity_readBitstring(bitstring* result, size_t n, bitstream* stream);
79+
simplicity_err rustsimplicity_0_4_readBitstring(bitstring* result, size_t n, bitstream* stream);
8080
#endif

simplicity-sys/depend/simplicity/bitstring.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ typedef struct bitstring {
3030
*/
3131
static inline bool getBit(const bitstring *s, size_t n) {
3232
size_t total_offset = s->offset + n;
33-
simplicity_assert(n < s->len);
33+
rustsimplicity_0_4_assert(n < s->len);
3434
return 1 & (s->arr[total_offset / CHAR_BIT] >> (CHAR_BIT - 1 - (total_offset % CHAR_BIT)));
3535
}
3636

@@ -40,8 +40,8 @@ static inline bool getBit(const bitstring *s, size_t n) {
4040
* n + 8 <= s->len;
4141
*/
4242
static inline uint_fast8_t getByte(const bitstring *s, size_t n) {
43-
simplicity_assert(8 <= s->len);
44-
simplicity_assert(n <= s->len - 8);
43+
rustsimplicity_0_4_assert(8 <= s->len);
44+
rustsimplicity_0_4_assert(n <= s->len - 8);
4545
size_t total_offset = s->offset + n;
4646
if (total_offset % CHAR_BIT <= CHAR_BIT - 8) {
4747
return (uint_fast8_t)(0xff & (s->arr[total_offset / CHAR_BIT] >> (CHAR_BIT - 8 - (total_offset % CHAR_BIT))));

simplicity-sys/depend/simplicity/cmr.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818
* unsigned char cmr[32]
1919
* unsigned char program[program_len]
2020
*/
21-
bool simplicity_computeCmr( simplicity_err* error, unsigned char* cmr
21+
bool rustsimplicity_0_4_computeCmr( simplicity_err* error, unsigned char* cmr
2222
, const unsigned char* program, size_t program_len) {
23-
simplicity_assert(NULL != error);
24-
simplicity_assert(NULL != cmr);
25-
simplicity_assert(NULL != program || 0 == program_len);
23+
rustsimplicity_0_4_assert(NULL != error);
24+
rustsimplicity_0_4_assert(NULL != cmr);
25+
rustsimplicity_0_4_assert(NULL != program || 0 == program_len);
2626

2727
bitstream stream = initializeBitstream(program, program_len);
2828
dag_node* dag = NULL;
29-
int_fast32_t dag_len = simplicity_decodeMallocDag(&dag, NULL, &stream);
29+
int_fast32_t dag_len = rustsimplicity_0_4_decodeMallocDag(&dag, NULL, &stream);
3030
if (dag_len <= 0) {
31-
simplicity_assert(dag_len < 0);
31+
rustsimplicity_0_4_assert(dag_len < 0);
3232
*error = (simplicity_err)dag_len;
3333
} else {
34-
simplicity_assert(NULL != dag);
35-
simplicity_assert((uint_fast32_t)dag_len <= DAG_LEN_MAX);
36-
*error = simplicity_closeBitstream(&stream);
34+
rustsimplicity_0_4_assert(NULL != dag);
35+
rustsimplicity_0_4_assert((uint_fast32_t)dag_len <= DAG_LEN_MAX);
36+
*error = rustsimplicity_0_4_closeBitstream(&stream);
3737
sha256_fromMidstate(cmr, dag[dag_len-1].cmr.s);
3838
}
3939

40-
simplicity_free(dag);
40+
rustsimplicity_0_4_free(dag);
4141
return IS_PERMANENT(*error);
4242
}

0 commit comments

Comments
 (0)