Skip to content

Commit 38c0019

Browse files
committed
simplicity-sys: update libsimplicity to bitcoin branch
Updates to BlockstreamResearch/simplicity#324 This PR does a couple things simultaneously: * Runs vendor-simplicity.sh and update-jets.sh * Updates the `Jet` trait to have associated transaction and environment types, and for the environment to be paramterized by the transaction type. * Changes the Core environment from () to CoreEnv::<Infallible> * Uncomments the commented-out symbols in simplicity-sys/src/c_jets/c_env/bitcoin.rs * Adds the "build bitcoin" lines to simplicity-sys/build.rs The update to the `Jet` trait is a bit noisy but ultimately mechanical: everywhere that we're generic over all J: Jet, we now also have to be generic over all T: Borrow<J::Transaction>, which leads to some extra line noise especially in unit tests where we have assert_* helper functions. The last three points are tiny diffs, thanks to the previous preparatory commits. The use of CoreEnv::<Infallible> as the core environment type is kinda fun. It means that it is impossible to execute any code which attempts to access the transaction in the environment. (No such code exists, since it would be nonsensical, but now we have some assurance that it won't exist by accident in the future.) Unfortunately this mixes mechanical and non-mechanical things in one commit. But the mechanical changes are exclusively in simplicity-sys/depend/ and src/jet/init/ and the non-mechanical changes are exclusively outside of those files, so it should be possible to review this.
1 parent aa36678 commit 38c0019

43 files changed

Lines changed: 11649 additions & 2598 deletions

Some content is hidden

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

simplicity-sys/build.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ fn main() {
116116
build.include("wasm-sysroot");
117117
}
118118

119-
let mut _bitcoin_build = build.clone();
119+
let mut bitcoin_build = build.clone();
120120
let mut elements_build = build;
121121

122122
// Bitcoin build
123-
// TODO
123+
bitcoin_build
124+
.files(bitcoin_files)
125+
.compile("BitcoinSimplicity");
124126

125127
// Elements build
126128
elements_build

simplicity-sys/depend/jets_wrapper.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* This file has been automatically generated. */
22

