Code Monkey home page Code Monkey logo

sapio's People

Contributors

bennyhodl avatar cryptoquick avatar georgantas avatar git-sgmoore avatar jamesob avatar jb55 avatar jeremyrubin avatar jharveyb avatar jmomx avatar jnmclarty avatar joemphilips avatar knocte avatar naumenkogs avatar peamaeq avatar practicalswift avatar proofofkeags avatar pyskell avatar rn-g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sapio's Issues

Questions on Main Net Usage

These are questions rather than an issue report. I didn't find a Discord or Discussion tab on the GitHub repo, let me know if there's a better place for this.

  • Are you aware of any sapio contracts that are in use on bitcoin main net?
  • This doc page writes "Without full Taproot support, Sapio is probably ill-advisable to use at writing". Is this outdated? I think taproot went live at block 709,631, right?
  • My goal is a bitcoin main net script with the simple functionality of verifying signatures (Ideally ECDSA, but potentially other) from an authority, and updating who that authority is. The payment pool example may be closest to this goal. Do you see this as a viable use case on bitcoin main net right now?

Functional Unit Tests

It would be nice to add some basic tests across the project covering bits of functionality. Right now it's under-tested.

RFC: Allow value-based removal of functionality in contract

Currently, a sapio function is a type like fn() -> Option<ThenFunc<...>>. This is to enable type level programming (without access to values) to determine if a function should or should not be defined. Functions themselves then must return an iterator of templates. Currently, we require that if a ThenFunc is present, it must return at least one txtemplate, because otherwise a thenfunc would decay into a finishfunc, which should be explicitly requested.

What's missing is the ability to prune a thenfunc based on internal values. To fix this, we could add an additional type of guards which are checked at compile time and remove a branch if set.

A few possible syntaxes:

