elements/src
Andrew Poelstra a3b7e71a3d
transaction: refuse to deserialize TxOuts with null values
In Bitcoin Core the notion of a "null" amount (and therefore a "null"
txout) is one which cannot be serialized or deserialized. In Core this
is implemented using a value of -1.

In Elements we use the CT notion of "nullness" which is that the flag on
the confidential value is 0. See d53479c9ff
which implemented this. This is reasonable, but because we don't have
checks on deserialization, we can deserialize objects that cannot be
reserialized.

In particular, in coins.h, we deserialize a coin by deserializing its
txout. When reserializing we assert that !out.IsNull(). This assertion
is hit by the `coins_deserialize` fuzztest.

There are a few potential fixes here:

* Remove the assertion from coins.h, which is there to catch logic bugs
  in Core, on the assumption that if they have no bugs then we don't
  either. This seems like a bad idea.
* Change "nullness" for amounts to be an encoding of -1, like in Core.
  This seems dangerous because we call `GetAmount` all over the place,
  and if this could return the -1 amount, this will likely blow
  something up. Probably this is safe for the same reason it is in Core
  -- that is, we never create null txouts except as sentinel values. But
  do you wanna bet that this is true now? That it'll always be true?
* Same as above, but assert that the amount is not null. This is safer
  than just blindly hoping that no overflows will occur but still not
  obviously safe.
* Refuse to deserialize null CT objects. This is impossible because we
  use null nonce values in txouts.
* Refuse to deserialize null CT values. Similarly, this is impossible
  because we use null values in null asset issuances, which are legal.
* Refused to deserialize CTxOuts with null values or assets.