3+
#include "simplicity/bitcoin/bitcoinJets.h"
34
#include "simplicity/elements/elementsJets.h"
45
#include "simplicity/simplicity_assert.h"
56
#include "wrapper.h"
@@ -17,11 +18,15 @@ WRAP_(and_16)
1718
WRAP_(and_32)
1819
WRAP_(and_64)
1920
WRAP_(and_8)
21+
WRAP_(bitcoin_annex_hash)
2022
WRAP_(annex_hash)
2123
WRAP_(asset_amount_hash)
2224
WRAP_(bip_0340_verify)
25+
WRAP_(bitcoin_build_tapbranch)
2326
WRAP_(build_tapbranch)
27+
WRAP_(bitcoin_build_tapleaf_simplicity)
2428
WRAP_(build_tapleaf_simplicity)
29+
WRAP_(bitcoin_build_taptweak)
2530
WRAP_(build_taptweak)
2631
WRAP_(calculate_asset)
2732
WRAP_(calculate_confidential_token)
@@ -32,9 +37,13 @@ WRAP_(ch_16)
3237
WRAP_(ch_32)
3338
WRAP_(ch_64)
3439
WRAP_(ch_8)
40+
WRAP_(bitcoin_check_lock_distance)
3541
WRAP_(check_lock_distance)
42+
WRAP_(bitcoin_check_lock_duration)
3643
WRAP_(check_lock_duration)
44+
WRAP_(bitcoin_check_lock_height)
3745
WRAP_(check_lock_height)
46+
WRAP_(bitcoin_check_lock_time)
3847
WRAP_(check_lock_time)
3948
WRAP_(check_sig_verify)
4049
WRAP_(complement_1)
@@ -43,21 +52,28 @@ WRAP_(complement_32)
4352
WRAP_(complement_64)
4453
WRAP_(complement_8)
4554
WRAP_(current_amount)
55+
WRAP_(bitcoin_current_annex_hash)
4656
WRAP_(current_annex_hash)
4757
WRAP_(current_asset)
58+
WRAP_(bitcoin_current_index)
4859
WRAP_(current_index)
4960
WRAP_(current_issuance_asset_amount)
5061
WRAP_(current_issuance_asset_proof)
5162
WRAP_(current_issuance_token_amount)
5263
WRAP_(current_issuance_token_proof)
5364
WRAP_(current_new_issuance_contract)
5465
WRAP_(current_pegin)
66+
WRAP_(bitcoin_current_prev_outpoint)
5567
WRAP_(current_prev_outpoint)
5668
WRAP_(current_reissuance_blinding)
5769
WRAP_(current_reissuance_entropy)
70+
WRAP_(bitcoin_current_script_hash)
5871
WRAP_(current_script_hash)
72+
WRAP_(bitcoin_current_script_sig_hash)
5973
WRAP_(current_script_sig_hash)
74+
WRAP_(bitcoin_current_sequence)
6075
WRAP_(current_sequence)
76+
WRAP_(bitcoin_current_value)
6177
WRAP_(decompress)
6278
WRAP_(decrement_16)
6379
WRAP_(decrement_32)
@@ -92,6 +108,7 @@ WRAP_(fe_negate)
92108
WRAP_(fe_normalize)
93109
WRAP_(fe_square)
94110
WRAP_(fe_square_root)
111+
WRAP_(bitcoin_fee)
95112
WRAP_(full_add_16)
96113
WRAP_(full_add_32)
97114
WRAP_(full_add_64)
@@ -178,22 +195,39 @@ WRAP_(increment_64)
178195
WRAP_(increment_8)
179196
WRAP_(input_amount)
180197
WRAP_(input_amounts_hash)
198+
WRAP_(bitcoin_input_annex_hash)
181199
WRAP_(input_annex_hash)
200+
WRAP_(bitcoin_input_annexes_hash)
182201
WRAP_(input_annexes_hash)
183202
WRAP_(input_asset)
203+
WRAP_(bitcoin_input_hash)
184204
WRAP_(input_hash)
205+
WRAP_(bitcoin_input_outpoints_hash)
185206
WRAP_(input_outpoints_hash)
186207
WRAP_(input_pegin)
208+
WRAP_(bitcoin_input_prev_outpoint)
187209
WRAP_(input_prev_outpoint)
210+
WRAP_(bitcoin_input_script_hash)
188211
WRAP_(input_script_hash)
212+
WRAP_(bitcoin_input_script_sig_hash)
189213
WRAP_(input_script_sig_hash)
214+
WRAP_(bitcoin_input_script_sigs_hash)
190215
WRAP_(input_script_sigs_hash)
216+
WRAP_(bitcoin_input_scripts_hash)
191217
WRAP_(input_scripts_hash)
218+
WRAP_(bitcoin_input_sequence)
192219
WRAP_(input_sequence)
220+
WRAP_(bitcoin_input_sequences_hash)
193221
WRAP_(input_sequences_hash)
222+
WRAP_(bitcoin_input_utxo_hash)
194223
WRAP_(input_utxo_hash)
224+
WRAP_(bitcoin_input_utxos_hash)
195225
WRAP_(input_utxos_hash)
226+
WRAP_(bitcoin_input_value)
227+
WRAP_(bitcoin_input_values_hash)
228+
WRAP_(bitcoin_inputs_hash)
196229
WRAP_(inputs_hash)
230+
WRAP_(bitcoin_internal_key)
197231
WRAP_(internal_key)
198232
WRAP_(is_one_16)
199233
WRAP_(is_one_32)
@@ -284,6 +318,7 @@ WRAP_(leftmost_8_2)
284318
WRAP_(leftmost_8_4)
285319
WRAP_(linear_combination_1)
286320
WRAP_(linear_verify_1)
321+
WRAP_(bitcoin_lock_time)
287322
WRAP_(lock_time)
288323
WRAP_(low_1)
289324
WRAP_(low_16)
@@ -325,7 +360,9 @@ WRAP_(negate_64)
325360
WRAP_(negate_8)
326361
WRAP_(new_issuance_contract)
327362
WRAP_(nonce_hash)
363+
WRAP_(bitcoin_num_inputs)
328364
WRAP_(num_inputs)
365+
WRAP_(bitcoin_num_outputs)
329366
WRAP_(num_outputs)
330367
WRAP_(one_16)
331368
WRAP_(one_32)
@@ -336,21 +373,28 @@ WRAP_(or_16)
336373
WRAP_(or_32)
337374
WRAP_(or_64)
338375
WRAP_(or_8)
376+
WRAP_(bitcoin_outpoint_hash)
339377
WRAP_(outpoint_hash)
340378
WRAP_(output_amount)
341379
WRAP_(output_amounts_hash)
342380
WRAP_(output_asset)
381+
WRAP_(bitcoin_output_hash)
343382
WRAP_(output_hash)
344383
WRAP_(output_is_fee)
345384
WRAP_(output_nonce)
346385
WRAP_(output_nonces_hash)
347386
WRAP_(output_null_datum)
348387
WRAP_(output_range_proof)
349388
WRAP_(output_range_proofs_hash)
389+
WRAP_(bitcoin_output_script_hash)
350390
WRAP_(output_script_hash)
391+
WRAP_(bitcoin_output_scripts_hash)
351392
WRAP_(output_scripts_hash)
352393
WRAP_(output_surjection_proof)
353394
WRAP_(output_surjection_proofs_hash)
395+
WRAP_(bitcoin_output_value)
396+
WRAP_(bitcoin_output_values_hash)
397+
WRAP_(bitcoin_outputs_hash)
354398
WRAP_(outputs_hash)
355399
WRAP_(parse_lock)
356400
WRAP_(parse_sequence)
@@ -422,6 +466,7 @@ WRAP_(scalar_negate)
422466
WRAP_(scalar_normalize)
423467
WRAP_(scalar_square)
424468
WRAP_(scale)
469+
WRAP_(bitcoin_script_cmr)
425470
WRAP_(script_cmr)
426471
WRAP_(sha_256_block)
427472
WRAP_(sha_256_ctx_8_add_1)
@@ -438,6 +483,7 @@ WRAP_(sha_256_ctx_8_add_buffer_511)
438483
WRAP_(sha_256_ctx_8_finalize)
439484
WRAP_(sha_256_ctx_8_init)
440485
WRAP_(sha_256_iv)
486+
WRAP_(bitcoin_sig_all_hash)
441487
WRAP_(sig_all_hash)
442488
WRAP_(some_1)
443489
WRAP_(some_16)
@@ -449,21 +495,36 @@ WRAP_(subtract_32)
449495
WRAP_(subtract_64)
450496
WRAP_(subtract_8)
451497
WRAP_(swu)
498+
WRAP_(bitcoin_tap_env_hash)
452499
WRAP_(tap_env_hash)
453500
WRAP_(tapdata_init)
501+
WRAP_(bitcoin_tapleaf_hash)
454502
WRAP_(tapleaf_hash)
503+
WRAP_(bitcoin_tapleaf_version)
455504
WRAP_(tapleaf_version)
505+
WRAP_(bitcoin_tappath)
456506
WRAP_(tappath)
507+
WRAP_(bitcoin_tappath_hash)
457508
WRAP_(tappath_hash)
458509
WRAP_(total_fee)
510+
WRAP_(bitcoin_total_input_value)
511+
WRAP_(bitcoin_total_output_value)
512+
WRAP_(bitcoin_transaction_id)
459513
WRAP_(transaction_id)
514+
WRAP_(bitcoin_tx_hash)
460515
WRAP_(tx_hash)
516+
WRAP_(bitcoin_tx_is_final)
461517
WRAP_(tx_is_final)
518+
WRAP_(bitcoin_tx_lock_distance)
462519
WRAP_(tx_lock_distance)
520+
WRAP_(bitcoin_tx_lock_duration)
463521
WRAP_(tx_lock_duration)
522+
WRAP_(bitcoin_tx_lock_height)
464523
WRAP_(tx_lock_height)
524+
WRAP_(bitcoin_tx_lock_time)
465525
WRAP_(tx_lock_time)
466526
WRAP_(verify)
527+
WRAP_(bitcoin_version)
467528
WRAP_(version)
468529
WRAP_(xor_1)
469530
WRAP_(xor_16)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# This file has been automatically generated.
2-
b7bd4171e74451c8e1b6948674285f0d4274e368
2+
fba36f60e2b71fda41175688dc5332e5fb60054a
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(BitcoinSimplicity)
4+
5+
set(CMAKE_C_STANDARD 11)
6+
set(CMAKE_C_EXTENSIONS OFF)
7+
8+
add_library(BitcoinSimplicity STATIC
9+
bitstream.c
10+
dag.c
11+
deserialize.c
12+
eval.c
13+
frame.c
14+
jets-secp256k1.c
15+
jets.c
16+
rsort.c
17+
sha256.c
18+
type.c
19+
typeInference.c
20+
bitcoin/env.c
21+
bitcoin/exec.c
22+
bitcoin/bitcoinJets.c
23+
bitcoin/ops.c
24+
bitcoin/primitive.c
25+
bitcoin/txEnv.c
26+
)
27+
28+
option(PRODUCTION "Enable production build" ON)
29+
if (PRODUCTION)
30+
target_compile_definitions(BitcoinSimplicity PRIVATE "PRODUCTION")
31+
endif()
32+
33+
target_include_directories(BitcoinSimplicity PUBLIC
34+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
35+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
36+
)