mixed:

    then! {continue_expansion [Self::period_over, Self::should_compile] |s, ctx| {

In this sytnax, we need a higher order trait to unify a script guard and a compile time guard, or we need fancy macro magic to split out on type.

dual list

  then! {continue_expansion [Self::should_compile] [Self::period_over] |s, ctx| {

in this syntax, we have two lists. It's confusing because the ordering means we lose the ability to make guards optional & it's probably confusing to remember

list with different braces:

  then! {continue_expansion <Self::should_compile> [Self::period_over] |s, ctx| {

This allows either order more clearly, but is further from normal rust look.

Proc Macros:

  #[sapio(then)]
  #[guards(a,b,c)]
  #[compile_if(d,e,f)]
  fn continue_expansion(&self, ctx: Context) -> Self::Then {
  
  }

This is probably the best longer term thing to do, as proc macros will make it easier to work with longer term. But there's a bit of a higher overhead to this approach...

error: no bin target named `sapio-cli`

Another error for you :) successfully built the treepay/ plugin with wasm-pack build but the next command fails.

Command that fails:
cargo run --bin sapio-cli -- contract create \{\"amount\":9.99,\"arguments\":\{\"Basic\":\{\"fee_sats_per_tx\":1000,\"participants\":\[\{\"address\":\"bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw\",\"amount\":2.99\}\],\"radix\":2\}\},\"network\":\"Regtest\"\} --file="plugin-example/treepay/pkg/sapio_wasm_plugin_example_bg.wasm"

Error code:
error: no bin target named sapio-cli

I'm sure I'm just missing something very basic.

Refactor Remove Stateful Arguments

It should be safe for StatefulArguments to always be serde_json::Value typed, which suggests we can remove it + coerce args, which would be very nice to do.

Can't `wasm-pack build`: No available targets are compatible with triple "wasm32-unknown-unknown"

I was trying to run README instructions and this is what I got. It seems to have something to do with clang (and I'm running Apple clang version 12.0.0 (clang-1200.0.32.2)).
OS: MacOS 11.2.3

error: failed to run custom build command for `secp256k1-sys v0.4.0`

Caused by:
  process didn't exit successfully: `/Users/gleb/Workspace/sapio/plugin-example/target/release/build/secp256k1-sys-5e6f5fc641c49029/build-script-build` (exit code: 1)
  --- stdout
  TARGET = Some("wasm32-unknown-unknown")
  OPT_LEVEL = Some("3")
  HOST = Some("x86_64-apple-darwin")
  CC_wasm32-unknown-unknown = None
  CC_wasm32_unknown_unknown = None
  TARGET_CC = None
  CC = None
  CFLAGS_wasm32-unknown-unknown = None
  CFLAGS_wasm32_unknown_unknown = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CC_wasm32-unknown-unknown = None
  CC_wasm32_unknown_unknown = None
  TARGET_CC = None
  CC = None
  CFLAGS_wasm32-unknown-unknown = None
  CFLAGS_wasm32_unknown_unknown = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-I" "wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_BUILD=1" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DECMULT_GEN_PREC_BITS=4" "-DUSE_NUM_NONE=1" "-DUSE_FIELD_INV_BUILTIN=1" "-DUSE_SCALAR_INV_BUILTIN=1" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/Users/gleb/Workspace/sapio/plugin-example/target/wasm32-unknown-unknown/release/build/secp256k1-sys-1758a304c2fd7414/out/depend/secp256k1/contrib/lax_der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c"
  cargo:warning=error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'
  cargo:warning=1 error generated.
  exit code: 1

  --- stderr


  error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-I" "wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_BUILD=1" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DECMULT_GEN_PREC_BITS=4" "-DUSE_NUM_NONE=1" "-DUSE_FIELD_INV_BUILTIN=1" "-DUSE_SCALAR_INV_BUILTIN=1" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/Users/gleb/Workspace/sapio/plugin-example/target/wasm32-unknown-unknown/release/build/secp256k1-sys-1758a304c2fd7414/out/depend/secp256k1/contrib/lax_der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c" with args "clang" did not execute successfully (status code exit code: 1).


warning: build failed, waiting for other jobs to finish...
    Building [=============================================>           ] 60/74: serde                                                                                         
error: build failed
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit code: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"
gleb@Glebs-MacBook-Pro plugin-example % 
gleb@Glebs-MacBook-Pro plugin-example % wasm-pack buildclang
error: The subcommand 'buildclang' wasn't recognized
	Did you mean 'build'?

If you believe you received this message in error, try re-running with 'wasm-pack -- buildclang'

error: could not compile `sapio-wasm-plugin-example` due to 4 previous errors; 2 warnings emitted

Resolving error: failed to build archive: section too large #146 by installing llvm and running AR=/usr/local/opt/llvm/bin/llvm-ar CC=/usr/local/opt/llvm/bin/clang wasm-pack build has led me to this error upon running this command:

Running on macOS Big Sur 11.6
Darwin alpha.local 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64

% AR=/usr/local/opt/llvm/bin/llvm-ar CC=/usr/local/opt/llvm/bin/clang wasm-pack build
[INFO]: ๐ŸŽฏ  Checking for the Wasm target...
[INFO]: ๐ŸŒ€  Compiling to Wasm...
   Compiling proc-macro2 v1.0.32
   Compiling unicode-xid v0.2.2
   Compiling autocfg v1.0.1
   Compiling syn v1.0.81
   Compiling autocfg v0.1.7
   Compiling rand_core v0.4.2
   Compiling serde_derive v1.0.130
   Compiling serde v1.0.130
   Compiling ryu v1.0.5
   Compiling serde_json v1.0.68
   Compiling itoa v0.4.8
   Compiling schemars v0.8.6
   Compiling cc v1.0.71
   Compiling dyn-clone v1.0.4
   Compiling memchr v2.4.1
   Compiling cfg-if v1.0.0
   Compiling log v0.4.14
   Compiling bech32 v0.7.3
   Compiling wasm-bindgen-shared v0.2.78
   Compiling tinyvec_macros v0.1.0
   Compiling matches v0.1.9
   Compiling version_check v0.9.3
   Compiling parking_lot_core v0.8.5
   Compiling bumpalo v3.8.0
   Compiling scopeguard v1.1.0
   Compiling lazy_static v1.4.0
   Compiling smallvec v1.7.0
   Compiling unicode-bidi v0.3.7
   Compiling percent-encoding v2.1.0
   Compiling bit-vec v0.6.3
   Compiling regex-syntax v0.6.25
   Compiling time-macros v0.2.3
   Compiling base64 v0.13.0
   Compiling once_cell v1.8.0
   Compiling num-cmp v0.1.0
   Compiling wasm-bindgen v0.2.78
   Compiling paste v1.0.5
   Compiling hex v0.4.3
   Compiling rand_core v0.3.1
   Compiling rand_jitter v0.1.4
   Compiling rand_os v0.1.3
   Compiling instant v0.1.12
   Compiling rand_pcg v0.1.2
   Compiling rand_chacha v0.1.1
   Compiling rand v0.6.5
   Compiling tinyvec v1.5.0
   Compiling num-traits v0.2.14
   Compiling num-integer v0.1.44
   Compiling num-bigint v0.2.6
   Compiling num-iter v0.1.42
   Compiling num-complex v0.2.4
   Compiling num-rational v0.2.4
   Compiling lock_api v0.4.5
   Compiling form_urlencoded v1.0.1
   Compiling bit-set v0.5.2
   Compiling ahash v0.7.6
   Compiling rand_hc v0.1.0
   Compiling rand_isaac v0.1.1
   Compiling rand_xorshift v0.1.1
   Compiling secp256k1-sys v0.4.1
   Compiling quote v1.0.10
   Compiling aho-corasick v0.7.18
   Compiling parking_lot v0.11.2
   Compiling unicode-normalization v0.1.19
   Compiling time v0.3.4
   Compiling regex v1.5.4
   Compiling idna v0.2.3
   Compiling url v2.2.2
   Compiling fancy-regex v0.7.1
   Compiling num v0.2.1
   Compiling fraction v0.8.0
   Compiling serde_derive_internals v0.25.0
   Compiling wasm-bindgen-backend v0.2.78
   Compiling wasm-bindgen-macro-support v0.2.78
   Compiling schemars_derive v0.8.6
   Compiling sapio_macros v0.1.0 (/Users/hu5ky5n0w/Projects/Bitcoin/sapio/sapio_macros)
   Compiling wasm-bindgen-macro v0.2.78
   Compiling jsonschema v0.12.2
   Compiling sapio-secp256k1 v0.20.1
   Compiling bitcoin_hashes v0.9.7
   Compiling sapio-bitcoin v0.26.0
   Compiling sapio-miniscript v5.1.0
   Compiling sapio-base v0.1.0 (/Users/hu5ky5n0w/Projects/Bitcoin/sapio/sapio-base)
   Compiling sapio-ctv-emulator-trait v0.1.2 (/Users/hu5ky5n0w/Projects/Bitcoin/sapio/emulator-trait)
   Compiling sapio-trait v0.1.0 (/Users/hu5ky5n0w/Projects/Bitcoin/sapio/sapio-trait)
   Compiling sapio v0.1.2 (/Users/hu5ky5n0w/Projects/Bitcoin/sapio/sapio)
   Compiling sapio-wasm-plugin v0.1.4 (/Users/hu5ky5n0w/Projects/Bitcoin/sapio/plugins)
   Compiling batching-trait v0.1.0 (/Users/hu5ky5n0w/Projects/Bitcoin/sapio/plugin-example/batching-trait)
warning: function is never used: `json_wrapped_string`
  --> /Users/hu5ky5n0w/Projects/Bitcoin/sapio/plugins/src/lib.rs:15:4
   |
15 | fn json_wrapped_string<'de, D, T>(d: D) -> Result<T, D::Error>
   |    ^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: unused return value of `std::ffi::CString::from_raw` that must be used
  --> /Users/hu5ky5n0w/Projects/Bitcoin/sapio/plugins/src/client/exports.rs:48:5
   |
48 |     CString::from_raw(s);
   |     ^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_must_use)]` on by default
   = note: call `drop(from_raw(ptr))` if you intend to drop the `CString`

warning: `sapio-wasm-plugin` (lib) generated 2 warnings
   Compiling sapio-wasm-plugin-example v0.1.0 (/Users/hu5ky5n0w/Projects/Bitcoin/sapio/plugin-example/treepay)
error: cannot find macro `then` in this scope
  --> treepay/src/plugin.rs:76:5
   |
76 |     then! {
   |     ^^^^
   |
note: `then` is imported here, but it is an attribute: `#[then]`
  --> treepay/src/plugin.rs:11:5
   |
11 | use sapio::*;
   |     ^^^^^^^^

error: cannot find macro `then` in this scope
  --> treepay/src/plugin.rs:50:5
   |
50 |     then! {
   |     ^^^^
   |
note: `then` is imported here, but it is an attribute: `#[then]`
  --> treepay/src/plugin.rs:11:5
   |
11 | use sapio::*;
   |     ^^^^^^^^

warning: unused import: `sapio::util::amountrange::*`
  --> treepay/src/plugin.rs:10:5
   |
10 | use sapio::util::amountrange::*;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused import: `std::collections::VecDeque`
  --> treepay/src/plugin.rs:17:5
   |
17 | use std::collections::VecDeque;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0599]: no function or associated item named `expand` found for struct `PayThese` in the current scope
  --> treepay/src/plugin.rs:72:27
   |
44 | struct PayThese {
   | --------------- function or associated item `expand` not found for this
...
72 |     declare! {then, Self::expand}
   |                           ^^^^^^ function or associated item not found in `PayThese`

error[E0599]: no function or associated item named `expand` found for struct `TreePay` in the current scope
   --> treepay/src/plugin.rs:117:27
    |
24  | pub struct TreePay {
    | ------------------ function or associated item `expand` not found for this
...
117 |     declare! {then, Self::expand}
    |                           ^^^^^^ function or associated item not found in `TreePay`

For more information about this error, try `rustc --explain E0599`.
warning: `sapio-wasm-plugin-example` (lib) generated 2 warnings
error: could not compile `sapio-wasm-plugin-example` due to 4 previous errors; 2 warnings emitted
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

Migrate from Policy to pluggable script generator

Using policy is convenient as it figures out automatically how to make a proper miniscript type.

However, Policy is not intended to be a 1:1 mapping, so really we should operate at the miniscript level if we want determinism, or make a deterministic policy version.

Fix Issue in Timelocks

One of the timelock try_from variants always returns Some, so it does not properly check that the timelock was properly formatted

Cross Module Call Caching & Forking

The cross module call system should be able to support module caches, currently it makes new instances always. Modules should have some sort of fork/clone semantic, currently they do not have one that works (related issue).

error: could not compile `secp256k1-sys` due to previous error

Error occurred on Build a Plugin step of the guide here: https://learn.sapio-lang.org/ch01-01-installation.html

Specific error code: error: failed to build archive: section too large
macOS Big Sur 11.6
Output of uname -a:

Darwin WUSBN185068-8YO 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64

See below for full command output:

WUSBN185068-8YO:bn185068 treepay % wasm-pack build
[INFO]: ๐ŸŽฏ  Checking for the Wasm target...
[INFO]: ๐ŸŒ€  Compiling to Wasm...
   Compiling secp256k1-sys v0.4.1
   Compiling serde_json v1.0.68
error: failed to build archive: section too large

The following warnings were emitted during compilation:

warning: depend/secp256k1/src/secp256k1.c:7:9: warning: 'SECP256K1_BUILD' macro redefined [-Wmacro-redefined]
warning: #define SECP256K1_BUILD
warning:         ^
warning: <command line>:1:9: note: previous definition is here
warning: #define SECP256K1_BUILD 1
warning:         ^
warning: In file included from depend/secp256k1/src/secp256k1.c:12:
warning: In file included from depend/secp256k1/src/assumptions.h:12:
warning: In file included from depend/secp256k1/src/util.h:16:
warning: wasm-sysroot/stdio.h:4:28: warning: 'extern' variable has an initializer [-Wextern-initializer]
warning: extern const unsigned char WASM32_INT_SIZE = sizeof(int);
warning:                            ^
warning: wasm-sysroot/stdio.h:5:28: warning: 'extern' variable has an initializer [-Wextern-initializer]
warning: extern const unsigned char WASM32_INT_ALIGN = alignof(int);
warning:                            ^
warning: wasm-sysroot/stdio.h:7:28: warning: 'extern' variable has an initializer [-Wextern-initializer]
warning: extern const unsigned char WASM32_UNSIGNED_INT_SIZE = sizeof(unsigned int);
warning:                            ^
warning: wasm-sysroot/stdio.h:8:28: warning: 'extern' variable has an initializer [-Wextern-initializer]
warning: extern const unsigned char WASM32_UNSIGNED_INT_ALIGN = alignof(unsigned int);
warning:                            ^
warning: wasm-sysroot/stdio.h:10:28: warning: 'extern' variable has an initializer [-Wextern-initializer]
warning: extern const unsigned char WASM32_SIZE_T_SIZE = sizeof(size_t);
warning:                            ^
warning: wasm-sysroot/stdio.h:11:28: warning: 'extern' variable has an initializer [-Wextern-initializer]
warning: extern const unsigned char WASM32_SIZE_T_ALIGN = alignof(size_t);
warning:                            ^
warning: wasm-sysroot/stdio.h:13:28: warning: 'extern' variable has an initializer [-Wextern-initializer]
warning: extern const unsigned char WASM32_UNSIGNED_CHAR_SIZE = sizeof(unsigned char);
warning:                            ^
warning: wasm-sysroot/stdio.h:14:28: warning: 'extern' variable has an initializer [-Wextern-initializer]
warning: extern const unsigned char WASM32_UNSIGNED_CHAR_ALIGN = alignof(unsigned char);
warning:                            ^
warning: wasm-sysroot/stdio.h:16:28: warning: 'extern' variable has an initializer [-Wextern-initializer]
warning: extern const unsigned char WASM32_PTR_SIZE = sizeof(void*);
warning:                            ^
warning: wasm-sysroot/stdio.h:17:28: warning: 'extern' variable has an initializer [-Wextern-initializer]
warning: extern const unsigned char WASM32_PTR_ALIGN = alignof(void*);
warning:                            ^
warning: In file included from depend/secp256k1/src/secp256k1.c:17:
warning: In file included from depend/secp256k1/src/ecmult_impl.h:16:
warning: In file included from depend/secp256k1/src/ecmult.h:12:
warning: depend/secp256k1/src/scratch.h:24:38: warning: unused function 'rustsecp256k1_v0_4_1_scratch_create' [-Wunused-function]
warning: static rustsecp256k1_v0_4_1_scratch* rustsecp256k1_v0_4_1_scratch_create(const rustsecp256k1_v0_4_1_callback* error_callback, size_t max_size);
warning:                                      ^
warning: depend/secp256k1/src/scratch.h:26:13: warning: unused function 'rustsecp256k1_v0_4_1_scratch_destroy' [-Wunused-function]
warning: static void rustsecp256k1_v0_4_1_scratch_destroy(const rustsecp256k1_v0_4_1_callback* error_callback, rustsecp256k1_v0_4_1_scratch* scratch);
warning:             ^
warning: In file included from depend/secp256k1/src/secp256k1.c:17:
warning: depend/secp256k1/src/ecmult_impl.h:1035:12: warning: unused function 'rustsecp256k1_v0_4_1_ecmult_multi_var' [-Wunused-function]
warning: static int rustsecp256k1_v0_4_1_ecmult_multi_var(const rustsecp256k1_v0_4_1_callback* error_callback, const rustsecp256k1_v0_4_1_ecmult_context *ctx, rustsecp256k1_v0_4_1_scratch *scratch, rustsecp256k1_v0_4_1_gej *r, const rustsecp256k1_v0_4_1_scalar *inp_g_sc, rustsecp256k1_v0_4_1_ecmult_multi_callback cb, void *cbdata, size_t n) {
warning:            ^
warning: depend/secp256k1/src/ecmult_impl.h:621:12: warning: unused function 'rustsecp256k1_v0_4_1_ecmult_strauss_batch_single' [-Wunused-function]
warning: static int rustsecp256k1_v0_4_1_ecmult_strauss_batch_single(const rustsecp256k1_v0_4_1_callback* error_callback, const rustsecp256k1_v0_4_1_ecmult_context *actx, rustsecp256k1_v0_4_1_scratch *scratch, rustsecp256k1_v0_4_1_gej *r, const rustsecp256k1_v0_4_1_scalar *inp_g_sc, rustsecp256k1_v0_4_1_ecmult_multi_callback cb, void *cbdata, size_t n) {
warning:            ^
warning: depend/secp256k1/src/ecmult_impl.h:863:15: warning: unused function 'rustsecp256k1_v0_4_1_pippenger_scratch_size' [-Wunused-function]
warning: static size_t rustsecp256k1_v0_4_1_pippenger_scratch_size(size_t n_points, int bucket_window) {
warning:               ^
warning: depend/secp256k1/src/ecmult_impl.h:944:12: warning: unused function 'rustsecp256k1_v0_4_1_ecmult_pippenger_batch_single' [-Wunused-function]
warning: static int rustsecp256k1_v0_4_1_ecmult_pippenger_batch_single(const rustsecp256k1_v0_4_1_callback* error_callback, const rustsecp256k1_v0_4_1_ecmult_context *actx, rustsecp256k1_v0_4_1_scratch *scratch, rustsecp256k1_v0_4_1_gej *r, const rustsecp256k1_v0_4_1_scalar *inp_g_sc, rustsecp256k1_v0_4_1_ecmult_multi_callback cb, void *cbdata, size_t n) {
warning:            ^
warning: 17 warnings generated.
warning: warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: /Users/BN185068/Projects/Bitcoin/sapio/plugin-example/target/wasm32-unknown-unknown/release/build/secp256k1-sys-64f6e92ae7a58219/out/libsecp256k1.a the table of contents is empty (no object file members in the library define global symbols)

error: could not compile `secp256k1-sys` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit code: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

Add Multisig Special Clause / Special Operator

Compiling to a native checkmultisig can have benefits for script size. Add an option to input signer groups as checkmultisig, and add a tree pass which can collapse signing groups into multi-sig.

Also consider adding a compiler pass to lift signature groups out of cases if exact matches.

TODO: Better Bindings to Rust-Miniscript

As of now there is a basic "hand written" binding for miniscript compilation. As a larger effort, it might make sense to think about how to provide better Python bindings (e.g., through PYO3). Handwritten bindings are not that bad, and maybe good if you only want to expose a carefully crafted API, but it might be a generally nice thing for miniscript to be available as a python library.

@sanket1729

Error: nothing matched in oneOf, Error: Required properties "context" are missing

Error at step 6 Instantiate a contract from the plugin. Had to run a different command than in the install doc. See #151 for context on that command.

Ran this from within the treepay/ folder.

sapio-cli contract create \{\"amount\":9.99,\"arguments\":\{\"Basic\":\{\"fee_sats_per_tx\":1000,\"participants\":\[\{\"address\":\"bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw\",\"amount\":2.99\}\],\"radix\":2\}\},\"network\":\"Regtest\"\} --file="pkg/sapio_wasm_plugin_example_bg.wasm"

Got this output error:

Error: nothing matched in oneOf
At instance path /arguments:
  {
    "Basic": {
      "fee_sats_per_tx": 1000,
      "participants": [
        {
          "address": "bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw",
          "amount": 2.99
        }
      ],
      "radix": 2
    }
  }

At schema path /properties/arguments/allOf/0/oneOf:
  [
    {
      "additionalProperties": false,
      "properties": {
        "TreePay": {
          "$ref": "#/definitions/TreePay"
        }
      },
      "required": [
        "TreePay"
      ],
      "title": "Standard Tree Pay",
      "type": "object"
    },
    {
      "additionalProperties": false,
      "properties": {
        "Advanced": {
          "properties": {
            "main_arguments": {
              "allOf": [
                {
                  "$ref": "#/definitions/TreePay"
                }
              ],
              "title": "Standard Tree Pay"
            },
            "random_field": {
              "format": "uint8",
              "minimum": 0.0,
              "title": "A Random Field For Example",
              "type": "integer"
            }
          },
          "required": [
            "main_arguments",
            "random_field"
          ],
          "type": "object"
        }
      },
      "required": [
        "Advanced"
      ],
      "title": "Advanced Tree Pay",
      "type": "object"
    },
    {
      "additionalProperties": false,
      "properties": {
        "BatchingTraitVersion0_1_1": {
          "$ref": "#/definitions/BatchingTraitVersion0_1_1"
        }
      },
      "required": [
        "BatchingTraitVersion0_1_1"
      ],
      "title": "Batching Trait API",
      "type": "object"
    }
  ]


Error: Required properties "context" are missing
At instance path /:
  {
    "amount": 9.99,
    "arguments": {
      "Basic": {
        "fee_sats_per_tx": 1000,
        "participants": [
          {
            "address": "bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw",
            "amount": 2.99
          }
        ],
        "radix": 2
      }
    },
    "network": "Regtest"
  }

At schema path /required:
  [
    "arguments",
    "context"
  ]

Failed to parse manifest

Hello, I am trying to build a package and instantiate a contract but I get this error

Error: failed to parse manifest: /home/allan/sapio/plugin-example/Cargo.toml Caused by: missing field package

Refactor MapEffectDB to a forking API

The MapEffectDB system should be moved outside of the memory space of WASM, and accessed solely through a forking API that forks the module to run with / without the effect observed and merge the results after. This helps with determinism.

Outdated Docs (`example`)

I can create a PR to update this, but it looks like the current quickstart no longer works as of 93006e7 since the examples folder has been removed.

I believe swapping out cargo run --example server --features ws (and the command in the Debugging Macros section with cargo run --bin sapio-ws should fix this

New Syntax Proposal?

Hi all,

I think the syntax abusing python classes is "cute", but ultimately going to be hard(er) to maintain and get to typecheck fully because there's too much magic.

Thus I'm proposing something like as follows:

 # Similar to React Props
 class Variables(TypeDict):
     key: PubKey
     amount: Amount
 
 # A list of Traits that should be implemented by the contract
 
 class HasAmount(Trait):
     @staticmethod
     def static_checks(cls):
         # Checks that class variable amount is defined
         cls.Variables.amount
 class HasNoUnlock(Trait):
     @staticmethod
     def static_checks(cls):
         # Check that there are no unlock methods
         assert len(cls.__impl__.unlock_methods) == 0
 
 Traits = (HasAmount, HasNoUnlock)
 
 c = Contract("c", Variables, Traits)
 
 @c.require
 def y(self):
     return SignedBy(self.key)
 
 @c.y
 @c.guarantee
 def x(self):
     tx =  TransactionTemplate()
     return tx
     
 b = c.prototype.copy()
 b.rename('b')
 @b.guarantee
 def z(self):
     tx =  TransactionTemplate()
     return tx

This is obviously not final as it will require a couple iterations to get it right.

My hope is to make it not too much more verbose, while being a better platform for new features.

If anyone has any feedback, please let me know!

[feature request]tooling for installation verification

Issue: Currently no way to verify if Sapio was installed correctly.

Example: In my installation I was getting "cargo build" errors when trying to build plugins. I assume that somehow the installation screwed up and I am missing some dependencies

feature request: A script that can handle verification of necessary dependencies for Sapio.

Is this a valid 2-of-3 escrow? Where can we and can't we use regular python functions?

I was trying to make a new version of BasicEscrow:

class BasicEscrow(Contract):
    class Fields:
        alice: PubKey
        bob: PubKey
        escrow: PubKey

    @unlock
    def redeem(self):
        accounts = [self.escrow, self.alice, self.bob]
        signed = [SignedBy(v) for i, v in enumerate(accounts)]

        return sum(signed) > 1

It passes tests but I'm just slightly confused at the moment on where I can use python functions or if I'm restricted to what bitcoin_script_compiler provides. I see multisig uses reduce so I assume this is okay too?

SIMP Based Test Framework

For the entries in sapio_zoo and sapio_stdlib, it should be possible to have some "contract controller" framework which makes it simple to test/drive contracts and simulate against a Bitcoin Node.

Some challenges with this:

  1. How to link against a compatible Bitcoind version
  2. How to allow testing undesirable state transitions

Procedural Macros for Sapio

Currently we use some (very nice) macros to make defining a sapio contract simpler.

However, this approach isn't quite optimal because it is difficult to make work with things like autoformatting and doesn't look rust-y.

To improve this, in #87 we discussed making proc macros. This would end up being a bit more verbose, but not awfully so.

This issue is to brainstorm what that should look like/what to prioritize.

In my view, it would be really nice if there were a way to make things look very native, e.g.:

#[sapio(then, compile_if=[A, B, C], guarded_by=[X,Y,Z])]
fn do_something(&self, ctx: &Context) -> Self::Then
{
}

The tradeoff here is verbosity -- it would be great if we could take advantage of a known signature to do something like:

#[sapio(compile_if=[A, B, C], guarded_by=[X,Y,Z])]
then do_something
{
}

and have it automatically inject the self/ctx params. But it is unclear if rust syntax tools would be unhappy with formatting such code...

More Efficient Emulator API

Currently we call the emulator API on each individual template during compilation.

Instead of doing that, investigate an API where all calls can be batched at the same time.

Why?

This gives flexibility of the Emulator to return a global clause that can be satisfied by any txtemplate.
E.g., we could change the concrete emulator API to derive the key from a merkle tree of all txtemplate psbts passed, and require a merkle path in order to sign with a given key?

This is important for reducing the script size without taproot or ctv.

local quickstart: No available targets are compatible with triple "wasm32-unknown-unknown"

I'm following the quickstart guide, and trying to run Sapio. I can't get past building the example project because of a Rust error. This is on a brand new rustup installation, and I've done $ rustup target add wasm32-unknown-unknown.

I'm running on Ubuntu 20. Not really familiar with the Rust ecosystem, so kind of in the dark as to what I'm looking at here

Error message, with command

โฎ cargo build --target wasm32-unknown-unknown
   Compiling secp256k1-sys v0.4.1
   Compiling url v2.2.2
   Compiling serde v1.0.132
   Compiling schemars_derive v0.8.8
   Compiling num-rational v0.2.4
   Compiling wasm-bindgen-macro-support v0.2.78
The following warnings were emitted during compilation:

warning: error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'
warning: 1 error generated.

error: failed to run custom build command for `secp256k1-sys v0.4.1`

Caused by:
  process didn't exit successfully: `/home/torkel/dev/bitcoin/sapio/plugin-example/target/debug/build/secp256k1-sys-6d98d50cf5cb04d0/build-script-build` (exit status: 1)
  --- stdout
  TARGET = Some("wasm32-unknown-unknown")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-unknown-linux-gnu")
  CC_wasm32-unknown-unknown = None
  CC_wasm32_unknown_unknown = None
  TARGET_CC = None
  CC = None
  CFLAGS_wasm32-unknown-unknown = None
  CFLAGS_wasm32_unknown_unknown = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CC_wasm32-unknown-unknown = None
  CC_wasm32_unknown_unknown = None
  TARGET_CC = None
  CC = None
  CFLAGS_wasm32-unknown-unknown = None
  CFLAGS_wasm32_unknown_unknown = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  running: "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-I" "wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_BUILD=1" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DECMULT_GEN_PREC_BITS=4" "-DUSE_NUM_NONE=1" "-DUSE_FIELD_INV_BUILTIN=1" "-DUSE_SCALAR_INV_BUILTIN=1" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/home/torkel/dev/bitcoin/sapio/plugin-example/target/wasm32-unknown-unknown/debug/build/secp256k1-sys-8c4bca1b90d79376/out/depend/secp256k1/contrib/lax_der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c"
  cargo:warning=error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'
  cargo:warning=1 error generated.
  exit status: 1

  --- stderr


  error occurred: Command "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-I" "wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_BUILD=1" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DECMULT_GEN_PREC_BITS=4" "-DUSE_NUM_NONE=1" "-DUSE_FIELD_INV_BUILTIN=1" "-DUSE_SCALAR_INV_BUILTIN=1" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/home/torkel/dev/bitcoin/sapio/plugin-example/target/wasm32-unknown-unknown/debug/build/secp256k1-sys-8c4bca1b90d79376/out/depend/secp256k1/contrib/lax_der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c" with args "clang" did not execute successfully (status code exit status: 1).


warning: build failed, waiting for other jobs to finish...
error: build failed

Available targets

โฏ rustup target list
aarch64-apple-darwin
aarch64-apple-ios
aarch64-apple-ios-sim
aarch64-fuchsia
aarch64-linux-android
aarch64-pc-windows-msvc
aarch64-unknown-linux-gnu
aarch64-unknown-linux-musl
aarch64-unknown-none
aarch64-unknown-none-softfloat
arm-linux-androideabi
arm-unknown-linux-gnueabi
arm-unknown-linux-gnueabihf
arm-unknown-linux-musleabi
arm-unknown-linux-musleabihf
armebv7r-none-eabi
armebv7r-none-eabihf
armv5te-unknown-linux-gnueabi
armv5te-unknown-linux-musleabi
armv7-linux-androideabi
armv7-unknown-linux-gnueabi
armv7-unknown-linux-gnueabihf
armv7-unknown-linux-musleabi
armv7-unknown-linux-musleabihf
armv7a-none-eabi
armv7r-none-eabi
armv7r-none-eabihf
asmjs-unknown-emscripten
i586-pc-windows-msvc
i586-unknown-linux-gnu
i586-unknown-linux-musl
i686-linux-android
i686-pc-windows-gnu
i686-pc-windows-msvc
i686-unknown-freebsd
i686-unknown-linux-gnu
i686-unknown-linux-musl
mips-unknown-linux-gnu
mips-unknown-linux-musl
mips64-unknown-linux-gnuabi64
mips64-unknown-linux-muslabi64
mips64el-unknown-linux-gnuabi64
mips64el-unknown-linux-muslabi64
mipsel-unknown-linux-gnu
mipsel-unknown-linux-musl
nvptx64-nvidia-cuda
powerpc-unknown-linux-gnu
powerpc64-unknown-linux-gnu
powerpc64le-unknown-linux-gnu
riscv32i-unknown-none-elf
riscv32imac-unknown-none-elf
riscv32imc-unknown-none-elf
riscv64gc-unknown-linux-gnu
riscv64gc-unknown-none-elf
riscv64imac-unknown-none-elf
s390x-unknown-linux-gnu
sparc64-unknown-linux-gnu
sparcv9-sun-solaris
thumbv6m-none-eabi
thumbv7em-none-eabi
thumbv7em-none-eabihf
thumbv7m-none-eabi
thumbv7neon-linux-androideabi
thumbv7neon-unknown-linux-gnueabihf
thumbv8m.base-none-eabi
thumbv8m.main-none-eabi
thumbv8m.main-none-eabihf
wasm32-unknown-emscripten
wasm32-unknown-unknown (installed)
wasm32-wasi
x86_64-apple-darwin
x86_64-apple-ios
x86_64-fortanix-unknown-sgx
x86_64-fuchsia
x86_64-linux-android
x86_64-pc-solaris
x86_64-pc-windows-gnu
x86_64-pc-windows-msvc
x86_64-sun-solaris
x86_64-unknown-freebsd
x86_64-unknown-illumos
x86_64-unknown-linux-gnu (installed)
x86_64-unknown-linux-gnux32
x86_64-unknown-linux-musl
x86_64-unknown-netbsd
x86_64-unknown-redox

Decide on a License

Unclear what license is best / makes most sense to use. Would love community feedback on this!

pyenv - python-build: definition not found: 3.8.3

Not sure if this is unique to me but on my linux box with pyenv 3.8.3 is not an installable version of python, even with pyenv fully up to date.

Install worked fine on 3.8.2

$ pyenv install 3.8.3
python-build: definition not found: 3.8.3

The following versions contain `3.8.3' in the name:
  miniconda-3.8.3
  miniconda3-3.8.3

See all available versions with `pyenv install --list'.

If the version you need is missing, try upgrading pyenv.

Consider using Dhall as an internal representation instead of json-schema

Not sure of the relative benefits and costs of this. But it occurred to me during some investigation of the artifacts. JSON Schema is well specified but it is extremely verbose and while the overall structure (json) is familiar, the ceremony around the structure of the document produced by sapio-cli contract api --file=X makes it difficult to tell the high level details of a contract API.

My understanding of the purpose of the json-schema based API suggests that this is primarily a document that needs to be ingested by software and only secondarily is intended for human scrutiny.

Dhall is a configuration language that has nearly isomorphic properties to json but supports both types and terminating functions to avoid repetition. This may make it easier to extract meaning from the document when it is read by humans.

Dhall has interfaces into rust as well.

Reasons not to do this:

  • dhall is less well-known than json-schema (most likely)
  • humans are scrutinizing this so infrequently that the added benefits are little, moving this far down the priority list
  • there are constraints that need to be specified that are not able to be specified in the dhall type language
  • dhall types don't typically have descriptions. If the description field is necessary it may mean dhall is unusable for this use case, though this requires further investigation.

Reasons to do this:

  • more concise schema documents
  • the ability to specify higher order schemas
  • dhall <> rust bridge is well used, and therefore unlikely to have implementation gotchas.

Consistent & Clear terminology clean up

Plugins, Callable, Modules, continuations, finish_or_fns, etc...

sapio codebase could use a comb over to make the terminology clear, consistent, and simple.

Unable to get binding of the template to UTXO

I am getting this error when trying to bind the contract:

.ok_or("Expected to have exactly one of key or file")?;

ARGS.json file:

{
  "context": {
 "amount": 3,
 "network": "Signet",
 "effects": {
   "effects": {}
 }
  },
  "arguments": {
 "TreePay": {
   "fee_sats_per_tx": 1000,
   "participants": [
     {
       "address": "tb1qz2w0qsgrmgaa99yzh8m6nqne89lega49ucehqg",
       "amount": 1
     },
     {
       "address": "tb1qz2w0qsgrmgaa99yzh8m6nqne89lega49ucehqg",
       "amount": 1
     }
   ],
   "radix": 2
 }
  }
}
[test@fedora sapio]$ cat /home/test/Documents/ARGS.json| ./target/release/sapio-cli contract create  --file plugin-example/target/wasm32-unknown-unknown/release/sapio_wasm_plugin_example.wasm  | jq > /home/test/Documents/UNBOUND.json

[test@fedora sapio]$ cat /home/test/Documents/UNBOUND.json | ./target/release/sapio-cli contract bind | jq > /home/test/Documents/BOUND.json
Error: "Expected to have exactly one of key or file"

"python3 setup.py build" fails for rust_miniscript

python3 setup.py build fails for rust_miniscript. What am I doing wrong? :)

$ rustc -V
rustc 1.45.0 (5c1f21c3b 2020-07-13)
$ cd rust_miniscript/
$ make
pip3 install -r requirements.txt
Requirement already satisfied: setuptools-rust==0.10.6
Requirement already satisfied: cffi==1.14.0
Requirement already satisfied: semantic-version>=2.6.0
Requirement already satisfied: toml>=0.9.0
Requirement already satisfied: pycparser
$ python3 setup.py build
python3 setup.py build
running build
running build_py
running build_ext
running build_rust
error: manifest path `rust_miniscript/rust-miniscript/Cargo.toml` does not exist
โ€ฆ
subprocess.CalledProcessError: Command '['cargo', 'metadata', '--manifest-path', 'rust_miniscript/rust-miniscript/Cargo.toml', '--format-version', '1']' returned non-zero exit status 101.

Improve Guard SIMP Structure

#217 adds SIMPs for Guards.

However, Guards end up possibly being called multiple times, producing multiple SIMPs for one Guard.

To fix this, all guards should always be cached, or we should do something else.

Failed to install rust_miniscript

make test fails after installing:

(sapio) โœ” ~/sapio [master {origin/master}|โ€ฆ1] 
11:30 $ make test
cd sapio_bitcoinlib && make test
make[1]: Entering directory '/home/me/sapio/sapio_bitcoinlib'
python3 -m unittest

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
make[1]: Leaving directory '/home/me/sapio/sapio_bitcoinlib'
cd bitcoin_script_compiler && make test
make[1]: Entering directory '/home/me/sapio/bitcoin_script_compiler'
python3 -m unittest

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
make[1]: Leaving directory '/home/me/sapio/bitcoin_script_compiler'
cd sapio_compiler && make test
make[1]: Entering directory '/home/me/sapio/sapio_compiler'
python3 -m unittest
E.
======================================================================
ERROR: sapio_compiler (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: sapio_compiler
Traceback (most recent call last):
  File "/home/me/.pyenv/versions/3.8.3/lib/python3.8/unittest/loader.py", line 470, in _find_test_path
    package = self._get_module_from_name(name)
  File "/home/me/.pyenv/versions/3.8.3/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/me/sapio/sapio_compiler/sapio_compiler/__init__.py", line 1, in <module>
    from .exports import *
  File "/home/me/sapio/sapio_compiler/sapio_compiler/exports.py", line 5, in <module>
    from .contract import Contract
  File "/home/me/sapio/sapio_compiler/sapio_compiler/contract.py", line 7, in <module>
    from .core.bindable_contract import BindableContract
  File "/home/me/sapio/sapio_compiler/sapio_compiler/core/bindable_contract.py", line 24, in <module>
    from sapio_compiler.core.initializer import Initializer
  File "/home/me/sapio/sapio_compiler/sapio_compiler/core/initializer.py", line 26, in <module>
    import rust_miniscript
ModuleNotFoundError: No module named 'rust_miniscript'


----------------------------------------------------------------------
Ran 2 tests in 0.000s

FAILED (errors=1)
make[1]: *** [Makefile:6: test] Error 1
make[1]: Leaving directory '/home/me/sapio/sapio_compiler'
make: *** [Makefile:4: test] Error 2
(sapio) โœ˜-2 ~/sapio [master {origin/master}|โ€ฆ1] 

I believe this is because the install guide is missing rust_miniscript here:

for MODULE in sapio_bitcoinlib bitcoin_script_compiler sapio_compiler sapio_stdlib sapio_zoo sapio_server; do
      echo "Building ${MODULE}"
      cd $MODULE && make && python3 setup.py build && python3 setup.py install && cd ..
      echo
  done

However trying to do this manually for rust_miniscript also fails:

(sapio) โœ” ~/sapio/rust_miniscript [master {origin/master}|โ€ฆ1] 
11:32 $ make && python3 setup.py build && python3 setup.py install
pip3 install -r requirements.txt
Requirement already satisfied: setuptools-rust==0.10.6 in /home/me/.pyenv/versions/3.8.3/envs/sapio/lib/python3.8/site-packages (from -r requirements.txt (line 1)) (0.10.6)
Requirement already satisfied: cffi==1.14.0 in /home/me/.pyenv/versions/3.8.3/envs/sapio/lib/python3.8/site-packages (from -r requirements.txt (line 2)) (1.14.0)
Requirement already satisfied: toml>=0.9.0 in /home/me/.pyenv/versions/3.8.3/envs/sapio/lib/python3.8/site-packages (from setuptools-rust==0.10.6->-r requirements.txt (line 1)) (0.10.1)
Requirement already satisfied: semantic-version>=2.6.0 in /home/me/.pyenv/versions/3.8.3/envs/sapio/lib/python3.8/site-packages (from setuptools-rust==0.10.6->-r requirements.txt (line 1)) (2.8.5)
Requirement already satisfied: pycparser in /home/me/.pyenv/versions/3.8.3/envs/sapio/lib/python3.8/site-packages (from cffi==1.14.0->-r requirements.txt (line 2)) (2.20)
WARNING: You are using pip version 19.2.3, however version 20.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
running build
running build_py
running build_ext
running build_rust
error: manifest path `rust_miniscript/rust-miniscript/Cargo.toml` does not exist
Traceback (most recent call last):
  File "setup.py", line 11, in <module>
    setup(
  File "/home/me/.pyenv/versions/sapio/lib/python3.8/site-packages/setuptools/__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "/home/me/.pyenv/versions/3.8.3/lib/python3.8/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/home/me/.pyenv/versions/3.8.3/lib/python3.8/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/home/me/.pyenv/versions/3.8.3/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/home/me/.pyenv/versions/3.8.3/lib/python3.8/distutils/command/build.py", line 135, in run
    self.run_command(cmd_name)
  File "/home/me/.pyenv/versions/3.8.3/lib/python3.8/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/home/me/.pyenv/versions/3.8.3/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/home/me/.pyenv/versions/sapio/lib/python3.8/site-packages/setuptools_rust/build_ext.py", line 26, in run
    build_rust.run()
  File "/home/me/.pyenv/versions/sapio/lib/python3.8/site-packages/setuptools_rust/build.py", line 313, in run
    self.build_extension(ext)
  File "/home/me/.pyenv/versions/sapio/lib/python3.8/site-packages/setuptools_rust/build.py", line 95, in build_extension
    metadata = json.loads(check_output(metadata_command).decode("utf-8"))
  File "/home/me/.pyenv/versions/3.8.3/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/home/me/.pyenv/versions/3.8.3/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['cargo', 'metadata', '--manifest-path', 'rust_miniscript/rust-miniscript/Cargo.toml', '--format-version', '1']' returned non-zero exit status 101.

Replace JSONSchema

we'd like to replace JSONSchema with something simpler and "application specific" that can go into rust-bitcoin (that means no deps not already in rust-bitcoin). There can be a function from our spec -> JsonSchema too, for compatibility. DHall is not an option because it has a bunch of deps.

Brainstorm being able to pass information from *children* to *parents*

Motivating example:

class A(Contract):
  class Fields:
    amount: Amount
  @guarantee
  def spend(self):
    t = TransactionTemplate()
    t.add_output(self.amount//2, B())
    t.add_output(self.amount//2, C())

suppose we want to hold that B has two weeks to be spent before C. There are a few ways to do this:

We could pass down a oneshot getter/setter

class Prop:
  def __init__(self):
    self.v = None
  def set(self, x):
    assert self.v is None
    self.v = x
  def get(self):
    assert self.v is not None
    return self.v
class A(Contract):
  class Fields:
    amount: Amount
  @guarantee
  def spend(self):
    t = TransactionTemplate()
    b_timeout = Prop()
    c_timeout = Prop()
    t.add_output(self.amount//2, B(timeout = b_timeout))
    t.add_output(self.amount//2, C(timeout = c_timeout))
    assert b_timeout.get() >= c_timeout.get() + 2 weeks

This is nice because it's a pretty flexible paradigm for passing information up from sub constracts. The sub-contract just has to follow the protocol of somewhere setting the data as required. The downside is that sometimes we want to share Props across different paths, so we might actually want to have the Prop fields stored as some sort of class local props. E.g. every contract has a self.props which can create/access things by name

An interesting note is that there then can become compilation order dependencies and deadlocks. E.g., if guaranteed spend 1 depends on data from guaranteed spend 2:

class A(Contract):
  class Fields:
    amount: Amount
  @guarantee
  def spend(self):
    t = TransactionTemplate()
    b_timeout = self.props.new("b")
    c_timeout = self.props.new("c")
    t.add_output(self.amount//2, B(timeout = b_timeout))
    assert b_timeout.get() >= c_timeout.get() + 2 weeks
  @guarantee
   def spend2(self)
    t = TransactionTemplate()
    c_timeout = self.props.new("c")
    b_timeout = self.props.new("b")
    t.add_output(self.amount//2, C(timeout = c_timeout))
    assert b_timeout.get() >= c_timeout.get() + 2 weeks

It is now possible for some scheduler to run this to completion, but naively it will fail to compile (spend will fail at c_timeout.get()).

Another option for prop passing is to give child contracts a Props field for computed values. E.g.,

class A:
  class Fields: pass
  class Props:
    timeout: int
  @unlock
  def spend(self):
    self.props.set('timeout', 10)
    return SignedBy(...) & After(Weeks(10))

In sum, a lot is already possible in the language with no further support, but we want to set up the use patterns and give examples of how to do this kind of stuff nicely, and add new features where it's going to permit better contract writing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.