flutter_libsparkmobile dependency update
What changed, and why it matters
This commit updates the Stack Wallet app's integration with the Firo Spark privacy library. It adds support for a new Spark transaction version ("H2" / Chaum V2) that activates on mainnet at block 1,371,000, while keeping older behavior on test networks. The change is a dependency and protocol upgrade, not a clear security fix, but it touches sensitive code that creates private transactions and could affect whether coins are spendable after the network upgrade.
Treat this as a routine protocol-upgrade commit, but verify the upstream flutter_libsparkmobile changelog between 783bd00f and c164f00 for any security advisories. Confirm the activation height 1,371,000 matches the Firo network consensus and that the fallback to V1 on non-mainnet networks is intentional. Run the Spark transaction tests, especially around the activation boundary, before releasing.
Security signals we found
Dependency bump for a native/FFI crypto library (flutter_libsparkmobile) without visible release notes or CVE context
Hard-coded activation height (_sparkChaumV2ActivationHeight = 1371000) governs transaction version selection
Renamed parameter scalarHex -> ownershipDigest and added extensionCommitment suggest an underlying cryptographic protocol change
Non-mainnet networks are forced to V1; mainnet switches to V2 at the activation height
No explicit security claim, advisory, or bug description in commit message or diff
Evidence from the diff
The patch bumps the flutter_libsparkmobile dependency from commit 783bd00f to c164f00 and wires in new parameters required by that library: spendVersion, transactionType, ownershipDigest (renamed from scalarHex), and extensionCommitment. A new helper sparkH2ParametersForNextBlock() selects version 1/type 9 before block 1,371,000 on mainnet and version 2/type 11 at/after that height; non-mainnet networks stay on V1. The new getSparkNameCommitment() FFI call is used when spendVersion == 2. Tests are added for the activation logic. The diff is a feature/compat upgrade; there is no explicit bug fix or vulnerability remediation in the visible code.
Changed components
lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dartlib/wl_gen/interfaces/lib_spark_interface.darttool/wl_templates/FIRO_lib_spark_interface_impl.template.dartpubspec.lockscripts/app_config/templates/pubspec.template.yamltest/wallets/spark_name_fee_test.dartInspect captured patch +129 / −11
diff --git a/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart b/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart
index 0f71059..f198786 100644
--- a/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart
+++ b/lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart
@@ -56,6 +56,24 @@ 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({
+ required CryptoCurrencyNetwork network,
+ required int nextBlockHeight,
+}) {
+ final useChaumV2 =
+ network == CryptoCurrencyNetwork.main &&
+ nextBlockHeight >= _sparkChaumV2ActivationHeight;
+ return (
+ transactionType: useChaumV2 ? _transactionSparkV2 : _transactionSpark,
+ spendVersion: useChaumV2 ? 2 : 1,
+ );
+}
int _compareSparkCoinsForSingleInputSpend(SparkCoin a, SparkCoin b) {
int result = b.value.compareTo(a.value);
@@ -512,6 +530,11 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
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,
@@ -522,6 +545,7 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
privateRecipientsCount: 1,
utxoNum: 0,
additionalTxSize: 0,
+ spendVersion: spendVersion,
),
);
@@ -610,7 +634,11 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
.privateKey
.data
.toHex;
- final lockTime = await chainHeight;
+ final lockTime = await fetchChainHeight();
+ final sparkParameters = sparkH2ParametersForNextBlock(
+ network: cryptoCurrency.network,
+ nextBlockHeight: lockTime + 1,
+ );
if (txData.sparkNameInfo != null) {
final spend = await _prepareSingleSparkSpend(
@@ -619,6 +647,8 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
subtractFeeFromAmount: false,
privateKeyHex: privateKeyHex,
lockTime: lockTime,
+ transactionType: sparkParameters.transactionType,
+ spendVersion: sparkParameters.spendVersion,
);
return spend.copyWith(sparkSpends: [spend]);
}
@@ -637,6 +667,8 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
subtractFeeFromAmount: true,
privateKeyHex: privateKeyHex,
lockTime: lockTime,
+ transactionType: sparkParameters.transactionType,
+ spendVersion: sparkParameters.spendVersion,
);
return spend.copyWith(sparkSpends: [spend]);
}
@@ -682,6 +714,7 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
privateRecipientsCount: privateRecipientCount,
utxoNum: transparentRecipientCount,
additionalTxSize: 0,
+ spendVersion: sparkParameters.spendVersion,
),
);
feeCache[key] = fee;
@@ -738,6 +771,8 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
subtractFeeFromAmount: false,
privateKeyHex: privateKeyHex,
lockTime: lockTime,
+ transactionType: sparkParameters.transactionType,
+ spendVersion: sparkParameters.spendVersion,
);
if (spend.fee?.raw != plan.fee) {
throw Exception("Spark transaction fee changed during creation.");
@@ -772,6 +807,8 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
required bool subtractFeeFromAmount,
required String privateKeyHex,
required int lockTime,
+ required int transactionType,
+ required int spendVersion,
}) async {
if (!(txData.recipients?.isNotEmpty == true ||
txData.sparkRecipients?.isNotEmpty == true)) {
@@ -889,7 +926,7 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
final txb = btc.TransactionBuilder(network: _bitcoinDartNetwork);
txb.setLockTime(lockTime);
- txb.setVersion(3 | (9 << 16));
+ txb.setVersion(_sparkTxVersion | (transactionType << 16));
List<TxRecipient>? recipientsWithFeeSubtracted;
List<({String address, Amount amount, String memo, bool isChange})>?
@@ -910,6 +947,7 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
privateRecipientsCount: (txData.sparkRecipients?.length ?? 0),
utxoNum: recipientCount,
additionalTxSize: 0, // name script size
+ spendVersion: spendVersion,
);
estimatedFee = BigInt.from(estFee);
} else {
@@ -1031,7 +1069,8 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
sparkNameValidityBlocks: txData.sparkNameInfo!.validBlocks,
name: txData.sparkNameInfo!.name,
additionalInfo: txData.sparkNameInfo!.additionalInfo,
- scalarHex: extractedTx.getId(),
+ ownershipDigest: extractedTx.getId(),
+ spendVersion: spendVersion,
privateKeyHex: privateKeyHex,
spendKeyIndex: sparkIndex,
diversifier: txData.sparkNameInfo!.sparkAddress.derivationIndex,
@@ -1041,6 +1080,12 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
);
}
+ final extensionCommitment = spendVersion == 2 && noProofNameTxData != null
+ ? libSpark.getSparkNameCommitment(
+ serializedSparkNameData: noProofNameTxData.script,
+ )
+ : Uint8List(32);
+
final spend = await computeWithLibSparkLogging(_createSparkSend, (
privateKeyHex: privateKeyHex,
index: sparkIndex,
@@ -1076,6 +1121,8 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
additionalTxSize: txData.sparkNameInfo == null
? 0
: noProofNameTxData!.size + sparkNameFeeScriptSizeDelta,
+ spendVersion: spendVersion,
+ extensionCommitment: extensionCommitment,
));
if (spend.usedCoins.length != 1) {
@@ -1108,7 +1155,8 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
sparkNameValidityBlocks: txData.sparkNameInfo!.validBlocks,
name: txData.sparkNameInfo!.name,
additionalInfo: txData.sparkNameInfo!.additionalInfo,
- scalarHex: hash,
+ ownershipDigest: hash,
+ spendVersion: spendVersion,
privateKeyHex: privateKeyHex,
spendKeyIndex: sparkIndex,
diversifier: txData.sparkNameInfo!.sparkAddress.derivationIndex,
@@ -1118,7 +1166,7 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
);
break;
} catch (e) {
- if (e.toString() != "Exception: hash fail") {
+ if (spendVersion == 2 || e.toString() != "Exception: hash fail") {
rethrow;
}
hashFailSafe++;
@@ -2865,6 +2913,8 @@ _createSparkSend(
List<({int setId, Uint8List blockHash})> idAndBlockHashes,
Uint8List txHash,
int additionalTxSize,
+ int spendVersion,
+ Uint8List extensionCommitment,
})
args,
) async {
@@ -2878,6 +2928,8 @@ _createSparkSend(
idAndBlockHashes: args.idAndBlockHashes,
txHash: args.txHash,
additionalTxSize: args.additionalTxSize,
+ spendVersion: args.spendVersion,
+ extensionCommitment: args.extensionCommitment,
);
return spend;
@@ -2933,6 +2985,7 @@ Future<int> _asyncSparkFeesWrapper({
required int privateRecipientsCount,
required int utxoNum,
required int additionalTxSize,
+ required int spendVersion,
}) async {
return await computeWithLibSparkLogging(_estSparkFeeComputeFunc, (
privateKeyHex: privateKeyHex,
@@ -2943,6 +2996,7 @@ Future<int> _asyncSparkFeesWrapper({
privateRecipientsCount: privateRecipientsCount,
utxoNum: utxoNum,
additionalTxSize: additionalTxSize,
+ spendVersion: spendVersion,
));
}
@@ -2956,6 +3010,7 @@ int _estSparkFeeComputeFunc(
int privateRecipientsCount,
int utxoNum,
int additionalTxSize,
+ int spendVersion,
})
args,
) {
@@ -2968,6 +3023,7 @@ int _estSparkFeeComputeFunc(
privateRecipientsCount: args.privateRecipientsCount,
utxoNum: args.utxoNum,
additionalTxSize: args.additionalTxSize,
+ spendVersion: args.spendVersion,
);
return est;
diff --git a/lib/wl_gen/interfaces/lib_spark_interface.dart b/lib/wl_gen/interfaces/lib_spark_interface.dart
index 92404f5..44650b8 100644
--- a/lib/wl_gen/interfaces/lib_spark_interface.dart
+++ b/lib/wl_gen/interfaces/lib_spark_interface.dart
@@ -35,7 +35,8 @@ abstract class LibSparkInterface {
required int sparkNameValidityBlocks,
required String name,
required String additionalInfo,
- required String scalarHex,
+ required String ownershipDigest,
+ required int spendVersion,
required String privateKeyHex,
required int spendKeyIndex,
required int diversifier,
@@ -44,6 +45,10 @@ abstract class LibSparkInterface {
required bool ignoreProof,
});
+ Uint8List getSparkNameCommitment({
+ required Uint8List serializedSparkNameData,
+ });
+
List<({Uint8List scriptPubKey, int amount, bool subtractFeeFromAmount})>
createSparkMintRecipients({
required List<({String sparkAddress, int value, String memo})> outputs,
@@ -128,6 +133,8 @@ abstract class LibSparkInterface {
required List<({int setId, Uint8List blockHash})> idAndBlockHashes,
required Uint8List txHash,
required int additionalTxSize,
+ required int spendVersion,
+ required Uint8List extensionCommitment,
});
int estimateSparkFee({
@@ -147,6 +154,7 @@ abstract class LibSparkInterface {
required int privateRecipientsCount,
required int utxoNum,
required int additionalTxSize,
+ required int spendVersion,
});
}
diff --git a/pubspec.lock b/pubspec.lock
index 2c04213..a187d14 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -1019,8 +1019,8 @@ packages:
dependency: "direct main"
description:
path: "."
- ref: "783bd00f0114b007f7ef97017cd10ad263ed452c"
- resolved-ref: "783bd00f0114b007f7ef97017cd10ad263ed452c"
+ ref: c164f003f6ddb29837901f48e3c0f80073fbcd09
+ resolved-ref: c164f003f6ddb29837901f48e3c0f80073fbcd09
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 cd53bf1..b1ab0af 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: 783bd00f0114b007f7ef97017cd10ad263ed452c
+# ref: c164f003f6ddb29837901f48e3c0f80073fbcd09
# %%END_ENABLE_FIRO%%
# %%ENABLE_EPIC%%
diff --git a/test/wallets/spark_name_fee_test.dart b/test/wallets/spark_name_fee_test.dart
index 0608fa9..fc11c79 100644
--- a/test/wallets/spark_name_fee_test.dart
+++ b/test/wallets/spark_name_fee_test.dart
@@ -2,6 +2,7 @@ import 'dart:typed_data';
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';
void main() {
@@ -42,4 +43,42 @@ void main() {
isTrue,
);
});
+
+ group('Spark H2 activation', () {
+ test('mainnet uses V1 before the activation block', () {
+ expect(
+ sparkH2ParametersForNextBlock(
+ network: CryptoCurrencyNetwork.main,
+ nextBlockHeight: 1370999,
+ ),
+ (transactionType: 9, spendVersion: 1),
+ );
+ });
+
+ 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),
+ );
+ }
+ });
+
+ test('non-mainnet networks remain on V1', () {
+ for (final network in CryptoCurrencyNetwork.values.where(
+ (network) => network != CryptoCurrencyNetwork.main,
+ )) {
+ expect(
+ sparkH2ParametersForNextBlock(
+ network: network,
+ nextBlockHeight: 1371000,
+ ),
+ (transactionType: 9, spendVersion: 1),
+ );
+ }
+ });
+ });
}
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 f2998be..23b01b6 100644
--- a/tool/wl_templates/FIRO_lib_spark_interface_impl.template.dart
+++ b/tool/wl_templates/FIRO_lib_spark_interface_impl.template.dart
@@ -101,7 +101,8 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
required int sparkNameValidityBlocks,
required String name,
required String additionalInfo,
- required String scalarHex,
+ required String ownershipDigest,
+ required int spendVersion,
required String privateKeyHex,
required int spendKeyIndex,
required int diversifier,
@@ -112,7 +113,8 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
sparkNameValidityBlocks: sparkNameValidityBlocks,
name: name,
additionalInfo: additionalInfo,
- scalarHex: scalarHex,
+ ownershipDigest: ownershipDigest,
+ spendVersion: spendVersion,
privateKeyHex: privateKeyHex,
spendKeyIndex: spendKeyIndex,
diversifier: diversifier,
@@ -121,6 +123,13 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
ignoreProof: ignoreProof,
);
+ @override
+ Uint8List getSparkNameCommitment({
+ required Uint8List serializedSparkNameData,
+ }) => LibSpark.getSparkNameCommitment(
+ serializedSparkNameData: serializedSparkNameData,
+ );
+
@override
List<({int amount, Uint8List scriptPubKey, bool subtractFeeFromAmount})>
createSparkMintRecipients({
@@ -288,6 +297,8 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
required List<({Uint8List blockHash, int setId})> idAndBlockHashes,
required Uint8List txHash,
required int additionalTxSize,
+ required int spendVersion,
+ required Uint8List extensionCommitment,
}) => LibSpark.createSparkSendTransaction(
index: index,
privateKeyHex: privateKeyHex,
@@ -298,6 +309,8 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
idAndBlockHashes: idAndBlockHashes,
txHash: txHash,
additionalTxSize: additionalTxSize,
+ spendVersion: spendVersion,
+ extensionCommitment: extensionCommitment,
);
@override
@@ -318,6 +331,7 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
required int privateRecipientsCount,
required int utxoNum,
required int additionalTxSize,
+ required int spendVersion,
}) => LibSpark.estimateSparkFee(
privateKeyHex: privateKeyHex,
sendAmount: sendAmount,
@@ -326,6 +340,7 @@ class _LibSparkInterfaceImpl extends LibSparkInterface {
privateRecipientsCount: privateRecipientsCount,
utxoNum: utxoNum,
additionalTxSize: additionalTxSize,
+ spendVersion: spendVersion,
index: index,
);
}
Why this scored 23/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.