simplicity-sys/depend/simplicity/Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
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
1+
CORE_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
2+
BITCOIN_OBJS := bitcoin/env.o bitcoin/exec.o bitcoin/ops.o bitcoin/bitcoinJets.o bitcoin/primitive.o bitcoin/cmr.o bitcoin/txEnv.o
3+
ELEMENTS_OBJS := elements/env.o elements/exec.o elements/ops.o elements/elementsJets.o elements/primitive.o elements/cmr.o elements/txEnv.o
24
TEST_OBJS := test.o ctx8Pruned.o ctx8Unpruned.o hashBlock.o regression4.o schnorr0.o schnorr6.o typeSkipTest.o elements/checkSigHashAllTx1.o
35

46
# From https://fastcompression.blogspot.com/2019/01/compiler-warnings.html
@@ -23,13 +25,16 @@ sha256.o: sha256.c
2325
%.o: %.c
2426
$(CC) -c $(CFLAGS) $(CWARN) $(CPPFLAGS) -o $@ $<
2527

26-
libElementsSimplicity.a: $(OBJS)
28+
libBitcoinSimplicity.a: $(CORE_OBJS) $(BITCOIN_OBJS)
29+
ar rcs $@ $^
30+
31+
libElementsSimplicity.a: $(CORE_OBJS) $(ELEMENTS_OBJS)
2732
ar rcs $@ $^
2833

2934
test: $(TEST_OBJS) libElementsSimplicity.a
3035
$(CC) $^ -o $@ $(LDFLAGS)
3136

32-
install: libElementsSimplicity.a
37+
install: libBitcoinSimplicity.a libElementsSimplicity.a
3338
mkdir -p $(out)/lib
3439
cp $^ $(out)/lib/
3540
cp -R include $(out)/include

0 commit comments

Comments
 (0)