Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/addresstype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in)
CSHA256().Write(in.data(), in.size()).Finalize(begin());
}

WitnessV2P2TSH::WitnessV2P2TSH(const CScript& in)
WitnessV2P2MR::WitnessV2P2MR(const CScript& in)
{
CSHA256().Write(in.data(), in.size()).Finalize(begin());
}
Expand Down Expand Up @@ -92,10 +92,10 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
addressRet = tap;
return true;
}
case TxoutType::WITNESS_V2_P2TSH: {
WitnessV2P2TSH p2tsh;
std::copy(vSolutions[0].begin(), vSolutions[0].end(), p2tsh.begin());
addressRet = p2tsh;
case TxoutType::WITNESS_V2_P2MR: {
WitnessV2P2MR p2mr;
std::copy(vSolutions[0].begin(), vSolutions[0].end(), p2mr.begin());
addressRet = p2mr;
return true;
}
case TxoutType::ANCHOR: {
Expand Down Expand Up @@ -159,9 +159,9 @@ class CScriptVisitor
return CScript() << CScript::EncodeOP_N(id.GetWitnessVersion()) << id.GetWitnessProgram();
}

CScript operator()(const WitnessV2P2TSH& id) const
CScript operator()(const WitnessV2P2MR& id) const
{
// P2TSH is version 2
// P2MR is version 2
return CScript() << CScript::EncodeOP_N(2) << ToByteVector(id);
}
};
Expand All @@ -177,7 +177,7 @@ class ValidDestinationVisitor
bool operator()(const WitnessV0ScriptHash& dest) const { return true; }
bool operator()(const WitnessV1Taproot& dest) const { return true; }
bool operator()(const WitnessUnknown& dest) const { return true; }
bool operator()(const WitnessV2P2TSH& dest) const { return true; }
bool operator()(const WitnessV2P2MR& dest) const { return true; }
};
} // namespace

Expand Down
12 changes: 6 additions & 6 deletions src/addresstype.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ struct WitnessV1Taproot : public XOnlyPubKey
explicit WitnessV1Taproot(const XOnlyPubKey& xpk) : XOnlyPubKey(xpk) {}
};

struct WitnessV2P2TSH : public BaseHash<uint256>
struct WitnessV2P2MR : public BaseHash<uint256>
{
WitnessV2P2TSH() : BaseHash() {}
explicit WitnessV2P2TSH(const uint256& hash) : BaseHash(hash) {}
explicit WitnessV2P2TSH(const CScript& script);
WitnessV2P2MR() : BaseHash() {}
explicit WitnessV2P2MR(const uint256& hash) : BaseHash(hash) {}
explicit WitnessV2P2MR(const CScript& script);
};

//! CTxDestination subtype to encode any future Witness version
Expand Down Expand Up @@ -145,10 +145,10 @@ struct PayToAnchor : public WitnessUnknown
* * WitnessV1Taproot: TxoutType::WITNESS_V1_TAPROOT destination (P2TR address)
* * PayToAnchor: TxoutType::ANCHOR destination (P2A address)
* * WitnessUnknown: TxoutType::WITNESS_UNKNOWN destination (P2W??? address)
* * WitnessV2P2TSH: TxoutType::WITNESS_V2_P2TSH destination (P2TSH address)
* * WitnessV2P2MR: TxoutType::WITNESS_V2_P2MR destination (P2MR address)
* A CTxDestination is the internal data type encoded in a bitcoin address
*/
using CTxDestination = std::variant<CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown, WitnessV2P2TSH>;
using CTxDestination = std::variant<CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown, WitnessV2P2MR>;

/** Check whether a CTxDestination corresponds to one with an address. */
bool IsValidDestination(const CTxDestination& dest);
Expand Down
14 changes: 7 additions & 7 deletions src/key_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DestinationEncoder
return bech32::Encode(bech32::Encoding::BECH32M, m_params.Bech32HRP(), data);
}

