Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
too-many-arguments-threshold = 15
too-many-arguments-threshold = 20
5 changes: 4 additions & 1 deletion docs/samples/solver/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ fn build_coinbase(script_sig: Vec<u8>, script_pubkey: Vec<u8>, amount_duffs: &st
ScriptSigBuf::from_bytes(script_sig),
0xFFFF_FFFF,
)],
vec![TxOut::new(value, ScriptPubKeyBuf::from_bytes(script_pubkey))],
vec![TxOut::new(
value.to_signed().to_sat(),
ScriptPubKeyBuf::from_bytes(script_pubkey),
)],
0,
Vec::new(),
))
Expand Down
6 changes: 6 additions & 0 deletions maint/codeql/rust/lib/policy.qll
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ predicate isSecretType(TypeItem t) {
// The identifier a share is issued against is the participant's, known to every member of the
// quorum; only the scalar the share carries is secret.
"BlsShareId",
// A masternode's owner payouts and the shares of its collateral hold public scripts, key ids
// and amounts.
"PayoutShare",
"CollateralShare",
// A share's reward update holds a public script and signature.
"ProUpShareTx",
// Serde artifact to deserialize a tagged enum.
"__Seed"
]
Expand Down
108 changes: 107 additions & 1 deletion pkgs/primitives/corpus/assetlock.json5
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
//
// Asset lock vectors. Sections with a program were generated with the
// reference implementation (dashpay/dash v24.0.0-rc.3, 0364ed626e).
//
// To run a program, paste it at the end of the `evo_assetlocks_tests` suite
// in `src/test/evo_assetlocks_tests.cpp` at the specified revision, build it
// with `make -C src test/test_dash` and run
// `./src/test/test_dash --run_test=evo_assetlocks_tests/<name>`. The output
// should match the section.
//

