Skip to content
19 changes: 8 additions & 11 deletions simplicity-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ const TEST_UTILS_ONLY: &[&str] = &[
/// Sources we never compile, and why.
const EXCLUDED: &[(&str, &str)] = &[
("elements/cmr.c", "Rust computes CMRs itself"),
// #385: uncomment when vendoring a libsimplicity that has the Bitcoin application (#324).
// Otherwise these get compiled into the libraries, and MSRV links fail on their undefined
// decoder symbols.
// ("cmr.c", "Rust computes CMRs itself"),
// ("bitcoin/cmr.c", "Rust computes CMRs itself"),
("cmr.c", "Rust computes CMRs itself"),
("bitcoin/cmr.c", "Rust computes CMRs itself"),
("test.c", "libsimplicity's test runner; defines main()"),
("regression4.c", "only used by test.c"),
("typeSkipTest.c", "only used by test.c"),
Expand Down Expand Up @@ -132,12 +129,12 @@ fn main() {
.file("depend/jets_wrapper.c")
.compile("RustSimplicityCommon");

// #385: uncomment once the Bitcoin transaction environment lands.
// build
// .clone()
// .files(sources(Library::Bitcoin))
// .file("depend/bitcoin_env.c")
// .compile("BitcoinSimplicity");
// Build the Bitcoin transaction environment's library.
build
.clone()
.files(sources(Library::Bitcoin))
.file("depend/bitcoin_env.c")
.compile("BitcoinSimplicity");

build
.files(sources(Library::Elements))
Expand Down
31 changes: 31 additions & 0 deletions simplicity-sys/depend/bitcoin_env.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdlib.h>
#include <stdalign.h>
#include "simplicity/bitcoin/env.h"
#include "simplicity/bitcoin/txEnv.h"
#include "simplicity/bitcoin/primitive.h"

typedef rawBitcoinBuffer rawBuffer;
typedef rawBitcoinBuffer rawBuffer;
typedef rawBitcoinOutput rawOutput;
typedef rawBitcoinInput rawInput;
typedef rawBitcoinTransaction rawTransaction;
typedef rawBitcoinTapEnv rawTapEnv;

const size_t rustsimplicity_0_8_c_sizeof_rawBitcoinBuffer = sizeof(rawBitcoinBuffer);
const size_t rustsimplicity_0_8_c_sizeof_rawBitcoinOutput = sizeof(rawBitcoinOutput);
const size_t rustsimplicity_0_8_c_sizeof_rawBitcoinInput = sizeof(rawBitcoinInput);
const size_t rustsimplicity_0_8_c_sizeof_rawBitcoinTransaction = sizeof(rawBitcoinTransaction);
const size_t rustsimplicity_0_8_c_sizeof_rawBitcoinTapEnv = sizeof(rawBitcoinTapEnv);
const size_t rustsimplicity_0_8_c_sizeof_bitcoinTxEnv = sizeof(txEnv);

const size_t rustsimplicity_0_8_c_alignof_rawBitcoinBuffer = alignof(rawBitcoinBuffer);
const size_t rustsimplicity_0_8_c_alignof_rawBitcoinOutput = alignof(rawBitcoinOutput);
const size_t rustsimplicity_0_8_c_alignof_rawBitcoinInput = alignof(rawBitcoinInput);
const size_t rustsimplicity_0_8_c_alignof_rawBitcoinTransaction = alignof(rawBitcoinTransaction);
const size_t rustsimplicity_0_8_c_alignof_rawBitcoinTapEnv = alignof(rawBitcoinTapEnv);
const size_t rustsimplicity_0_8_c_alignof_bitcoinTxEnv = alignof(txEnv);

void rustsimplicity_0_8_c_bitcoin_set_txEnv(txEnv *result, const bitcoinTransaction *tx, const bitcoinTapEnv *taproot, unsigned int ix)
{
*result = rustsimplicity_0_8_bitcoin_build_txEnv(tx, taproot, ix);
}
61 changes: 61 additions & 0 deletions simplicity-sys/depend/jets_wrapper.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* This file has been automatically generated. */

#include "simplicity/bitcoin/bitcoinJets.h"
#include "simplicity/elements/elementsJets.h"
#include "simplicity/simplicity_assert.h"
#include "wrapper.h"
Expand All @@ -17,15 +18,19 @@ WRAP_(and_16)
WRAP_(and_32)
WRAP_(and_64)
WRAP_(and_8)
WRAP_(bitcoin_annex_hash)
WRAP_(annex_hash)
WRAP_(asset_amount_hash)
WRAP_(bip_0340_verify)
WRAP_(broken_do_not_use_check_lock_distance)
WRAP_(broken_do_not_use_check_lock_duration)
WRAP_(broken_do_not_use_tx_lock_distance)
WRAP_(broken_do_not_use_tx_lock_duration)
WRAP_(bitcoin_build_tapbranch)
WRAP_(build_tapbranch)
WRAP_(bitcoin_build_tapleaf_simplicity)
WRAP_(build_tapleaf_simplicity)
WRAP_(bitcoin_build_taptweak)
WRAP_(build_taptweak)
WRAP_(calculate_asset)
WRAP_(calculate_confidential_token)
Expand All @@ -36,7 +41,11 @@ WRAP_(ch_16)
WRAP_(ch_32)
WRAP_(ch_64)
WRAP_(ch_8)
WRAP_(bitcoin_check_lock_distance)
WRAP_(bitcoin_check_lock_duration)
WRAP_(bitcoin_check_lock_height)
WRAP_(check_lock_height)
WRAP_(bitcoin_check_lock_time)
WRAP_(check_lock_time)
WRAP_(check_sig_verify)
WRAP_(complement_1)
Expand All @@ -45,21 +54,28 @@ WRAP_(complement_32)
WRAP_(complement_64)
WRAP_(complement_8)
WRAP_(current_amount)
WRAP_(bitcoin_current_annex_hash)
WRAP_(current_annex_hash)
WRAP_(current_asset)
WRAP_(bitcoin_current_index)
WRAP_(current_index)
WRAP_(current_issuance_asset_amount)
WRAP_(current_issuance_asset_proof)
WRAP_(current_issuance_token_amount)
WRAP_(current_issuance_token_proof)
WRAP_(current_new_issuance_contract)
WRAP_(current_pegin)
WRAP_(bitcoin_current_prev_outpoint)
WRAP_(current_prev_outpoint)
WRAP_(current_reissuance_blinding)
WRAP_(current_reissuance_entropy)
WRAP_(bitcoin_current_script_hash)
WRAP_(current_script_hash)
WRAP_(bitcoin_current_script_sig_hash)
WRAP_(current_script_sig_hash)
WRAP_(bitcoin_current_sequence)
WRAP_(current_sequence)
WRAP_(bitcoin_current_value)
WRAP_(decompress)
WRAP_(decrement_16)
WRAP_(decrement_32)
Expand Down Expand Up @@ -94,6 +110,7 @@ WRAP_(fe_negate)
WRAP_(fe_normalize)
WRAP_(fe_square)
WRAP_(fe_square_root)
WRAP_(bitcoin_fee)
WRAP_(full_add_16)
WRAP_(full_add_32)
WRAP_(full_add_64)
Expand Down Expand Up @@ -180,22 +197,39 @@ WRAP_(increment_64)
WRAP_(increment_8)
WRAP_(input_amount)
WRAP_(input_amounts_hash)
WRAP_(bitcoin_input_annex_hash)
WRAP_(input_annex_hash)
WRAP_(bitcoin_input_annexes_hash)
WRAP_(input_annexes_hash)
WRAP_(input_asset)
WRAP_(bitcoin_input_hash)
WRAP_(input_hash)
WRAP_(bitcoin_input_outpoints_hash)
WRAP_(input_outpoints_hash)
WRAP_(input_pegin)
WRAP_(bitcoin_input_prev_outpoint)
WRAP_(input_prev_outpoint)
WRAP_(bitcoin_input_script_hash)
WRAP_(input_script_hash)
WRAP_(bitcoin_input_script_sig_hash)
WRAP_(input_script_sig_hash)
WRAP_(bitcoin_input_script_sigs_hash)
WRAP_(input_script_sigs_hash)
WRAP_(bitcoin_input_scripts_hash)
WRAP_(input_scripts_hash)
WRAP_(bitcoin_input_sequence)
WRAP_(input_sequence)
WRAP_(bitcoin_input_sequences_hash)
WRAP_(input_sequences_hash)
WRAP_(bitcoin_input_utxo_hash)
WRAP_(input_utxo_hash)
WRAP_(bitcoin_input_utxos_hash)
WRAP_(input_utxos_hash)
WRAP_(bitcoin_input_value)
WRAP_(bitcoin_input_values_hash)
WRAP_(bitcoin_inputs_hash)
WRAP_(inputs_hash)
WRAP_(bitcoin_internal_key)
WRAP_(internal_key)
WRAP_(is_one_16)
WRAP_(is_one_32)
Expand Down Expand Up @@ -286,6 +320,7 @@ WRAP_(leftmost_8_2)
WRAP_(leftmost_8_4)
WRAP_(linear_combination_1)
WRAP_(linear_verify_1)
WRAP_(bitcoin_lock_time)
WRAP_(lock_time)
WRAP_(low_1)
WRAP_(low_16)
Expand Down Expand Up @@ -327,7 +362,9 @@ WRAP_(negate_64)
WRAP_(negate_8)
WRAP_(new_issuance_contract)
WRAP_(nonce_hash)
WRAP_(bitcoin_num_inputs)
WRAP_(num_inputs)
WRAP_(bitcoin_num_outputs)
WRAP_(num_outputs)
WRAP_(one_16)
WRAP_(one_32)
Expand All @@ -338,21 +375,28 @@ WRAP_(or_16)
WRAP_(or_32)
WRAP_(or_64)
WRAP_(or_8)
WRAP_(bitcoin_outpoint_hash)
WRAP_(outpoint_hash)
WRAP_(output_amount)
WRAP_(output_amounts_hash)
WRAP_(output_asset)
WRAP_(bitcoin_output_hash)
WRAP_(output_hash)
WRAP_(output_is_fee)
WRAP_(output_nonce)
WRAP_(output_nonces_hash)
WRAP_(output_null_datum)
WRAP_(output_range_proof)
WRAP_(output_range_proofs_hash)
WRAP_(bitcoin_output_script_hash)
WRAP_(output_script_hash)
WRAP_(bitcoin_output_scripts_hash)
WRAP_(output_scripts_hash)
WRAP_(output_surjection_proof)
WRAP_(output_surjection_proofs_hash)
WRAP_(bitcoin_output_value)
WRAP_(bitcoin_output_values_hash)
WRAP_(bitcoin_outputs_hash)
WRAP_(outputs_hash)
WRAP_(parse_lock)
WRAP_(parse_sequence)
Expand Down Expand Up @@ -424,6 +468,7 @@ WRAP_(scalar_negate)
WRAP_(scalar_normalize)
WRAP_(scalar_square)
WRAP_(scale)
WRAP_(bitcoin_script_cmr)
WRAP_(script_cmr)
WRAP_(sha_256_block)
WRAP_(sha_256_ctx_8_add_1)
Expand All @@ -440,6 +485,7 @@ WRAP_(sha_256_ctx_8_add_buffer_511)
WRAP_(sha_256_ctx_8_finalize)
WRAP_(sha_256_ctx_8_init)
WRAP_(sha_256_iv)
WRAP_(bitcoin_sig_all_hash)
WRAP_(sig_all_hash)
WRAP_(some_1)
WRAP_(some_16)
Expand All @@ -451,19 +497,34 @@ WRAP_(subtract_32)
WRAP_(subtract_64)
WRAP_(subtract_8)
WRAP_(swu)
WRAP_(bitcoin_tap_env_hash)
WRAP_(tap_env_hash)
WRAP_(tapdata_init)
WRAP_(bitcoin_tapleaf_hash)
WRAP_(tapleaf_hash)
WRAP_(bitcoin_tapleaf_version)
WRAP_(tapleaf_version)
WRAP_(bitcoin_tappath)
WRAP_(tappath)
WRAP_(bitcoin_tappath_hash)
WRAP_(tappath_hash)
WRAP_(total_fee)
WRAP_(bitcoin_total_input_value)
WRAP_(bitcoin_total_output_value)
WRAP_(bitcoin_transaction_id)
WRAP_(transaction_id)
WRAP_(bitcoin_tx_hash)
WRAP_(tx_hash)
WRAP_(bitcoin_tx_is_final)
WRAP_(tx_is_final)
WRAP_(bitcoin_tx_lock_distance)
WRAP_(bitcoin_tx_lock_duration)
WRAP_(bitcoin_tx_lock_height)
WRAP_(tx_lock_height)
WRAP_(bitcoin_tx_lock_time)
WRAP_(tx_lock_time)
WRAP_(verify)
WRAP_(bitcoin_version)
WRAP_(version)
WRAP_(xor_1)
WRAP_(xor_16)
Expand Down
2 changes: 1 addition & 1 deletion simplicity-sys/depend/simplicity-HEAD-revision.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file has been automatically generated.
ba967b1a0d57e069c37cd4041b8bae53f12fd456
aaeda4645fbc2be631f92d1a08c87066940d6ae0
3 changes: 3 additions & 0 deletions simplicity-sys/depend/simplicity-sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/// `CORE_OBJS` in libsimplicity's Makefile.
const CORE_SOURCES: &[&str] = &[
"bitstream.c",
"cmr.c",
"dag.c",
"deserialize.c",
"eval.c",
Expand All @@ -19,9 +20,11 @@ const CORE_SOURCES: &[&str] = &[
/// `BITCOIN_OBJS` in libsimplicity's Makefile.
const BITCOIN_SOURCES: &[&str] = &[
"bitcoin/env.c",
"bitcoin/exec.c",
"bitcoin/ops.c",
"bitcoin/bitcoinJets.c",
"bitcoin/primitive.c",
"bitcoin/cmr.c",
"bitcoin/txEnv.c",
];

Expand Down
38 changes: 38 additions & 0 deletions simplicity-sys/depend/simplicity/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 3.16)

project(BitcoinSimplicity)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS OFF)

add_library(BitcoinSimplicity STATIC
bitstream.c
cmr.c
dag.c
deserialize.c
eval.c
frame.c
jets-secp256k1.c
jets.c
rsort.c
sha256.c
type.c
typeInference.c
bitcoin/env.c
bitcoin/exec.c
bitcoin/bitcoinJets.c
bitcoin/cmr.c
bitcoin/ops.c
bitcoin/primitive.c
bitcoin/txEnv.c
)

option(PRODUCTION "Enable production build" ON)
if (PRODUCTION)
target_compile_definitions(BitcoinSimplicity PRIVATE "PRODUCTION")
endif()

target_include_directories(BitcoinSimplicity PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
4 changes: 2 additions & 2 deletions simplicity-sys/depend/simplicity/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CORE_OBJS := bitstream.o dag.o deserialize.o eval.o frame.o jets.o jets-secp256k1.o rsort.o sha256.o type.o typeInference.o
BITCOIN_OBJS := bitcoin/env.o bitcoin/ops.o bitcoin/bitcoinJets.o bitcoin/primitive.o bitcoin/txEnv.o
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
BITCOIN_OBJS := bitcoin/env.o bitcoin/exec.o bitcoin/ops.o bitcoin/bitcoinJets.o bitcoin/primitive.o bitcoin/cmr.o bitcoin/txEnv.o
ELEMENTS_OBJS := elements/env.o elements/exec.o elements/ops.o elements/elementsJets.o elements/primitive.o elements/cmr.o elements/txEnv.o
TEST_OBJS := test.o ctx8Pruned.o ctx8Unpruned.o hashBlock.o regression4.o schnorr0.o schnorr6.o typeSkipTest.o elements/checkSigHashAllTx1.o

Expand Down
22 changes: 22 additions & 0 deletions simplicity-sys/depend/simplicity/bitcoin/cmr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <simplicity/bitcoin/cmr.h>

#include "../cmr.h"
#include "primitive.h"

/* Deserialize a Simplicity 'program' and compute its CMR.
*
* Caution: no typechecking is performed, only a well-formedness check.
*
* If at any time malloc fails then '*error' is set to 'SIMPLICITY_ERR_MALLOC' and 'false' is returned,
* Otherwise, 'true' is returned indicating that the result was successfully computed and returned in the '*error' value.
*
* If the operation completes successfully then '*error' is set to 'SIMPLICITY_NO_ERROR', and the 'cmr' array is filled in with the program's computed CMR.
*
* Precondition: NULL != error;
* unsigned char cmr[32]
* unsigned char program[program_len]
*/
bool rustsimplicity_0_8_bitcoin_computeCmr( simplicity_err* error, unsigned char* cmr
, const unsigned char* program, size_t program_len) {
return rustsimplicity_0_8_computeCmr(error, cmr, rustsimplicity_0_8_bitcoin_decodeJet, program, program_len);
}
Loading
Loading