partial revert of SIST in prep for h2 fork
What changed, and why it matters
This commit re-enables sending private Firo (Spark) funds to exchange addresses, which had been temporarily blocked. It also upgrades the wallet to support a newer Spark transaction format (Chaum V2) that allows multiple inputs, and it adds safety checks to prevent broadcasting insecure multi-input transactions using the older format. The change is described by the developer as a 'partial revert' ahead of a network fork, not as a security fix.
Treat this as a protocol-upgrade/refactoring change rather than an urgent vulnerability patch. Review the updated flutter_libsparkmobile commit for any native security fixes, verify that the Chaum V2 activation height matches the Firo network fork, and run integration tests for private Spark sends to exchange addresses and Spark name registrations.
Security signals we found
Re-enables previously disabled private Spark-to-exchange sends under the new Chaum V2 rules
Adds explicit guard: multi-input Spark transactions are rejected unless they use the Chaum V2 transaction version
Replaces raw spend version integers with a typed enum to reduce version-confusion bugs
Filters out all-zero txids when building the set of Spark input txids
Dependency bump for flutter_libsparkmobile, which may include corresponding native Spark library changes
Evidence from the diff
The patch removes temporary exceptions that blocked private Firo Spark sends to exchange addresses and replaces them with calls to prepareSendSpark() with requireChaumV2: true. It refactors Spark spend-version handling from raw integers to a LibSparkSpendVersion enum, distinguishes Chaum V1 (transaction type 9, single-input only) from Chaum V2 (type 11, multi-input allowed), and adds validation that refuses to broadcast multi-input transactions unless they use the Chaum V2 version. It also updates the flutter_libsparkmobile dependency to a newer commit and filters out zero/placeholder txids when collecting Spark input txids.
Changed components
Firo wallet Spark spend preparation (lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart)Firo wallet implementation (lib/wallets/wallet/impl/firo_wallet.dart)Exchange step 4 send flow (lib/pages/exchange_view/exchange_step_views/step_4_view.dart)Exchange send-from flow (lib/pages/exchange_view/send_from_view.dart)Generated/native libspark interface (lib/wl_gen/interfaces/lib_spark_interface.dart, tool/wl_templates/FIRO_lib_spark_interface_impl.template.dart)flutter_libsparkmobile git dependencyInspect captured patch +279 / −102
diff --git a/lib/pages/exchange_view/exchange_step_views/step_4_view.dart b/lib/pages/exchange_view/exchange_step_views/step_4_view.dart
index a48b85b..896feb7 100644
--- a/lib/pages/exchange_view/exchange_step_views/step_4_view.dart
+++ b/lib/pages/exchange_view/exchange_step_views/step_4_view.dart
@@ -288,9 +288,14 @@ class _Step4ViewState extends ConsumerState<Step4View> {
);
if (wallet is FiroWallet && !firoPublicSend) {
- throw Exception(
- "Sending private Firo funds to an exchange address is temporarily "
- "unavailable.",
+ txDataFuture = wallet.prepareSendSpark(
+ txData: TxData(
+ recipients: [recipient],
+ note:
+ "${model.trade!.payInCurrency.toUpperCase()}/"
+ "${model.trade!.payOutCurrency.toUpperCase()} exchange",
+ ),
+ requireChaumV2: true,
);
} else {
final memo = wallet.info.coin is Stellar
diff --git a/lib/pages/exchange_view/send_from_view.dart b/lib/pages/exchange_view/send_from_view.dart
index 1e3555c..9fe4121 100644
--- a/lib/pages/exchange_view/send_from_view.dart
+++ b/lib/pages/exchange_view/send_from_view.dart
@@ -293,6 +293,7 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
),
);
} else {
+ final firoWallet = wallet as FiroWallet;
// otherwise do firo send based on balance selected
if (shouldSendPublicFiroFunds) {
txDataFuture = wallet.prepareSend(
@@ -302,9 +303,21 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
),
);
} else {
- throw Exception(
- "Sending private Firo funds to an exchange address is "
- "temporarily unavailable.",
+ txDataFuture = firoWallet.prepareSendSpark(
+ txData: TxData(
+ recipients: recipient.addressType == .spark ? null : [recipient],
+ sparkRecipients: recipient.addressType == .spark
+ ? [
+ (
+ address: recipient.address,
+ amount: recipient.amount,
+ memo: "",
+ isChange: false,
+ ),
+ ]
+ : null,
+ ),
+ requireChaumV2: true,
);
}
}
diff --git a/lib/wallets/wallet/impl/firo_wallet.dart b/lib/wallets/wallet/impl/firo_wallet.dart
index 48970b5..34c68c2 100644
--- a/lib/wallets/wallet/impl/firo_wallet.dart
+++ b/lib/wallets/wallet/impl/firo_wallet.dart
@@ -95,6 +95,9 @@ class MasternodeInfo {
final kMasterNodeValue = Decimal.fromInt(1000); // full value (not sats)
+const _zeroTxid =
+ "0000000000000000000000000000000000000000000000000000000000000000";
+
class FiroWallet<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
with
ElectrumXInterface<T>,
@@ -278,7 +281,10 @@ class FiroWallet<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
final txid = map["txid"] as String?;
final vout = map["vout"] as int?;
- if (coinbase == null && txid != null && vout != null) {
+ if (coinbase == null &&
+ txid != null &&
+ vout != null &&
+ txid != _zeroTxid) {
txInputTxidsSet.add(txid);
}
}
@@ -992,7 +998,8 @@ class FiroWallet<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
).raw.toInt();
if (collateralUtxo.value != expectedCollateralRaw) {
throw Exception(
- "Collateral outpoint must be exactly ${kMasterNodeValue.toString()} FIRO.",
+ "Collateral outpoint must be exactly "
+ "${kMasterNodeValue.toString()} FIRO.",
);
}
diff --git a/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart b/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart
index f198786..193bb13 100644
--- a/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart
+++ b/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart
@@ -56,25 +56,33 @@ const OP_SPARKNAMEID = 0xe1;
const OP_DROP = 0x75;
const _maxSingleInputSparkTransactions = 50;
-const _sparkTxVersion = 3;
-const _transactionSpark = 9;
-const _transactionSparkV2 = 11;
const _sparkChaumV2ActivationHeight = 1371000;
@visibleForTesting
-({int transactionType, int spendVersion}) sparkH2ParametersForNextBlock({
+LibSparkSpendVersion sparkSpendVersionForNextBlock({
required CryptoCurrencyNetwork network,
required int nextBlockHeight,
}) {
- final useChaumV2 =
- network == CryptoCurrencyNetwork.main &&
- nextBlockHeight >= _sparkChaumV2ActivationHeight;
- return (
- transactionType: useChaumV2 ? _transactionSparkV2 : _transactionSpark,
- spendVersion: useChaumV2 ? 2 : 1,
+ if (network != .main) return .chaumV1;
+
+ return libSpark.getSpendVersionForBlockHeight(
+ nextBlockHeight: nextBlockHeight,
+ chaumV2ActivationHeight: _sparkChaumV2ActivationHeight,
);
}
+@visibleForTesting
+bool isChaumV2SparkTransactionVersion(int transactionVersion) =>
+ transactionVersion == LibSparkSpendVersion.chaumV2.transactionVersion;
+
+LibSparkNameProofInput _sparkNameProofInput({
+ required LibSparkSpendVersion spendVersion,
+ required String inputHex,
+}) => switch (spendVersion) {
+ .chaumV1 => .chaumV1(scalarHex: inputHex),
+ .chaumV2 => .chaumV2(ownershipDigest: inputHex),
+};
+
int _compareSparkCoinsForSingleInputSpend(SparkCoin a, SparkCoin b) {
int result = b.value.compareTo(a.value);
if (result != 0) return result;
@@ -519,6 +527,44 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
);
}
+ final root = await getRootHDNode();
+ final privateKey = root.derivePath(sparkDerivationPath).privateKey.data;
+ final chainTipHeight = await fetchChainHeight();
+ final spendVersion = sparkSpendVersionForNextBlock(
+ network: cryptoCurrency.network,
+ nextBlockHeight: chainTipHeight + 1,
+ );
+
+ if (spendVersion.allowsMultipleInputs) {
+ final serializedCoins = coins
+ .map(
+ (e) => (
+ serializedCoin: e.serializedCoinB64!,
+ serializedCoinContext: e.contextB64!,
+ groupId: e.groupId,
+ height: e.height!,
+ ),
+ )
+ .toList();
+ int estimate = await _asyncSparkFeesWrapper(
+ privateKeyHex: privateKey.toHex,
+ index: sparkIndex,
+ sendAmount: amount.raw.toInt(),
+ subtractFeeFromAmount: true,
+ serializedCoins: serializedCoins,
+ privateRecipientsCount: 1,
+ utxoNum: 0,
+ additionalTxSize: 0,
+ spendVersion: spendVersion,
+ );
+ if (estimate < 0) estimate = 0;
+
+ return Amount(
+ rawValue: BigInt.from(estimate),
+ fractionDigits: cryptoCurrency.fractionDigits,
+ );
+ }
+
final serializedCoins = [
(
serializedCoin: coins.first.serializedCoinB64!,
@@ -527,14 +573,6 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
height: coins.first.height!,
),
];
-
- final root = await getRootHDNode();
- final privateKey = root.derivePath(sparkDerivationPath).privateKey.data;
- final chainTipHeight = await fetchChainHeight();
- final spendVersion = sparkH2ParametersForNextBlock(
- network: cryptoCurrency.network,
- nextBlockHeight: chainTipHeight + 1,
- ).spendVersion;
BigInt singleInputFee = BigInt.from(
await _asyncSparkFeesWrapper(
privateKeyHex: privateKey.toHex,
@@ -580,7 +618,10 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
}
/// Spark to Spark/Transparent (spend) creation
- Future<TxData> prepareSendSpark({required TxData txData}) async {
+ Future<TxData> prepareSendSpark({
+ required TxData txData,
+ bool requireChaumV2 = false,
+ }) async {
if (isViewOnly) {
throw Exception("Spending is not supported for view only wallets");
}
@@ -595,6 +636,18 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
throw Exception("Recipient has invalid amount.");
}
+ final lockTime = await fetchChainHeight();
+ final spendVersion = sparkSpendVersionForNextBlock(
+ network: cryptoCurrency.network,
+ nextBlockHeight: lockTime + 1,
+ );
+ if (requireChaumV2 && !spendVersion.allowsMultipleInputs) {
+ throw Exception(
+ "Sending private Firo funds to an exchange address is temporarily "
+ "unavailable.",
+ );
+ }
+
final coins = await mainDB.isar.sparkCoins
.where()
.walletIdEqualToAnyLTagHash(walletId)
@@ -634,21 +687,26 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
.privateKey
.data
.toHex;
- final lockTime = await fetchChainHeight();
- final sparkParameters = sparkH2ParametersForNextBlock(
- network: cryptoCurrency.network,
- nextBlockHeight: lockTime + 1,
- );
+
+ if (spendVersion.allowsMultipleInputs) {
+ return _prepareSparkSpend(
+ txData: txData,
+ coins: coins,
+ subtractFeeFromAmount: isSendAll,
+ privateKeyHex: privateKeyHex,
+ lockTime: lockTime,
+ spendVersion: spendVersion,
+ );
+ }
if (txData.sparkNameInfo != null) {
- final spend = await _prepareSingleSparkSpend(
+ final spend = await _prepareSparkSpend(
txData: txData,
- coin: coins.first,
+ coins: [coins.first],
subtractFeeFromAmount: false,
privateKeyHex: privateKeyHex,
lockTime: lockTime,
- transactionType: sparkParameters.transactionType,
- spendVersion: sparkParameters.spendVersion,
+ spendVersion: spendVersion,
);
return spend.copyWith(sparkSpends: [spend]);
}
@@ -661,14 +719,13 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
);
}
- final spend = await _prepareSingleSparkSpend(
+ final spend = await _prepareSparkSpend(
txData: txData,
- coin: coins.single,
+ coins: [coins.single],
subtractFeeFromAmount: true,
privateKeyHex: privateKeyHex,
lockTime: lockTime,
- transactionType: sparkParameters.transactionType,
- spendVersion: sparkParameters.spendVersion,
+ spendVersion: spendVersion,
);
return spend.copyWith(sparkSpends: [spend]);
}
@@ -714,7 +771,7 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
privateRecipientsCount: privateRecipientCount,
utxoNum: transparentRecipientCount,
additionalTxSize: 0,
- spendVersion: sparkParameters.spendVersion,
+ spendVersion: spendVersion,
),
);
feeCache[key] = fee;
@@ -762,17 +819,16 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
}
}
- final spend = await _prepareSingleSparkSpend(
+ final spend = await _prepareSparkSpend(
txData: txData.copyWith(
recipients: batchTransparentRecipients,
sparkRecipients: batchPrivateRecipients,
),
- coin: coins[plan.coinIndex],
+ coins: [coins[plan.coinIndex]],
subtractFeeFromAmount: false,
privateKeyHex: privateKeyHex,
lockTime: lockTime,
- transactionType: sparkParameters.transactionType,
- spendVersion: sparkParameters.spendVersion,
+ spendVersion: spendVersion,
);
if (spend.fee?.raw != plan.fee) {
throw Exception("Spark transaction fee changed during creation.");
@@ -801,15 +857,17 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
);
}
- Future<TxData> _prepareSingleSparkSpend({
+ Future<TxData> _prepareSparkSpend({
required TxData txData,
- required SparkCoin coin,
+ required List<SparkCoin> coins,
required bool subtractFeeFromAmount,
required String privateKeyHex,
required int lockTime,
- required int transactionType,
- required int spendVersion,
+ required LibSparkSpendVersion spendVersion,
}) async {
+ if (coins.isEmpty) {
+ throw Exception("No spendable Spark coins found");
+ }
if (!(txData.recipients?.isNotEmpty == true ||
txData.sparkRecipients?.isNotEmpty == true)) {
throw Exception("No recipients provided.");
@@ -856,7 +914,6 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
);
final txAmount = transparentSumOut + sparkSumOut;
- final coins = [coin];
final isSendAll = subtractFeeFromAmount;
// prepare coin data for ffi
@@ -926,7 +983,7 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
final txb = btc.TransactionBuilder(network: _bitcoinDartNetwork);
txb.setLockTime(lockTime);
- txb.setVersion(_sparkTxVersion | (transactionType << 16));
+ txb.setVersion(spendVersion.transactionVersion);
List<TxRecipient>? recipientsWithFeeSubtracted;
List<({String address, Amount amount, String memo, bool isChange})>?
@@ -1069,8 +1126,10 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
sparkNameValidityBlocks: txData.sparkNameInfo!.validBlocks,
name: txData.sparkNameInfo!.name,
additionalInfo: txData.sparkNameInfo!.additionalInfo,
- ownershipDigest: extractedTx.getId(),
- spendVersion: spendVersion,
+ proofInput: _sparkNameProofInput(
+ spendVersion: spendVersion,
+ inputHex: extractedTx.getId(),
+ ),
privateKeyHex: privateKeyHex,
spendKeyIndex: sparkIndex,
diversifier: txData.sparkNameInfo!.sparkAddress.derivationIndex,
@@ -1080,11 +1139,12 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
);
}
- final extensionCommitment = spendVersion == 2 && noProofNameTxData != null
+ final extensionCommitment =
+ spendVersion == .chaumV2 && noProofNameTxData != null
? libSpark.getSparkNameCommitment(
serializedSparkNameData: noProofNameTxData.script,
)
- : Uint8List(32);
+ : null;
final spend = await computeWithLibSparkLogging(_createSparkSend, (
privateKeyHex: privateKeyHex,
@@ -1125,7 +1185,8 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
extensionCommitment: extensionCommitment,
));
- if (spend.usedCoins.length != 1) {
+ if (spend.usedCoins.isEmpty ||
+ (!spendVersion.allowsMultipleInputs && spend.usedCoins.length != 1)) {
throw Exception("Unable to create a single-input Spark transaction.");
}
@@ -1155,8 +1216,10 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
sparkNameValidityBlocks: txData.sparkNameInfo!.validBlocks,
name: txData.sparkNameInfo!.name,
additionalInfo: txData.sparkNameInfo!.additionalInfo,
- ownershipDigest: hash,
- spendVersion: spendVersion,
+ proofInput: _sparkNameProofInput(
+ spendVersion: spendVersion,
+ inputHex: hash,
+ ),
privateKeyHex: privateKeyHex,
spendKeyIndex: sparkIndex,
diversifier: txData.sparkNameInfo!.sparkAddress.derivationIndex,
@@ -1166,7 +1229,8 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
);
break;
} catch (e) {
- if (spendVersion == 2 || e.toString() != "Exception: hash fail") {
+ if (spendVersion == .chaumV2 ||
+ e.toString() != "Exception: hash fail") {
rethrow;
}
hashFailSafe++;
@@ -1236,7 +1300,8 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
);
}
}
- if (usedSparkCoins.length != 1) {
+ if (usedSparkCoins.isEmpty ||
+ (!spendVersion.allowsMultipleInputs && usedSparkCoins.length != 1)) {
throw Exception("Unable to create a single-input Spark transaction.");
}
@@ -1278,16 +1343,27 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
(e) =>
e.raw == null ||
e.usedSparkCoins == null ||
- e.usedSparkCoins!.length != 1,
+ e.usedSparkCoins!.isEmpty,
)) {
- throw Exception(
- "Refusing to broadcast a non-single-input Spark transaction.",
- );
+ throw Exception("Refusing to broadcast an invalid Spark transaction.");
+ }
+ for (final transaction in transactions) {
+ if (transaction.usedSparkCoins!.length > 1) {
+ final transactionVersion = btc.Transaction.fromHex(
+ transaction.raw!,
+ ).version;
+ if (!isChaumV2SparkTransactionVersion(transactionVersion)) {
+ throw Exception(
+ "Refusing to broadcast a multi-input Chaum V1 transaction.",
+ );
+ }
+ }
}
final coinIds = transactions
- .map((e) => e.usedSparkCoins!.single.lTagHash)
- .toSet();
- if (coinIds.length != transactions.length) {
+ .expand((e) => e.usedSparkCoins!)
+ .map((e) => e.lTagHash)
+ .toList(growable: false);
+ if (coinIds.toSet().length != coinIds.length) {
throw Exception(
"A Spark coin cannot be used by multiple transactions.",
);
@@ -1325,6 +1401,10 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
}
}
+ if (txData.sparkSpends == null) {
+ return confirmed.single;
+ }
+
return txData.copyWith(
txHash: confirmed.first.txHash,
txid: confirmed.first.txid,
@@ -2913,8 +2993,8 @@ _createSparkSend(
List<({int setId, Uint8List blockHash})> idAndBlockHashes,
Uint8List txHash,
int additionalTxSize,
- int spendVersion,
- Uint8List extensionCommitment,
+ LibSparkSpendVersion spendVersion,
+ Uint8List? extensionCommitment,
})
args,
) async {
@@ -2985,7 +3065,7 @@ Future<int> _asyncSparkFeesWrapper({
required int privateRecipientsCount,
required int utxoNum,
required int additionalTxSize,
- required int spendVersion,
+ required LibSparkSpendVersion spendVersion,
}) async {
return await computeWithLibSparkLogging(_estSparkFeeComputeFunc, (
privateKeyHex: privateKeyHex,
@@ -3010,7 +3090,7 @@ int _estSparkFeeComputeFunc(
int privateRecipientsCount,
int utxoNum,
int additionalTxSize,
- int spendVersion,
+ LibSparkSpendVersion spendVersion,
})
args,
) {
diff --git a/lib/wl_gen/interfaces/lib_spark_interface.dart b/lib/wl_gen/interfaces/lib_spark_interface.dart
index 44650b8..06ddf07 100644
--- a/lib/wl_gen/interfaces/lib_spark_interface.dart
+++ b/lib/wl_gen/interfaces/lib_spark_interface.dart
@@ -4,6 +4,34 @@ import 'package:logger/logger.dart';
export '../generated/lib_spark_interface_impl.dart';
+enum LibSparkSpendVersion {
+ chaumV1(transactionType: 9),
+ chaumV2(transactionType: 11);
+
+ const LibSparkSpendVersion({required this.transactionType});
+
+ static const int baseTransactionVersion = 3;
+ final int transactionType;
+
+ int get transactionVersion =>
+ baseTransactionVersion | (transactionType << 16);
+
+ bool get allowsMultipleInputs => this == chaumV2;
+}
+
+final class LibSparkNameProofInput {
+ const LibSparkNameProofInput.chaumV1({required String scalarHex})
+ : spendVersion = .chaumV1,
+ inputHex = scalarHex;
+
+ const LibSparkNameProofInput.chaumV2({required String ownershipDigest})
+ : spendVersion = .chaumV2,
+ inputHex = ownershipDigest;
+
+ final LibSparkSpendVersion spendVersion;
+ final String inputHex;
+}
+
abstract class LibSparkInterface {
const LibSparkInterface();
@@ -31,12 +59,16 @@ abstract class LibSparkInterface {
bool isTestNet = false,
});
+ LibSparkSpendVersion getSpendVersionForBlockHeight({
+ required int nextBlockHeight,
+ required int chaumV2ActivationHeight,
+ });
+
({Uint8List script, int size}) createSparkNameScript({
required int sparkNameValidityBlocks,
required String name,
required String additionalInfo,
- required String ownershipDigest,
- required int spendVersion,
+ required LibSparkNameProofInput proofInput,
required String privateKeyHex,
required int spendKeyIndex,
required int diversifier,
@@ -133,8 +165,8 @@ abstract class LibSparkInterface {
required List<({int setId, Uint8List blockHash})> idAndBlockHashes,
required Uint8List txHash,
required int additionalTxSize,
- required int spendVersion,
- required Uint8List extensionCommitment,
+ required LibSparkSpendVersion spendVersion,
+ Uint8List? extensionCommitment,
});
int estimateSparkFee({
@@ -154,7 +186,7 @@ abstract class LibSparkInterface {
required int privateRecipientsCount,
required int utxoNum,
required int additionalTxSize,
- required int spendVersion,
+ required LibSparkSpendVersion spendVersion,
});
}
diff --git a/pubspec.lock b/pubspec.lock
index a187d14..10c5f6f 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -1019,8 +1019,8 @@ packages:
dependency: "direct main"
description:
path: "."
- ref: c164f003f6ddb29837901f48e3c0f80073fbcd09
- resolved-ref: c164f003f6ddb29837901f48e3c0f80073fbcd09
+ ref: "1c902b020647302376275c454d01cc64cf9f8956"
+ resolved-ref: "1c902b020647302376275c454d01cc64cf9f8956"
url: "https://github.com/cypherstack/flutter_libsparkmobile.git"
source: git
version: "0.1.0"
diff --git a/scripts/app_config/templates/pubspec.template.yaml b/scripts/app_config/templates/pubspec.template.yaml
index b1ab0af..c566a1f 100644
--- a/scripts/app_config/templates/pubspec.template.yaml
+++ b/scripts/app_config/templates/pubspec.template.yaml
@@ -44,7 +44,7 @@ dependencies:
# flutter_libsparkmobile:
# git:
# url: https://github.com/cypherstack/flutter_libsparkmobile.git
-# ref: c164f003f6ddb29837901f48e3c0f80073fbcd09
+# ref: 1c902b020647302376275c454d01cc64cf9f8956
# %%END_ENABLE_FIRO%%
# %%ENABLE_EPIC%%
diff --git a/test/wallets/spark_name_fee_test.dart b/test/wallets/spark_name_fee_test.dart
index fc11c79..331cc6a 100644
--- a/test/wallets/spark_name_fee_test.dart
+++ b/test/wallets/spark_name_fee_test.dart
@@ -4,6 +4,7 @@ import 'package:flutter_libsparkmobile/flutter_libsparkmobile.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
+import 'package:stackwallet/wl_gen/interfaces/lib_spark_interface.dart';
void main() {
test('Spark Name validation rejects underscores before construction', () {
@@ -46,24 +47,26 @@ void main() {
group('Spark H2 activation', () {
test('mainnet uses V1 before the activation block', () {
- expect(
- sparkH2ParametersForNextBlock(
- network: CryptoCurrencyNetwork.main,
- nextBlockHeight: 1370999,
- ),
- (transactionType: 9, spendVersion: 1),
+ final version = sparkSpendVersionForNextBlock(
+ network: CryptoCurrencyNetwork.main,
+ nextBlockHeight: 1370999,
);
+
+ expect(version, LibSparkSpendVersion.chaumV1);
+ expect(version.allowsMultipleInputs, isFalse);
+ expect(version.transactionVersion, 3 | (9 << 16));
});
test('mainnet uses V2 at activation and later', () {
for (final nextBlockHeight in [1371000, 1371001]) {
- expect(
- sparkH2ParametersForNextBlock(
- network: CryptoCurrencyNetwork.main,
- nextBlockHeight: nextBlockHeight,
- ),
- (transactionType: 11, spendVersion: 2),
+ final version = sparkSpendVersionForNextBlock(
+ network: CryptoCurrencyNetwork.main,
+ nextBlockHeight: nextBlockHeight,
);
+
+ expect(version, LibSparkSpendVersion.chaumV2);
+ expect(version.allowsMultipleInputs, isTrue);
+ expect(version.transactionVersion, 3 | (11 << 16));
}
});
@@ -72,13 +75,28 @@ void main() {
(network) => network != CryptoCurrencyNetwork.main,
)) {
expect(
- sparkH2ParametersForNextBlock(
+ sparkSpendVersionForNextBlock(
network: network,
nextBlockHeight: 1371000,
),
- (transactionType: 9, spendVersion: 1),
+ LibSparkSpendVersion.chaumV1,
);
}
});
+
+ test('only the Chaum V2 transaction version permits multiple inputs', () {
+ expect(
+ isChaumV2SparkTransactionVersion(
+ LibSparkSpendVersion.chaumV1.transactionVersion,
+ ),
+ isFalse,
+ );
+ expect(
+ isChaumV2SparkTransactionVersion(
+ LibSparkSpendVersion.chaumV2.transactionVersion,
+ ),
+ isTrue,
+ );
+ });
});
}
diff --git a/tool/wl_templates/FIRO_lib_spark_interface_impl.template.dart b/tool/wl_templates/FIRO_lib_spark_interface_impl.template.dart
index 23b01b6..5408f11 100644
--- a/tool/wl_templates/FIRO_lib_spark_interface_impl.template.dart
+++ b/tool/wl_templates/FIRO_lib_spark_interface_impl.template.dart
@@ -96,13 +96,27 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
isTestNet: isTestNet,
);
+ @override
+ LibSparkSpendVersion getSpendVersionForBlockHeight({
+ required int nextBlockHeight,
+ required int chaumV2ActivationHeight,
+ }) {
+ final version = SparkSpendVersion.forBlockHeight(
+ nextBlockHeight: nextBlockHeight,
+ chaumV2ActivationHeight: chaumV2ActivationHeight,
+ );
+ return switch (version) {
+ .chaumV1 => .chaumV1,
+ .chaumV2 => .chaumV2,
+ };
+ }
+
@override
({Uint8List script, int size}) createSparkNameScript({
required int sparkNameValidityBlocks,
required String name,
required String additionalInfo,
- required String ownershipDigest,
- required int spendVersion,
+ required LibSparkNameProofInput proofInput,
required String privateKeyHex,
required int spendKeyIndex,
required int diversifier,
@@ -113,8 +127,10 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
sparkNameValidityBlocks: sparkNameValidityBlocks,
name: name,
additionalInfo: additionalInfo,
- ownershipDigest: ownershipDigest,
- spendVersion: spendVersion,
+ proofInput: switch (proofInput.spendVersion) {
+ .chaumV1 => .chaumV1(scalarHex: proofInput.inputHex),
+ .chaumV2 => .chaumV2(ownershipDigest: proofInput.inputHex),
+ },
privateKeyHex: privateKeyHex,
spendKeyIndex: spendKeyIndex,
diversifier: diversifier,
@@ -297,8 +313,8 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
required List<({Uint8List blockHash, int setId})> idAndBlockHashes,
required Uint8List txHash,
required int additionalTxSize,
- required int spendVersion,
- required Uint8List extensionCommitment,
+ required LibSparkSpendVersion spendVersion,
+ Uint8List? extensionCommitment,
}) => LibSpark.createSparkSendTransaction(
index: index,
privateKeyHex: privateKeyHex,
@@ -309,7 +325,10 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
idAndBlockHashes: idAndBlockHashes,
txHash: txHash,
additionalTxSize: additionalTxSize,
- spendVersion: spendVersion,
+ spendVersion: switch (spendVersion) {
+ .chaumV1 => .chaumV1,
+ .chaumV2 => .chaumV2,
+ },
extensionCommitment: extensionCommitment,
);
@@ -331,7 +350,7 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
required int privateRecipientsCount,
required int utxoNum,
required int additionalTxSize,
- required int spendVersion,
+ required LibSparkSpendVersion spendVersion,
}) => LibSpark.estimateSparkFee(
privateKeyHex: privateKeyHex,
sendAmount: sendAmount,
@@ -340,7 +359,10 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
privateRecipientsCount: privateRecipientsCount,
utxoNum: utxoNum,
additionalTxSize: additionalTxSize,
- spendVersion: spendVersion,
+ spendVersion: switch (spendVersion) {
+ .chaumV1 => .chaumV1,
+ .chaumV2 => .chaumV2,
+ },
index: index,
);
}
Why this scored 31/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.