Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that GetAddressUtxos only returns UTXOs for addresses we requested #1606

Open
str4d opened this issue Oct 14, 2024 · 0 comments
Open

Comments

@str4d
Copy link
Contributor

str4d commented Oct 14, 2024

override suspend fun fetchUtxos(
tAddresses: List<String>,
startHeight: BlockHeightUnsafe
): Flow<Response<GetAddressUtxosReplyUnsafe>> {
require(tAddresses.isNotEmpty() && tAddresses.all { it.isNotBlank() }) {
"${Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE_EMPTY} array of addresses contains invalid item." // NON-NLS
}
val getUtxosBuilder =
Service.GetAddressUtxosArg.newBuilder().apply {
addAllAddresses(tAddresses)
setStartHeight(startHeight.value)
}
val request = getUtxosBuilder.build()
return try {
requireChannel().createStub(streamingRequestTimeout)
.getAddressUtxosStream(request)
.map {
val response: Response<GetAddressUtxosReplyUnsafe> =
Response.Success(GetAddressUtxosReplyUnsafe.new(it))
response
}.catch {
val failure: Response.Failure<GetAddressUtxosReplyUnsafe> =
GrpcStatusResolver.resolveFailureFromStatus(it)
emit(failure)
}
} catch (e: StatusException) {
flowOf(GrpcStatusResolver.resolveFailureFromStatus(e))
}
}

This code passes tAddresses to lightwalletd, but does not check that the response from lightwalletd only contains addresses that were in tAddresses, which means any bugs in lightwalletd (or its backing node) would result in unexpected transparent addresses making their way into the wallet DB.

We should check that for each response, utxo.address exists in tAddresses. If we get a UTXO that doesn't match, we should log a warning containing the unexpected UTXO, and then skip it (not include it in the returned stream).

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

No branches or pull requests

1 participant