{
"assetlock": {
// Block 0000000000000017863c74745bfd506478eac05e032e2d546fe5f003c7a20bea
Expand Down Expand Up @@ -260,5 +271,100 @@
]
}
}
}
},
/*
BOOST_AUTO_TEST_CASE(assetlock_check)
{
const bool is_v24_active{true};
const CScript p2pkh{GetScriptForDestination(PKHash{uint160{}})};
const CScript p2sh{GetScriptForDestination(ScriptHash{uint160{}})};
const CScript other{CScript() << OP_TRUE};
for (const auto& [version, credits] : std::vector<std::pair<uint8_t, std::vector<CTxOut>>>{
{1, {{1, p2pkh}}},
{1, {{0, p2pkh}}},
{1, {{-1, p2pkh}}},
{1, {{MAX_MONEY, p2pkh}}},
{1, {{MAX_MONEY + 1, p2pkh}}},
{1, {{MAX_MONEY, p2pkh}, {1, p2pkh}}},
{1, {{1, p2pkh}, {-1, p2pkh}}},
{1, {{CAmount{0x7fffffffffffffff}, p2pkh}}},
{1, {{-CAmount{0x7fffffffffffffff} - 1, p2pkh}}},
{1, {{MAX_MONEY, p2pkh}, {CAmount{0x7fffffffffffffff}, p2pkh}}},
{0, {{1, p2pkh}}},
{2, {{1, p2pkh}}},
{3, {{1, p2pkh}}},
{1, {{1, p2sh}}},
{2, {{1, p2sh}}},
{1, {{1, other}}},
{2, {{1, other}}},
{2, {{1, p2pkh}, {1, p2sh}}},
{2, {{1, p2sh}, {1, other}}},
{2, {{0, other}}},
}) {
CAmount total{0};
for (const CTxOut& credit : credits) {
if (MoneyRange(credit.nValue)) total += credit.nValue;
}
CMutableTransaction tx;
tx.nVersion = 3;
tx.nType = TRANSACTION_ASSET_LOCK;
tx.vout.emplace_back(total > 0 && MoneyRange(total) ? total : 1, CScript() << OP_RETURN << ParseHex(""));
SetTxPayload(tx, CAssetLockPayload{credits, version});
TxValidationState state;
CheckAssetLockTx(CTransaction{tx}, state, is_v24_active);
std::printf(" { \"version\": %u, \"values\": [", version);
for (size_t i = 0; i < credits.size(); ++i) std::printf("%s%lld", i ? ", " : "", (long long)credits[i].nValue);
std::printf("], \"payload\": \"%s\", \"reason\": \"%s\" },\n", HexStr(tx.vExtraPayload).c_str(),
state.GetRejectReason().c_str());
}
}
*/
// Each vector is an asset lock payload of `version` with one credit output
// per value. `payload` is its serialization, which holds the credit
// scripts, and `reason` the rejection reason, empty when the payload
// passes. The transaction around it has an OP_RETURN output of the total
// of the credits in the money range, or of 1 when that total is 0 or out
// of range.
"check": [
// One credit of one duff passes.
{ "version": 1, "values": [1], "payload": "010101000000000000001976a914000000000000000000000000000000000000000088ac", "reason": "" },
// A zero credit is out of range.
{ "version": 1, "values": [0], "payload": "010100000000000000001976a914000000000000000000000000000000000000000088ac", "reason": "bad-assetlocktx-credit-outofrange" },
// A negative credit decodes and is out of range.
{ "version": 1, "values": [-1], "payload": "0101ffffffffffffffff1976a914000000000000000000000000000000000000000088ac", "reason": "bad-assetlocktx-credit-outofrange" },
// A credit of exactly the money range passes.
{ "version": 1, "values": [2100000000000000], "payload": "01010040075af07507001976a914000000000000000000000000000000000000000088ac", "reason": "" },
// A credit one duff above the money range.
{ "version": 1, "values": [2100000000000001], "payload": "01010140075af07507001976a914000000000000000000000000000000000000000088ac", "reason": "bad-assetlocktx-credit-outofrange" },
// Two credits in range whose total exceeds the money range.
{ "version": 1, "values": [2100000000000000, 1], "payload": "01020040075af07507001976a914000000000000000000000000000000000000000088ac01000000000000001976a914000000000000000000000000000000000000000088ac", "reason": "bad-assetlocktx-credit-outofrange" },
// A negative credit after a valid one.
{ "version": 1, "values": [1, -1], "payload": "010201000000000000001976a914000000000000000000000000000000000000000088acffffffffffffffff1976a914000000000000000000000000000000000000000088ac", "reason": "bad-assetlocktx-credit-outofrange" },
// The highest 64-bit credit is out of range.
{ "version": 1, "values": [9223372036854775807], "payload": "0101ffffffffffffff7f1976a914000000000000000000000000000000000000000088ac", "reason": "bad-assetlocktx-credit-outofrange" },
// The lowest 64-bit credit is out of range.
{ "version": 1, "values": [-9223372036854775808], "payload": "010100000000000000801976a914000000000000000000000000000000000000000088ac", "reason": "bad-assetlocktx-credit-outofrange" },
// The range check of a credit comes before it is added to the total.
{ "version": 1, "values": [2100000000000000, 9223372036854775807], "payload": "01020040075af07507001976a914000000000000000000000000000000000000000088acffffffffffffff7f1976a914000000000000000000000000000000000000000088ac", "reason": "bad-assetlocktx-credit-outofrange" },
// Version 0 is invalid.
{ "version": 0, "values": [1], "payload": "000101000000000000001976a914000000000000000000000000000000000000000088ac", "reason": "bad-assetlocktx-version" },
// Version 2, the current version, passes.
{ "version": 2, "values": [1], "payload": "020101000000000000001976a914000000000000000000000000000000000000000088ac", "reason": "" },
// Version 3 is above the current version.
{ "version": 3, "values": [1], "payload": "030101000000000000001976a914000000000000000000000000000000000000000088ac", "reason": "bad-assetlocktx-version" },
// Version 1 rejects a P2SH credit.
{ "version": 1, "values": [1], "payload": "0101010000000000000017a914000000000000000000000000000000000000000087", "reason": "bad-assetlocktx-pubKeyHash" },
// Version 2 accepts a P2SH credit.
{ "version": 2, "values": [1], "payload": "0201010000000000000017a914000000000000000000000000000000000000000087", "reason": "" },
// Version 1 rejects a credit that is neither P2PKH nor P2SH.
{ "version": 1, "values": [1], "payload": "010101000000000000000151", "reason": "bad-assetlocktx-pubKeyHash" },
// Version 2 rejects it with its own reason.
{ "version": 2, "values": [1], "payload": "020101000000000000000151", "reason": "bad-assetlocktx-script-pubkey" },
// Version 2 accepts P2PKH and P2SH credits together.
{ "version": 2, "values": [1, 1], "payload": "020201000000000000001976a914000000000000000000000000000000000000000088ac010000000000000017a914000000000000000000000000000000000000000087", "reason": "" },
// A bad script after a valid credit.
{ "version": 2, "values": [1, 1], "payload": "0202010000000000000017a91400000000000000000000000000000000000000008701000000000000000151", "reason": "bad-assetlocktx-script-pubkey" },
// The range check comes before the script check.
{ "version": 2, "values": [0], "payload": "020100000000000000000151", "reason": "bad-assetlocktx-credit-outofrange" },
],
}
Loading
Loading