Skip to content

Conversation

@aguycalled
Copy link
Collaborator

@aguycalled aguycalled commented Jun 24, 2025

Add BLSCT Raw Transaction and Balance Proof RPC Methods

Summary

This PR adds six new RPC methods for handling BLSCT raw transactions and balance proofs, which are needed for BasicSwap integration; providing a complete workflow for creating, funding, signing, and decoding BLSCT transactions, as well as creating and verifying zero-knowledge balance proofs.
Also adds the getblsctrecoverydata RPC method for extracting recovery data from BLSCT transaction outputs.

New RPC Methods

BLSCT Raw Transaction Methods

1. createblsctrawtransaction

Creates an unsigned BLSCT transaction from specified inputs and outputs.

Parameters:

  • inputs (array): Array of input objects with txid, vout, and optional fields
  • outputs (array): Array of output objects with address, amount, and optional fields

Returns: Hex-encoded unsigned transaction

2. fundblsctrawtransaction

Adds inputs to a BLSCT transaction until it has enough value to cover outputs and fee.

Parameters:

  • hexstring (string): The hex string of the raw transaction
  • changeaddress (string, optional): The BLSCT address to receive change

Returns: Hex-encoded funded transaction

3. signblsctrawtransaction

Signs a BLSCT raw transaction by adding BLSCT signatures.

Parameters:

  • hexstring (string): The transaction hex string

Returns: Hex-encoded signed transaction

4. decodeblsctrawtransaction

Decodes a BLSCT raw transaction and returns a JSON object describing the transaction structure.

Parameters:

  • hexstring (string): The transaction hex string

Returns: JSON object with inputs, outputs, and fee information

BLSCT Balance Proof Methods

5. createblsctbalanceproof

Creates a zero-knowledge proof that the wallet has at least the specified balance.

Parameters:

  • amount (amount): The minimum balance to prove

Returns: JSON object with serialized balance proof

6. verifyblsctbalanceproof

Verifies a zero-knowledge balance proof.

Parameters:

  • proof (string): The serialized balance proof (hex string)

Returns: JSON object with validation result and minimum amount proven

BLSCT Recovery Data Methods

7. getblsctrecoverydata

Creates a zero-knowledge proof that the wallet has at least the specified balance.

Parameters:

  • txid_or_hex : The transaction id or raw transaction hex
  • vout (optional): The output index. If omitted, shows data for all outputs.

Returns: JSON object with the recovery data

Key Features

  • Complete Transaction Workflow: Create → Fund → Sign → Decode -> Recover
  • Zero-Knowledge Balance Proofs: Prove balance without revealing specific UTXOs
  • Proper Error Handling: Comprehensive validation and error messages
  • BLSCT-Specific: Designed specifically for BLSCT transactions and addresses
  • Wallet Integration: Automatically retrieves missing transaction data from wallet

Testing

Added comprehensive functional tests in test/functional/blsct_rawtransaction.py covering:

  • Basic functionality of all four raw transaction and the recovery data methods
  • Error handling for invalid inputs
  • Complete end-to-end workflow testing
  • Integration with existing BLSCT wallet functionality

Usage Examples

# Create a raw transaction
navio-cli createblsctrawtransaction '[{"txid":"abc123","vout":0}]' '[{"address":"navio1...","amount":0.1}]'

# Fund the transaction
navio-cli fundblsctrawtransaction "hexstring"

# Sign the transaction
navio-cli signblsctrawtransaction "hexstring"

# Decode a transaction
navio-cli decodeblsctrawtransaction "hexstring"

# Create a balance proof
navio-cli createblsctbalanceproof 1.0

# Verify a balance proof
navio-cli verifyblsctbalanceproof "proof_hex_string"

# Recover data from output
navio-cli getblsctrecoverydata "txhex" 1

Technical Details

  • Uses the new blsct::UnsignedTransaction class for transaction handling
  • Integrates with BLSCT wallet key management for signing
  • Leverages existing BLSCT recovery data for input validation
  • Implements proper serialization/deserialization for all data structures
  • Follows RPC conventions and error handling patterns

OP_BLSCHECKSIG Opcode Support

Added support for the OP_BLSCHECKSIG opcode, enabling BLS signature verification in transaction scripts:

  • New opcode: OP_BLSCHECKSIG for BLS signature verification
  • Signature checker integration: Updated TransactionSignatureChecker to handle BLS signatures, which works as a collector and delegates the verification logic to blsct::VerifyTx.

Technical implementation:

  • Added OP_BLSCHECKSIG case in src/script/interpreter.cpp
  • Implemented CheckBlsSignature method in GenericTransactionSignatureChecker
  • Fixed src/blsct/wallet/verification.cpp to properly handle BLS signature verification
  • Added comprehensive tests in src/test/blsct_signature_checker_tests.cpp

@aguycalled aguycalled requested review from gogoex and mxaddict July 9, 2025 19:04
gogoex
gogoex previously approved these changes Jul 12, 2025
Copy link
Collaborator

@gogoex gogoex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the high-level implementation of the newly added commands. If I'm not misunderstanding, specific_vout != -1 one should be fixed. Other ones are all minor.

@aguycalled aguycalled dismissed gogoex’s stale review July 12, 2025 19:34

The merge-base changed after approval.

@aguycalled aguycalled merged commit 53e7e2f into master Aug 14, 2025
6 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants