Skip to content

Commit

Permalink
Bump libwally-core to 0.8.6
Browse files Browse the repository at this point in the history
The secp256k1-zkp submodule at CLibWally/libwally-core/src/secp256k1 is updated along with libwally-core. In build-libwally.sh script we switch back to a vanilla  libwally at the same commit that Bitcoin Core uses.

Although Bitcoin Core bumped that commit a few months ago, we don't change it here because secp256k1-zkp has not yet been rebased on it.

There were two breaking change in libwally-core:

1. wally_psbt_from_bytes got an additional FLAGS argument in 0fb94751def8b2c767680e2428ebe2fdabd436c7 (ElementsProject/libwally-core#336): trivially fixed by setting it to 0

2. wally_psbt_output no longer has a witness_script field as of 8f8481a3c509fc4a02425db3839f92594e6ea852  (ElementsProject/libwally-core#330). This required a more tedious workaround.
  • Loading branch information
Sjors committed Nov 25, 2022
1 parent 59dd96c commit d7c12bc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CLibWally/libwally-core
Submodule libwally-core updated 73 files
+4 −0 .gitignore
+28 −0 CHANGES.md
+3 −3 README.md
+2 −2 configure.ac
+2 −1 docs/requirements.txt
+28 −8 docs/source/conf.py
+1 −0 docs/source/index.rst
+982 −75 include/wally.hpp
+6 −6 include/wally_bip32.h
+124 −0 include/wally_crypto.h
+172 −41 include/wally_elements.h
+437 −0 include/wally_map.h
+1,775 −481 include/wally_psbt.h
+226 −0 include/wally_psbt_members.h
+1 −0 include/wally_script.h
+4 −2 include/wally_transaction.h
+3 −3 setup.py
+4 −1 src/Makefile.am
+0 −1 src/address.c
+0 −1 src/aes.c
+0 −1 src/anti_exfil.c
+6 −16 src/bip32.c
+0 −1 src/bip38.c
+1 −1 src/ccan/ccan/crypto/ripemd160/ripemd160.c
+1 −1 src/ccan/ccan/crypto/sha256/sha256.c
+1 −1 src/ccan/ccan/crypto/sha512/sha512.c
+659 −349 src/ctest/psbts.h
+45 −22 src/ctest/test_psbt.c
+20 −10 src/ctest/test_psbt_limits.c
+1,128 −180 src/data/psbt.json
+0 −6 src/data/pset.json
+4 −5 src/ecdh.c
+218 −48 src/elements.c
+0 −1 src/hmac.c
+1 −1 src/hmac.inl
+110 −12 src/internal.c
+37 −1 src/internal.h
+611 −0 src/map.c
+1 −1 src/pbkdf2.inl
+3,760 −1,483 src/psbt.c
+0 −133 src/psbt_int.h
+289 −0 src/psbt_io.h
+0 −1 src/pullpush.c
+15 −19 src/script.c
+1 −1 src/secp256k1
+167 −1 src/sign.c
+116 −36 src/swig_java/jni_elements_extra.java_in
+33 −0 src/swig_java/jni_extra.java_in
+205 −44 src/swig_java/swig.i
+582 −148 src/swig_python/contrib/psbt.py
+50 −12 src/swig_python/python_extra.py_in
+12 −3 src/swig_python/swig.i
+0 −1 src/symmetric.c
+11 −11 src/test/test_bip32.py
+141 −5 src/test/test_elements.py
+264 −0 src/test/test_map.py
+257 −147 src/test/test_psbt.py
+0 −28 src/test/test_pset.py
+78 −1 src/test/test_sign.py
+776 −328 src/test/util.py
+183 −197 src/transaction.c
+0 −24 src/transaction_shared.h
+3 −3 src/wrap_js/cordovaplugin/yarn.lock
+1 −0 src/wrap_js/src/combined.c
+1 −0 src/wrap_js/windows_config/libsecp256k1-config.h
+35 −65 tools/android_helpers.sh
+3 −3 tools/build_android_libraries.sh
+1 −1 tools/build_js_bindings.sh
+32 −0 tools/build_psbt_ctests.py
+1 −1 tools/build_wasm.sh
+26 −13 tools/build_wrappers.py
+1 −1 tools/msvc/build.bat
+433 −2 tools/wasm_exports.sh
1 change: 1 addition & 0 deletions CLibWally/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module CLibWally {
header "libwally-core/include/wally_bip38.h"
header "libwally-core/include/wally_bip39.h"
header "libwally-core/include/wally_psbt.h"
header "libwally-core/include/wally_psbt_members.h"
header "libwally-core/include/wally_script.h"
header "libwally-core/include/wally_transaction.h"
export *
Expand Down
33 changes: 25 additions & 8 deletions LibWally/PSBT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public struct PSBTOutput : Identifiable {
return self.txOutput.scriptPubKey.bytes.hexString + String(self.txOutput.amount)
}

init(_ wally_psbt_outputs: UnsafeMutablePointer<wally_psbt_output>, tx: wally_tx, index: Int, network: Network) {
init(_ wally_psbt: wally_psbt, _ wally_psbt_outputs: UnsafeMutablePointer<wally_psbt_output>, tx: wally_tx, index: Int, network: Network) {
precondition(index >= 0 && index < tx.num_outputs)
precondition(tx.num_outputs != 0 )
self.wally_psbt_output = wally_psbt_outputs[index]
Expand All @@ -107,11 +107,28 @@ public struct PSBTOutput : Identifiable {
self.origins = nil
}
let output = tx.outputs![index]
let scriptPubKey: ScriptPubKey
if let scriptPubKeyBytes = self.wally_psbt_output.witness_script {
scriptPubKey = ScriptPubKey(Data(bytes: scriptPubKeyBytes, count: self.wally_psbt_output.witness_script_len))
} else {
scriptPubKey = ScriptPubKey(Data(bytes: output.script, count: output.script_len))
// This is overriden with the witness script if found in the PSBT
var scriptPubKey = ScriptPubKey(Data(bytes: output.script, count: output.script_len))

let witnessScriptLen = UnsafeMutablePointer<Int>.allocate(capacity: 1)
let witnessScriptWritten = UnsafeMutablePointer<Int>.allocate(capacity: 1)
defer {
witnessScriptLen.deallocate()
witnessScriptWritten.deallocate()
}
// const struct wally_psbt *psbt, size_t index, size_t *written
var wally_psbt_tmp = wally_psbt // Copy to allow unsafe access
precondition(wally_psbt_get_output_witness_script_len(&wally_psbt_tmp, index, witnessScriptLen) == WALLY_OK)

if witnessScriptLen.pointee > 0 {
let witnessScriptBytes = UnsafeMutablePointer<UInt8>.allocate(capacity: witnessScriptLen.pointee)
defer {
witnessScriptBytes.deallocate()
}
precondition(wally_psbt_get_output_witness_script(&wally_psbt_tmp, index, witnessScriptBytes, witnessScriptLen.pointee, witnessScriptWritten) == WALLY_OK)

precondition(witnessScriptLen.pointee == witnessScriptWritten.pointee)
scriptPubKey = ScriptPubKey(Data(bytes: witnessScriptBytes, count: witnessScriptLen.pointee))
}

self.txOutput = TxOutput(tx_output: output, scriptPubKey: scriptPubKey, network: network)
Expand Down Expand Up @@ -263,7 +280,7 @@ public struct PSBT : Equatable {
wally_psbt.deallocate()
}
}
guard wally_psbt_from_bytes(psbt_bytes, psbt_bytes_len, &output) == WALLY_OK else {
guard wally_psbt_from_bytes(psbt_bytes, psbt_bytes_len, UInt32(0), &output) == WALLY_OK else {
// libwally-core returns WALLY_EINVAL regardless of why parsing fails
throw ParseError.invalid
}
Expand All @@ -277,7 +294,7 @@ public struct PSBT : Equatable {
self.inputs = inputs
var outputs: [PSBTOutput] = []
for i in 0..<self.wally_psbt.outputs_allocation_len {
outputs.append(PSBTOutput(self.wally_psbt.outputs, tx: self.wally_psbt.tx!.pointee, index: i, network: network))
outputs.append(PSBTOutput(self.wally_psbt, self.wally_psbt.outputs, tx: self.wally_psbt.tx!.pointee, index: i, network: network))
}
self.outputs = outputs
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Opinionated Swift wrapper around [LibWally](https://github.com/ElementsProject/libwally-core),
a collection of useful primitives for cryptocurrency wallets.

Supports a minimal set of features based on v0.8.5. See also [original docs](https://wally.readthedocs.io/en/release_0.8.5).
Supports a minimal set of features based on v0.8.6. See also [original docs](https://wally.readthedocs.io/en/release_0.8.6).

- [ ] Core Functions
- [x] base58 encode / decode
Expand Down

0 comments on commit d7c12bc

Please sign in to comment.