std::string operator()(const WitnessV2P2TSH& id) const
std::string operator()(const WitnessV2P2MR& id) const
{
std::vector<unsigned char> data = {2}; // Version 2
data.reserve(53); // Reserve space for the hash
Expand Down Expand Up @@ -189,13 +189,13 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par
return tap;
}

if (version == 2 && data.size() == WITNESS_V2_P2TSH_SIZE) {
WitnessV2P2TSH tsh;
if (data.size() == tsh.size()) {
std::copy(data.begin(), data.end(), tsh.begin());
return tsh;
if (version == 2 && data.size() == WITNESS_V2_P2MR_SIZE) {
WitnessV2P2MR tmr;
if (data.size() == tmr.size()) {
std::copy(data.begin(), data.end(), tmr.begin());
return tmr;
}
error_str = strprintf("Invalid P2TSH address program size (%d %s)", data.size(), byte_str);
error_str = strprintf("Invalid P2MR address program size (%d %s)", data.size(), byte_str);
return CNoDestination();
}

Expand Down
77 changes: 17 additions & 60 deletions src/libbitcoinpqc/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
name: Rust CI
name: C CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Test
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -21,25 +18,17 @@ jobs:
sudo apt-get update
sudo apt-get install -y build-essential cmake libssl-dev
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt

- name: Cache dependencies
uses: Swatinem/rust-cache@v2

- name: Check code format
run: cargo fmt -- --check

- name: Clippy
run: cargo clippy -- -D warnings
- name: Configure
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON
- name: Build
run: cargo build --verbose
run: cmake --build build --verbose

- name: Run tests
run: cargo test --verbose
run: cd build && ctest -V

build-matrix:
name: Build on ${{ matrix.os }}
Expand All @@ -48,7 +37,6 @@ jobs:
matrix:
os: [ubuntu-latest]
# os: [ubuntu-latest, macos-latest]
rust: [stable]
fail-fast: false
steps:
- uses: actions/checkout@v3
Expand All @@ -64,45 +52,14 @@ jobs:
run: |
brew install cmake
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
components: clippy, rustfmt

- name: Cache dependencies
uses: Swatinem/rust-cache@v2

- name: Check code format
run: cargo fmt -- --check

- name: Clippy
run: cargo clippy -- -D warnings
- name: Configure
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON
- name: Build
run: cargo build --verbose
run: cmake --build build --verbose

- name: Run tests
run: cargo test --verbose

# benchmark:
# name: Benchmark
# runs-on: ubuntu-latest
# needs: test
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# steps:
# - uses: actions/checkout@v3

# - name: Install dependencies
# run: |
# sudo apt-get update
# sudo apt-get install -y build-essential cmake libssl-dev

# - name: Install Rust
# uses: dtolnay/rust-toolchain@stable

# - name: Cache dependencies
# uses: Swatinem/rust-cache@v2

# - name: Run benchmarks
# run: cargo bench
run: cd build && ctest -V
8 changes: 0 additions & 8 deletions src/libbitcoinpqc/.gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
build/
dist/
*.o
benchmark_results.txt
__pycache__
python/build/
*.egg-info/
node_modules/
**.gcno
**.lcov
**/target/
tags
TAGS
rust-toolchain.toml
Cargo.lock
5 changes: 1 addition & 4 deletions src/libbitcoinpqc/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"rust-analyzer.cargo.features": ["ide"],
"editor.formatOnSave": true,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.extraArgs": ["--all-targets"]
"editor.formatOnSave": true
}
3 changes: 1 addition & 2 deletions src/libbitcoinpqc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ include_directories(

# Custom randombytes implementation
set(CUSTOM_RANDOMBYTES
dilithium/ref/randombytes_custom.c
sphincsplus/ref/randombytes_custom.c
src/randombytes_custom.c
)

# ML-DSA-44 (Dilithium) source files
Expand Down
Loading
Loading