We are going with the latter solution, because it is narrowly scoped,
does not increase the "crash surface" (we throw an exception, and we
already throw exceptions for other kinds of invalid serializations),
and is very unlikely to cause bugs (null values are invalid on the
network anyway; this is the first check in VerifyAmounts) (so are null
assets for that matter, which we maybe also should refuse to
deserialize).
2025-02-06 21:31:47 +00:00
..
bench CI: fix benchmark + QT tests by properly initializing CBlockIndex by calling SetNodeContext 2024-05-21 16:54:52 +00:00
common refactor: Fixup uint64_t-cast style in touched line 2022-02-01 11:19:18 +01:00
compat scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
config
consensus Add Simplicity Deployment structure 2024-10-07 14:39:10 -04:00
crc32c Update crc32c subtree 2021-09-29 14:10:29 +02:00
crypto Merge b304b65782 into merged_master (Bitcoin PR bitcoin/bitcoin#24359) 2023-06-30 17:50:25 +00:00
index Merge 5f44c5c428 into merged_master (Bitcoin PR bitcoin/bitcoin#24133) 2023-07-01 07:02:48 +00:00
init Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
interfaces Merge 848b11615b into merged_master (Bitcoin PR bitcoin/bitcoin#22834) 2023-07-03 09:33:46 +00:00
ipc refactor: Block unsafe fs::path std::string conversion calls 2021-10-05 11:10:47 -04:00
leveldb
logging scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
minisketch Update minisketch subtree to latest upstream 2022-02-04 22:47:49 +08:00
node fix: discountct package mining 2024-09-09 12:03:33 +02:00
policy discount: fix weight calculation 2024-09-25 15:18:38 +02:00
primitives transaction: refuse to deserialize TxOuts with null values 2025-02-06 21:31:47 +00:00
qt Use LBTC instead of L-BTC in QT 2024-11-04 05:54:22 -08:00
rpc amountfromvalue: add arg to check moneyrange 2025-01-17 13:09:10 +02:00
script Update to latest Simplicity 2025-02-04 12:14:25 -05:00
secp256k1 Fix extra changes in secp repo 2023-08-31 09:33:00 -07:00
simplicity Merge commit '3b60583dd2' into simplicity 2025-01-31 11:44:47 -05:00
support Use spans of std::byte in serialize 2022-01-02 11:40:31 +01:00
test Update to latest Simplicity 2025-02-04 12:14:25 -05:00
univalue Update univalue subtree to latest upstream 2021-10-11 20:45:56 +08:00
util Merge 3c565302aa into merged_master (Bitcoin PR bitcoin/bitcoin#24409) 2023-07-02 13:45:31 +00:00
wallet moneyrange: check asset type 2025-01-17 13:09:10 +02:00
zmq zmq: Fix implicit-integer-sign-change 2022-01-31 16:53:12 +01:00
.clang-format Use c++17 in clang-format 2021-11-12 11:46:34 +01:00
.clang-tidy Enable clang-tidy bugprone-argument-comment and fix violations 2021-09-07 09:11:10 +02:00
addrdb.cpp Merge bitcoin/bitcoin#24201: p2p: Avoid InitError when downgrading peers.dat 2022-02-25 08:45:11 +01:00
addrdb.h Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
addrman.cpp p2p: Avoid InitError when downgrading peers.dat 2022-02-25 09:53:10 +09:00
addrman.h p2p: Avoid InitError when downgrading peers.dat 2022-02-25 09:53:10 +09:00
addrman_impl.h test: Remove unused AddrManTest class 2021-12-28 21:54:51 +01:00
arith_uint256.cpp Fix implicit-integer-sign-change in arith_uint256 2022-01-13 15:56:59 +01:00
arith_uint256.h
asset.cpp Merge 12eda278ac into merged_master (Bitcoin PR bitcoin/bitcoin#23288) 2023-05-15 11:28:54 +00:00
asset.h moneyrange: check asset type 2025-01-17 13:09:10 +02:00
assetsdir.cpp
assetsdir.h
attributes.h
banman.cpp Fix race condition for SetBannedSetDirty() calls 2022-01-28 19:27:25 +00:00
banman.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
base58.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
base58.h
bech32.cpp Merge ee8c997125 into merged_master (Bitcoin PR bitcoin/bitcoin#24402) 2023-07-02 16:24:37 +00:00
bech32.h Merge 22feb7fee9 into merged_master (Bitcoin PR bitcoin/bitcoin#23577) 2023-06-02 08:34:54 +00:00
bitcoin-chainstate.cpp build: Add example bitcoin-chainstate executable 2022-02-14 14:53:46 -05:00
bitcoin-cli-res.rc Merge cabbd01d85 into merged_master (Bitcoin PR bitcoin/bitcoin#22724) 2023-04-10 10:20:20 +00:00
bitcoin-cli.cpp Merge 3c565302aa into merged_master (Bitcoin PR bitcoin/bitcoin#24409) 2023-07-02 13:45:31 +00:00
bitcoin-tx-res.rc Merge cabbd01d85 into merged_master (Bitcoin PR bitcoin/bitcoin#22724) 2023-04-10 10:20:20 +00:00
bitcoin-tx.cpp Merge 3c565302aa into merged_master (Bitcoin PR bitcoin/bitcoin#24409) 2023-07-02 13:45:31 +00:00
bitcoin-util-res.rc windres: use PACKAGE_VERSION rather than building more version numbers 2021-08-17 16:54:47 +08:00
bitcoin-util.cpp Output license info when binaries are passed -version 2022-02-22 15:36:19 +00:00
bitcoin-wallet-res.rc windres: use PACKAGE_VERSION rather than building more version numbers 2021-08-17 16:54:47 +08:00
bitcoin-wallet.cpp Merge 3c565302aa into merged_master (Bitcoin PR bitcoin/bitcoin#24409) 2023-07-02 13:45:31 +00:00
bitcoind-res.rc Merge cabbd01d85 into merged_master (Bitcoin PR bitcoin/bitcoin#22724) 2023-04-10 10:20:20 +00:00
bitcoind.cpp Merge 3c565302aa into merged_master (Bitcoin PR bitcoin/bitcoin#24409) 2023-07-02 13:45:31 +00:00
blech32.cpp blech32: add blech32m format and use it to decode witness v1+ addresses 2021-08-18 15:54:20 +00:00
blech32.h blech32: add blech32m format and use it to decode witness v1+ addresses 2021-08-18 15:54:20 +00:00
blind.cpp unblindconfidentialpair: update moneyrange check with asset 2025-01-17 13:09:11 +02:00
blind.h Linter fixes 2023-08-31 14:47:07 -07:00
blindpsbt.cpp elements: fixes for bitcoin/bitcoin#22976 2023-04-24 12:05:24 +00:00
blindpsbt.h Linter fixes 2023-08-31 14:47:07 -07:00
block_proof.cpp Refactor CBlockIndex to make proof and dynafed fields optional. 2022-12-12 09:46:04 -08:00
block_proof.h
blockencodings.cpp Merge 4a540683ec into merged_master (Bitcoin PR #20813) 2021-06-16 14:11:07 +00:00
blockencodings.h
blockfilter.cpp scripted-diff: rename MapIntoRange to FastRange64 2022-01-06 11:29:55 -05:00
blockfilter.h
chain.cpp CI: fix asan lock issues 2024-05-21 16:56:01 +00:00
chain.h Reload trimmed header from index instead of block, block may have been pruned 2024-05-21 05:34:30 +00:00
chainparams.cpp Accept by default discountct in liquidv1 2024-11-18 05:00:12 -08:00
chainparams.h discount: introduce config args 2024-05-14 19:03:17 +02:00
chainparamsbase.cpp Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
chainparamsbase.h liquidtestnet: Add chainparams 2022-09-08 19:01:27 +00:00
chainparamsseeds.h Merge b71a07778f into merged_master (Bitcoin PR bitcoin/bitcoin#24417) 2023-07-02 16:47:44 +00:00
checkqueue.h Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
clientversion.cpp Merge 3c565302aa into merged_master (Bitcoin PR bitcoin/bitcoin#24409) 2023-07-02 13:45:31 +00:00
clientversion.h refactor: shift CopyrightHolders() and LicenseInfo() to clientversion.cpp 2022-02-22 15:36:19 +00:00
coins.cpp build: fix additional ASAN issues in CI 2023-09-07 05:07:50 +00:00
coins.h Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
compat.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
compressor.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
compressor.h Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
confidential_validation.cpp
confidential_validation.h Merge 816e15ee81 into merged_master (Bitcoin PR bitcoin/bitcoin#22951) 2023-05-09 11:50:39 +00:00
core_io.h Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
core_memusage.h
core_read.cpp Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
core_write.cpp feat: add discountweight to TxToUniv 2024-09-20 14:39:13 +02:00
cuckoocache.h Add FastRange32 function and use it throughout the codebase 2022-01-07 13:37:47 -05:00
dbwrapper.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
dbwrapper.h Use spans of std::byte in serialize 2022-01-02 11:40:31 +01:00
deploymentinfo.cpp Add Simplicity Deployment structure 2024-10-07 14:39:10 -04:00
deploymentinfo.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
deploymentstatus.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
deploymentstatus.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
dummywallet.cpp Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
dynafed.cpp improve efficiency by gating locks with 2024-05-27 09:25:31 +00:00
dynafed.h Linter fixes 2023-08-31 14:47:07 -07:00
external_signer.cpp external_signer: improve fingerprint matching logic (stop on first match) 2021-08-24 11:30:09 +02:00
external_signer.h refactor: make ExternalSigner NetworkArg() and m_chain private 2021-06-16 10:48:58 +02:00
flatfile.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
flatfile.h
fs.cpp refactor: replace boost::filesystem with std::filesystem 2022-02-03 18:35:52 +08:00
fs.h util: Work around libstdc++ create_directories issue 2022-02-17 12:30:11 +01:00
hash.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
hash.h Merge 196b459920 into merged_master (Bitcoin PR bitcoin/bitcoin#23438) 2023-06-29 08:37:35 +00:00
httprpc.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
httprpc.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
httpserver.cpp Merge bitcoin/bitcoin#23607: rpc: Pass const char* to evhttp_connection_get_peer for new libevent 2022-01-13 18:35:25 +01:00
httpserver.h
i2p.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
i2p.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
indirectmap.h
init.cpp Update help text for "acceptdiscountct" 2024-11-18 05:00:12 -08:00
init.h refactor: shift CopyrightHolders() and LicenseInfo() to clientversion.cpp 2022-02-22 15:36:19 +00:00
issuance.cpp Merge 816e15ee81 into merged_master (Bitcoin PR bitcoin/bitcoin#22951) 2023-05-09 11:50:39 +00:00
issuance.h Merge 816e15ee81 into merged_master (Bitcoin PR bitcoin/bitcoin#22951) 2023-05-09 11:50:39 +00:00
key.cpp build: fix compilation warnings 2023-09-01 16:39:08 +02:00
key.h Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
key_io.cpp Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
key_io.h Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
logging.cpp refactor: replace boost::filesystem with std::filesystem 2022-02-03 18:35:52 +08:00
logging.h refactor: replace boost::filesystem with std::filesystem 2022-02-03 18:35:52 +08:00
mainchainrpc.cpp ci: remove unused param 2023-10-09 20:32:39 +00:00
mainchainrpc.h
Makefile.am link: add simplicity to bitcoin-chainstate binary 2024-10-08 13:03:02 +00:00
Makefile.bench.include Add Simplicity to the build system. 2024-10-07 14:39:09 -04:00
Makefile.crc32c.include build: remove support for weak linking getauxval() 2021-09-24 15:40:04 +08:00
Makefile.elementssimplicity.include Sanitize libsimplicity 2025-01-31 11:43:23 -05:00
Makefile.leveldb.include build: remove build stubs for external leveldb 2021-10-15 01:02:45 +00:00
Makefile.minisketch.include build: add minisketch build file and include it 2021-10-21 09:37:30 +08:00
Makefile.qt.include Add Simplicity to the build system. 2024-10-07 14:39:09 -04:00
Makefile.qt_locale.include qt: Pre-branch translation updates for 23.x 2022-02-28 16:59:56 +01:00
Makefile.qttest.include Add Simplicity to the build system. 2024-10-07 14:39:09 -04:00
Makefile.test.include Add Simplicity to the build system. 2024-10-07 14:39:09 -04:00
Makefile.test_fuzz.include scripted-diff: Rename libbitcoin_server.a to libbitcoin_node.a 2021-12-20 10:53:01 -05:00
Makefile.test_util.include scripted-diff: Rename libbitcoin_server.a to libbitcoin_node.a 2021-12-20 10:53:01 -05:00
Makefile.univalue.include Integrate univalue into our buildsystem 2021-10-11 20:46:25 +08:00
mapport.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
mapport.h
memusage.h
merkleblock.cpp
merkleblock.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
net.cpp net: fix GetListenPort() to derive the proper port 2022-03-02 15:42:37 +01:00
net.h Merge 30308cc380 into merged_master (Bitcoin PR bitcoin/bitcoin#20196) 2023-07-03 11:17:52 +00:00
net_permissions.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
net_permissions.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
net_processing.cpp Restore NODE_NETWORK functionality with trim_headers 2024-05-21 05:34:30 +00:00
net_processing.h Merge bitcoin/bitcoin#23706: rpc: getblockfrompeer followups 2022-01-25 18:48:41 +01:00
net_types.cpp net: Drop only invalid entries when reading banlist.json 2021-12-14 18:58:45 +01:00
net_types.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
netaddress.cpp net: remove unused CNetAddr::GetHash() 2022-02-11 15:21:52 +01:00
netaddress.h net: remove unused CNetAddr::GetHash() 2022-02-11 15:21:52 +01:00
netbase.cpp Merge bitcoin/bitcoin#23542: net: open p2p connections to nodes that listen on non-default ports 2022-03-02 09:33:03 +01:00
netbase.h Merge bitcoin/bitcoin#23542: net: open p2p connections to nodes that listen on non-default ports 2022-03-02 09:33:03 +01:00
netmessagemaker.h
noui.cpp
noui.h
outputtype.cpp Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
outputtype.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
pegins.cpp improve efficiency by gating locks with 2024-05-27 09:25:31 +00:00
pegins.h Merge 816e15ee81 into merged_master (Bitcoin PR bitcoin/bitcoin#22951) 2023-05-09 11:50:39 +00:00
pow.cpp
pow.h
prevector.h
protocol.cpp Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
protocol.h Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
psbt.cpp Merge 196b459920 into merged_master (Bitcoin PR bitcoin/bitcoin#23438) 2023-06-29 08:37:35 +00:00
psbt.h Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
pubkey.cpp pubkey: fix bug in VerifySchnorr introduced in merge of bitcoin/bitcoin#22448 in 09333e2aca 2023-11-03 20:50:42 +00:00
pubkey.h Merge 196b459920 into merged_master (Bitcoin PR bitcoin/bitcoin#23438) 2023-06-29 08:37:35 +00:00
random.cpp build: remove unneeded getentropy detection (HAVE_GETENTROPY) 2022-02-02 17:22:42 +01:00
random.h doc: Fix typos pointed out by lint-spelling 2022-01-30 08:59:10 -03:00
randomenv.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
randomenv.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
rest.cpp CI: fix asan lock issues 2024-05-21 16:56:01 +00:00
reverse_iterator.h
scheduler.cpp scripted-diff: rename m_cs_callbacks_pending -> m_callbacks_mutex 2022-01-14 13:25:23 +01:00
scheduler.h refactor: replace RecursiveMutex m_callbacks_mutex with Mutex 2022-01-14 13:27:41 +01:00
serialize.h Merge 196b459920 into merged_master (Bitcoin PR bitcoin/bitcoin#23438) 2023-06-29 08:37:35 +00:00
shutdown.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
shutdown.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
signet.cpp Merge 623745ca74 into merged_master (Bitcoin PR bitcoin/bitcoin#23912) 2023-06-14 15:44:11 +00:00
signet.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
span.h span: Add BytePtr helper 2022-01-02 11:13:40 +01:00
streams.h scripted-diff: Rename nReadPos to m_read_pos in streams.h 2022-02-09 17:21:04 +01:00
sync.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
sync.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
threadinterrupt.cpp
threadinterrupt.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
threadsafety.h
timedata.cpp timedata: rename variables to match the coding style 2022-03-02 15:40:35 +01:00
timedata.h timedata: make it possible to reset the state 2022-03-02 15:40:30 +01:00
tinyformat.h Use C++17 [[fallthrough]] attribute, and drop -Wno-implicit-fallthrough 2021-07-05 08:59:38 +03:00
torcontrol.cpp Merge bitcoin/bitcoin#22834: net: respect -onlynet= when making outbound connections 2022-03-01 18:32:01 +01:00
torcontrol.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
txdb.cpp CI: fix asan lock issues 2024-05-21 16:56:01 +00:00
txdb.h Extreme trimming on startup 2024-05-21 05:34:30 +00:00
txmempool.cpp discount: implement mempool logic 2024-05-14 19:03:36 +02:00
txmempool.h discount: implement mempool logic 2024-05-14 19:03:36 +02:00
txorphanage.cpp
txorphanage.h [net processing] Add Orphanage empty consistency check 2021-07-20 13:12:42 +01:00
txrequest.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
txrequest.h
uint256.cpp Merge 1ba24fe9b3 into merged_master (Elements PR ElementsProject/elements#1002) 2021-09-04 22:14:42 +00:00
uint256.h Merge 196b459920 into merged_master (Bitcoin PR bitcoin/bitcoin#23438) 2023-06-29 08:37:35 +00:00
undo.h
validation.cpp Add Simplicity Deployment structure 2024-10-07 14:39:10 -04:00
validation.h Allow untrimming headers when needed 2024-05-21 05:34:30 +00:00
validationinterface.cpp
validationinterface.h
version.h
versionbits.cpp Merge af0b578041 into merged_master (Bitcoin PR bitcoin/bitcoin#24187) 2023-06-30 16:06:00 +00:00
versionbits.h Merge d4e92d8436 into merged_master (Bitcoin PR bitcoin/bitcoin#23508) 2023-06-29 11:46:17 +00:00
walletinitinterface.h Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
warnings.cpp
warnings.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00