mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
Merge branch 'master' into elements-22-rc6
This commit is contained in:
commit
ddeb7b99d8
16 changed files with 429 additions and 33 deletions
|
|
@ -160,7 +160,7 @@ task:
|
|||
<< : *GLOBAL_TASK_TEMPLATE
|
||||
container:
|
||||
image: ubuntu:focal
|
||||
cpu: 4 # Increase CPU and memory to avoid timeout
|
||||
cpu: 8 # Increase CPU and memory to avoid timeout
|
||||
memory: 16G
|
||||
env:
|
||||
<< : *CIRRUS_EPHEMERAL_WORKER_TEMPLATE_ENV
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ This document assumes some familiarity with Bitcoin and Elements (UTXOs, [Script
|
|||
| Flags | Yes | 1 byte | `unsigned char` | | 1 if the transaction contains a witness, otherwise 0. All other values are invalid. |
|
||||
| Num Inputs | Yes | Varies | `VarInt` | | Number of inputs to the transaction. |
|
||||
| Inputs | Yes | Varies | `Vector<TxIn>` | | |
|
||||
| Num Inputs | Yes | Varies | `VarInt` | | Number of outputs from the transaction. |
|
||||
| Num Outputs | Yes | Varies | `VarInt` | | Number of outputs from the transaction. |
|
||||
| Outputs | Yes | Varies | `Vector<TxOut>` | | |
|
||||
| Locktime | Yes | 4 bytes | `uint32_t` | Little-endian | See [BIP 113](https://github.com/bitcoin/bips/blob/master/bip-0113.mediawiki). |
|
||||
| Witness | Only if flags is 1 | Varies | `Witness` | | See [BIP 141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki). Note that Elements witnesses contain more data than Bitcoin witnesses. This extra data is described further below. |
|
||||
|
|
@ -104,7 +104,7 @@ SegWit transactions have one such witness for each input.
|
|||
| Script Witness | Yes | Varies | `Vector<hex>` | | The vector represents the witness stack.<br>Can be empty (length of 0). |
|
||||
| Peg-in Witness | Yes | Varies | `Vector<hex>` | | The vector represents the witness stack.<br>Can be empty (length of 0). |
|
||||
|
||||
The range proofs must be empty if their asociated amounts (issuance / inflation keys) are explicit.
|
||||
The range proofs must be empty if their associated amounts (issuance / inflation keys) are explicit.
|
||||
Refer [here](https://elementsproject.org/features/confidential-transactions/investigation) for more details on range proofs.
|
||||
|
||||
A non-empty peg-in witness stack should always have a length of 6, and the items should be interpreted as follows:
|
||||
|
|
@ -203,13 +203,13 @@ Deserialization:
|
|||
| Input #2
|
||||
| 8d83eb1b0826f46d473003d041116927
|
||||
| 470e2ce0f7cc0c634a983d438d770ac8 ... Outpoint TXID: c80a778d433d984a630cccf7e02c0e4727691141d00330476df426081beb838d
|
||||
| 00000000 ........................... Outpoint index
|
||||
| 00000000 ........................... Outpoint index
|
||||
|
|
||||
| 00 ................................. ScriptSig length
|
||||
| | .................................. ScriptSig (empty)
|
||||
|
|
||||
| ffffffff ........................... Sequence number: UINT32_MAX
|
||||
|
||||
|
||||
02 ................................... Num Outputs
|
||||
|
|
||||
| Output #1
|
||||
|
|
@ -239,7 +239,7 @@ Deserialization:
|
|||
| 03 ................................. Nonce header (0x03 → compressed point)
|
||||
| 72fdd5c6e805a50d73ab15ec41cfaadc
|
||||
| be408ecc7a5867621918f1070f84ec95 ... Nonce x-coordinate (big-endian)
|
||||
|
|
||||
|
|
||||
| 16 ................................. ScriptPubKey length (0x16 = 22 bytes)
|
||||
| | 001424ae71d4804ca7dd1fa66486a8
|
||||
| | 7af9dff1663c84 ................... ScriptPubKey
|
||||
|
|
@ -317,18 +317,18 @@ Deserialization:
|
|||
| | .................................. ScriptSig (empty: segwit transaction)
|
||||
|
|
||||
| fdffffff ........................... Sequence number
|
||||
|
|
||||
|
|
||||
| .................................... Asset issuance
|
||||
| | 000000000000000000000000000000
|
||||
| | 000000000000000000000000000000
|
||||
| | 0000 ............................. Asset blinding nonce (0 for new asset issuance)
|
||||
| |
|
||||
| |
|
||||
| | 000000000000000000000000000000
|
||||
| | 000000000000000000000000000000
|
||||
| | 0000 ............................. Asset entropy
|
||||
| |
|
||||
| | 01 ............................... Amount header (0x01 → explicit, unblinded value)
|
||||
| | 00000000c4b20100 ................. Amount: 0xc4b20100 = 3,300,000,000 → 33 units (each divisible by 100,000,000)
|
||||
| | 00000000c4b20100 ................. Amount: 0xc4b20100 = 3,300,000,000 → 33 units (each divisible by 100,000,000)
|
||||
| |
|
||||
| | 01 ............................... Num inflation keys header (0x01 → explicit, unblinded value)
|
||||
| | 0000000029b92700 ................. Value. 0x29b92700 = 700,000,000 inflation keys
|
||||
|
|
@ -343,7 +343,7 @@ Deserialization:
|
|||
| 08 ................................. Amount header (0x08 → blinded value)
|
||||
| 66abe471dfadfb650825abe6f757860b
|
||||
| 6760d30ff62bc7c9ebd438608f45368b ... Amount x-coordinate (big-endian)
|
||||
|
|
||||
|
|
||||
| 02 ................................. Nonce header (0x02 → blinded value)
|
||||
| 115750003261bc64bb73d83401a91279
|
||||
| 6d0c0fb9d54c72751a7ca7a5149a9bdf ... Nonce x-coordinate (big-endian)
|
||||
|
|
@ -518,7 +518,7 @@ Deserialization:
|
|||
| 6d521c38ec1ea15734ae22b7c4606441
|
||||
| 2829c0d0579f0a713d1c04ede979026f ... Asset ID: 6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d
|
||||
|
|
||||
| 01 ................................. Amount header (0x01 → explicit, unblinded value)
|
||||
| 01 ................................. Amount header (0x01 → explicit, unblinded value)
|
||||
| 00000000002b09c1 ................... Amount: 0.02820545 L-BTC
|
||||
|
|
||||
| 00 ................................. Nonce header (0x00 → null)
|
||||
|
|
@ -532,7 +532,7 @@ Deserialization:
|
|||
| 6d521c38ec1ea15734ae22b7c4606441
|
||||
| 2829c0d0579f0a713d1c04ede979026f ... Asset ID: 6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d
|
||||
|
|
||||
| 01 ................................. Amount header (0x01 → explicit, unblinded value)
|
||||
| 01 ................................. Amount header (0x01 → explicit, unblinded value)
|
||||
| 0000000000000027 ................... Amount: 0.00000039 L-BTC
|
||||
|
|
||||
| 00 ................................. Nonce header (0x00 → null)
|
||||
|
|
@ -560,10 +560,10 @@ Deserialization:
|
|||
| | | f34227cbba1cf25eb0778aa45f8b
|
||||
| | | 7cb3495046 ..................... Stack item #2
|
||||
| 06 ................................. Peg-in witness stack length
|
||||
| | 08 ............................... Stack item #1 length
|
||||
| | 08 ............................... Stack item #1 length
|
||||
| | | e8092b0000000000 ............... Peg-in value (little-endian): 0x2b09e8 = 0.02820545 BTC)
|
||||
| | 20 ............................... Stack item #2 length (0x20 = 32)
|
||||
| | | 6d521c38ec1ea15734ae22b7c46064
|
||||
| | | 6d521c38ec1ea15734ae22b7c46064
|
||||
| | | 412829c0d0579f0a713d1c04ede979
|
||||
| | | 026f ........................... Asset ID: 6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d
|
||||
| | 20 ............................... Stack item #3 length (0x20 = 32)
|
||||
|
|
@ -592,4 +592,4 @@ Deserialization:
|
|||
| Output #2 witness
|
||||
| 00 ................................. Surjection proof length
|
||||
| 00 ................................. Range proof length
|
||||
```
|
||||
```
|
||||
|
|
|
|||
|
|
@ -255,6 +255,56 @@ The currently defined elements per-input proprietary types are as follows:
|
|||
|
|
||||
| 0
|
||||
| 2
|
||||
|-
|
||||
| Explicit Value
|
||||
| <tt>PSBT_ELEMENTS_IN_EXPLICIT_VALUE = 0x11</tt>
|
||||
| None
|
||||
| No key data
|
||||
| <tt><64-bit little endian int value></tt>
|
||||
| The explicit value for the input being spent. If provided, <tt>PSBT_ELEMENTS_IN_VALUE_PROOF</tt> must be provided too. Must not be provided if the input's value in the UTXO is already explicit.
|
||||
|
|
||||
| 0
|
||||
| 2
|
||||
|-
|
||||
| Explicit Value Proof
|
||||
| <tt>PSBT_ELEMENTS_IN_VALUE_PROOF = 0x12</tt>
|
||||
| None
|
||||
| No key data
|
||||
| <tt><rangeproof></tt>
|
||||
| An explicit value rangeproof that proves that the value commitment in this input's UTXO matches the explicit value in <tt>PSBT_ELEMENTS_IN_EXPLICIT_VALUE</tt>. If provided, <tt>PSBT_ELEMENTS_IN_EXPLICIT_VALUE</tt> must be provided too.
|
||||
|
|
||||
| 0
|
||||
| 2
|
||||
|-
|
||||
| Explicit Asset
|
||||
| <tt>PSBT_ELEMENTS_IN_EXPLICIT_ASSET = 0x13</tt>
|
||||
| None
|
||||
| No key data
|
||||
| <tt><32 byte asset tag></tt>
|
||||
| The explicit asset for the input being spent. If provided, <tt>PSBT_ELEMENTS_IN_ASSET_PROOF</tt> must be provided too. Must not be provided if the input's asset in the UTXO is already explicit.
|
||||
|
|
||||
| 0
|
||||
| 2
|
||||
|-
|
||||
| Explicit Asset Proof
|
||||
| <tt>PSBT_ELEMENTS_IN_ASSET_PROOF = 0x14</tt>
|
||||
| None
|
||||
| No key data
|
||||
| <tt><proof></tt>
|
||||
| An asset surjection proof with this input's asset as the only asset in the input set in order to prove that the asset commitment in the UTXO matches the explicit asset in <tt>PSBT_ELEMENTS_IN_EXPLICIT_ASSET</tt>. If provided, <tt>PSBT_ELEMENTS_IN_EXPLICIT_ASSET</tt> must be provided too.
|
||||
|
|
||||
| 0
|
||||
| 2
|
||||
|-
|
||||
| Blinded Issuance Flag
|
||||
| <tt>PSBT_ELEMENTS_IN_BLINDED_ISSUANCE = 0x15</tt>
|
||||
| None
|
||||
| No key data
|
||||
| <tt><1 byte boolean></tt>
|
||||
| A boolean flag. <tt>0x00</tt> indicates the issuance should not be blinded, <tt>0x01</tt> indicates it should be. If not specified, assumed to be <tt>0x01</tt>. Note that this does not indicate actual blinding status, but rather the expected blinding status prior to signing.
|
||||
|
|
||||
| 0
|
||||
| 2
|
||||
|}
|
||||
|
||||
The currently defined elements per-output proprietary types are as follows:
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ Var StartMenuGroup
|
|||
!insertmacro MUI_LANGUAGE English
|
||||
|
||||
# Installer attributes
|
||||
InstallDir $PROGRAMFILES64\Bitcoin
|
||||
InstallDir $PROGRAMFILES64\Elements
|
||||
CRCCheck on
|
||||
XPStyle on
|
||||
BrandingText " "
|
||||
|
|
@ -105,7 +105,7 @@ Section -post SEC0001
|
|||
WriteRegDWORD HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1
|
||||
WriteRegDWORD HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1
|
||||
WriteRegStr HKCR "@PACKAGE_TARNAME@" "URL Protocol" ""
|
||||
WriteRegStr HKCR "@PACKAGE_TARNAME@" "" "URL:Bitcoin"
|
||||
WriteRegStr HKCR "@PACKAGE_TARNAME@" "" "URL:Elements"
|
||||
WriteRegStr HKCR "@PACKAGE_TARNAME@\DefaultIcon" "" $INSTDIR\@BITCOIN_GUI_NAME@@EXEEXT@
|
||||
WriteRegStr HKCR "@PACKAGE_TARNAME@\shell\open\command" "" '"$INSTDIR\@BITCOIN_GUI_NAME@@EXEEXT@" "%1"'
|
||||
SectionEnd
|
||||
|
|
@ -138,7 +138,7 @@ Section -un.post UNSEC0001
|
|||
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk"
|
||||
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\$(^Name).lnk"
|
||||
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\@PACKAGE_NAME@ (testnet, 64-bit).lnk"
|
||||
Delete /REBOOTOK "$SMSTARTUP\Bitcoin.lnk"
|
||||
Delete /REBOOTOK "$SMSTARTUP\Elements.lnk"
|
||||
Delete /REBOOTOK $INSTDIR\uninstall.exe
|
||||
Delete /REBOOTOK $INSTDIR\debug.log
|
||||
Delete /REBOOTOK $INSTDIR\db.log
|
||||
|
|
|
|||
|
|
@ -220,6 +220,35 @@ BlindProofResult VerifyBlindProofs(const PSBTOutput& o) {
|
|||
return BlindProofResult::OK;
|
||||
}
|
||||
|
||||
BlindProofResult VerifyBlindProofs(const PSBTInput& i) {
|
||||
CTxOut utxo;
|
||||
if (!i.GetUTXO(utxo)) {
|
||||
return BlindProofResult::OK;
|
||||
}
|
||||
|
||||
if (i.m_explicit_value != std::nullopt) {
|
||||
if (i.m_value_proof.empty()) {
|
||||
return BlindProofResult::MISSING_VALUE_PROOF;
|
||||
} else if (!utxo.nValue.IsCommitment()) {
|
||||
return BlindProofResult::NOT_FULLY_BLINDED;
|
||||
} else if (!VerifyBlindValueProof(*i.m_explicit_value, utxo.nValue, i.m_value_proof, utxo.nAsset)) {
|
||||
return BlindProofResult::INVALID_VALUE_PROOF;
|
||||
}
|
||||
}
|
||||
|
||||
if (!i.m_explicit_asset.IsNull()) {
|
||||
if (i.m_asset_proof.empty()) {
|
||||
return BlindProofResult::MISSING_ASSET_PROOF;
|
||||
} else if (!utxo.nAsset.IsCommitment()) {
|
||||
return BlindProofResult::NOT_FULLY_BLINDED;
|
||||
} else if (!VerifyBlindAssetProof(i.m_explicit_asset, i.m_asset_proof, utxo.nAsset)) {
|
||||
return BlindProofResult::INVALID_ASSET_PROOF;
|
||||
}
|
||||
}
|
||||
|
||||
return BlindProofResult::OK;
|
||||
}
|
||||
|
||||
void CreateAssetCommitment(CConfidentialAsset& conf_asset, secp256k1_generator& asset_gen, const CAsset& asset, const uint256& asset_blinder)
|
||||
{
|
||||
conf_asset.vchCommitment.resize(CConfidentialAsset::nCommittedSize);
|
||||
|
|
@ -386,7 +415,8 @@ BlindingStatus BlindPSBT(PartiallySignedTransaction& psbt, std::map<uint32_t, st
|
|||
}
|
||||
|
||||
// Handle issuances
|
||||
if (input.m_issuance_value != std::nullopt || input.m_issuance_value_commitment.IsCommitment() || input.m_issuance_inflation_keys_amount != std::nullopt || input.m_issuance_inflation_keys_commitment.IsCommitment()) {
|
||||
if ((!input.m_blinded_issuance.has_value() || input.m_blinded_issuance.value()) &&
|
||||
(input.m_issuance_value != std::nullopt || input.m_issuance_value_commitment.IsCommitment() || input.m_issuance_inflation_keys_amount != std::nullopt || input.m_issuance_inflation_keys_commitment.IsCommitment())) {
|
||||
CAsset issuance_asset;
|
||||
CAsset reissuance_asset;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
struct PartiallySignedTransaction;
|
||||
struct PSBTOutput;
|
||||
struct PSBTInput;
|
||||
|
||||
enum class BlindingStatus
|
||||
{
|
||||
|
|
@ -52,5 +53,6 @@ BlindingStatus BlindPSBT(PartiallySignedTransaction& psbt, std::map<uint32_t, st
|
|||
bool VerifyBlindValueProof(CAmount value, const CConfidentialValue& conf_value, const std::vector<unsigned char>& proof, const CConfidentialAsset& conf_asset);
|
||||
bool VerifyBlindAssetProof(const uint256& asset, const std::vector<unsigned char>& proof, const CConfidentialAsset& conf_asset);
|
||||
BlindProofResult VerifyBlindProofs(const PSBTOutput& o);
|
||||
BlindProofResult VerifyBlindProofs(const PSBTInput& i);
|
||||
|
||||
#endif //BITCOIN_BLINDPSBT_H
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ void BlockAssembler::resetBlock()
|
|||
nFees = 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, std::chrono::seconds min_tx_age, DynaFedParamEntry* proposed_entry, CScript const* commit_script)
|
||||
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, std::chrono::seconds min_tx_age, DynaFedParamEntry* proposed_entry, const std::vector<CScript>* commit_scripts)
|
||||
{
|
||||
assert(min_tx_age >= std::chrono::seconds(0));
|
||||
int64_t nTimeStart = GetTimeMicros();
|
||||
|
|
@ -206,8 +206,10 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
|||
}
|
||||
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
||||
// Non-consensus commitment output before finishing coinbase transaction
|
||||
if (commit_script) {
|
||||
coinbaseTx.vout.insert(coinbaseTx.vout.begin(), CTxOut(policyAsset, 0, *commit_script));
|
||||
if (commit_scripts && !commit_scripts->empty()) {
|
||||
for (auto commit_script: *commit_scripts) {
|
||||
coinbaseTx.vout.insert(std::prev(coinbaseTx.vout.end()), CTxOut(policyAsset, 0, commit_script));
|
||||
}
|
||||
}
|
||||
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
|
||||
pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ public:
|
|||
explicit BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool, const CChainParams& params, const Options& options);
|
||||
|
||||
/** Construct a new block template with coinbase to scriptPubKeyIn */
|
||||
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn, std::chrono::seconds min_tx_age = std::chrono::seconds(0), DynaFedParamEntry* = nullptr, CScript const* commit_script = nullptr);
|
||||
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn, std::chrono::seconds min_tx_age = std::chrono::seconds(0), DynaFedParamEntry* = nullptr, const std::vector<CScript>* commit_scripts = nullptr);
|
||||
|
||||
inline static std::optional<int64_t> m_last_block_num_txs{};
|
||||
inline static std::optional<int64_t> m_last_block_weight{};
|
||||
|
|
|
|||
95
src/psbt.h
95
src/psbt.h
|
|
@ -73,6 +73,11 @@ static constexpr uint8_t PSBT_ELEMENTS_IN_ISSUANCE_ASSET_ENTROPY = 0x0d;
|
|||
static constexpr uint8_t PSBT_ELEMENTS_IN_UTXO_RANGEPROOF = 0x0e;
|
||||
static constexpr uint8_t PSBT_ELEMENTS_IN_ISSUANCE_BLIND_VALUE_PROOF = 0x0f;
|
||||
static constexpr uint8_t PSBT_ELEMENTS_IN_ISSUANCE_BLIND_INFLATION_KEYS_PROOF = 0x10;
|
||||
static constexpr uint8_t PSBT_ELEMENTS_IN_EXPLICIT_VALUE = 0x11;
|
||||
static constexpr uint8_t PSBT_ELEMENTS_IN_VALUE_PROOF = 0x12;
|
||||
static constexpr uint8_t PSBT_ELEMENTS_IN_EXPLICIT_ASSET = 0x13;
|
||||
static constexpr uint8_t PSBT_ELEMENTS_IN_ASSET_PROOF = 0x14;
|
||||
static constexpr uint8_t PSBT_ELEMENTS_IN_BLINDED_ISSUANCE = 0x15;
|
||||
|
||||
// Output types
|
||||
static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT = 0x00;
|
||||
|
|
@ -248,6 +253,7 @@ struct PSBTInput
|
|||
uint256 m_issuance_asset_entropy;
|
||||
std::vector<unsigned char> m_blind_issuance_value_proof;
|
||||
std::vector<unsigned char> m_blind_issuance_inflation_keys_proof;
|
||||
std::optional<bool> m_blinded_issuance;
|
||||
|
||||
// Peg-in
|
||||
std::variant<std::monostate, Sidechain::Bitcoin::CTransactionRef, CTransactionRef> m_peg_in_tx;
|
||||
|
|
@ -259,6 +265,10 @@ struct PSBTInput
|
|||
|
||||
// Auxiliary elements stuff
|
||||
std::vector<unsigned char> m_utxo_rangeproof;
|
||||
std::optional<CAmount> m_explicit_value;
|
||||
std::vector<unsigned char> m_value_proof;
|
||||
uint256 m_explicit_asset;
|
||||
std::vector<unsigned char> m_asset_proof;
|
||||
|
||||
bool IsNull() const;
|
||||
void FillSignatureData(SignatureData& sigdata) const;
|
||||
|
|
@ -473,6 +483,31 @@ struct PSBTInput
|
|||
SerializeToVector(s, CompactSizeWriter(PSBT_OUT_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_IN_ISSUANCE_BLIND_INFLATION_KEYS_PROOF));
|
||||
s << m_blind_issuance_inflation_keys_proof;
|
||||
}
|
||||
|
||||
// Explicit value and its proof
|
||||
if (m_explicit_value.has_value()) {
|
||||
SerializeToVector(s, CompactSizeWriter(PSBT_IN_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_IN_EXPLICIT_VALUE));
|
||||
SerializeToVector(s, m_explicit_value.value());
|
||||
}
|
||||
if (!m_value_proof.empty()) {
|
||||
SerializeToVector(s, CompactSizeWriter(PSBT_IN_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_IN_VALUE_PROOF));
|
||||
s << m_value_proof;
|
||||
}
|
||||
|
||||
// Explicit asset and its proof
|
||||
if (!m_explicit_asset.IsNull()) {
|
||||
SerializeToVector(s, CompactSizeWriter(PSBT_IN_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_IN_EXPLICIT_ASSET));
|
||||
SerializeToVector(s, m_explicit_asset);
|
||||
}
|
||||
if (!m_asset_proof.empty()) {
|
||||
SerializeToVector(s, CompactSizeWriter(PSBT_IN_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_IN_ASSET_PROOF));
|
||||
s << m_asset_proof;
|
||||
}
|
||||
|
||||
if (m_blinded_issuance.has_value()) {
|
||||
SerializeToVector(s, CompactSizeWriter(PSBT_IN_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_IN_BLINDED_ISSUANCE));
|
||||
SerializeToVector(s, *m_blinded_issuance);
|
||||
}
|
||||
}
|
||||
|
||||
// Write proprietary things
|
||||
|
|
@ -886,6 +921,60 @@ struct PSBTInput
|
|||
s >> m_blind_issuance_inflation_keys_proof;
|
||||
break;
|
||||
}
|
||||
case PSBT_ELEMENTS_IN_EXPLICIT_VALUE:
|
||||
{
|
||||
if (!key_lookup.emplace(key).second) {
|
||||
throw std::ios_base::failure("Duplicate Key, explicit value is already provided");
|
||||
} else if (subkey_len != 1) {
|
||||
throw std::ios_base::failure("Input explicit value is more than one byte type");
|
||||
}
|
||||
CAmount v;
|
||||
UnserializeFromVector(s, v);
|
||||
m_explicit_value = v;
|
||||
break;
|
||||
}
|
||||
case PSBT_ELEMENTS_IN_VALUE_PROOF:
|
||||
{
|
||||
if (!key_lookup.emplace(key).second) {
|
||||
throw std::ios_base::failure("Duplicate Key, explicit value proof is already provided");
|
||||
} else if (subkey_len != 1) {
|
||||
throw std::ios_base::failure("Input explicit value proof is more than one byte type");
|
||||
}
|
||||
s >> m_value_proof;
|
||||
break;
|
||||
}
|
||||
case PSBT_ELEMENTS_IN_EXPLICIT_ASSET:
|
||||
{
|
||||
if (!key_lookup.emplace(key).second) {
|
||||
throw std::ios_base::failure("Duplicate Key, explicit asset is already provided");
|
||||
} else if (subkey_len != 1) {
|
||||
throw std::ios_base::failure("Input explicit asset is more than one byte type");
|
||||
}
|
||||
UnserializeFromVector(s, m_explicit_asset);
|
||||
break;
|
||||
}
|
||||
case PSBT_ELEMENTS_IN_ASSET_PROOF:
|
||||
{
|
||||
if (!key_lookup.emplace(key).second) {
|
||||
throw std::ios_base::failure("Duplicate Key, explicit asset proof is already provided");
|
||||
} else if (subkey_len != 1) {
|
||||
throw std::ios_base::failure("Input explicit asset proof is more than one byte type");
|
||||
}
|
||||
s >> m_asset_proof;
|
||||
break;
|
||||
}
|
||||
case PSBT_ELEMENTS_IN_BLINDED_ISSUANCE:
|
||||
{
|
||||
if (!key_lookup.emplace(key).second) {
|
||||
throw std::ios_base::failure("Duplicate Key, issuance needs blinded flag is already provided");
|
||||
} else if (subkey_len != 1) {
|
||||
throw std::ios_base::failure("Input issuance needs blinded flag is more than one byte type");
|
||||
}
|
||||
bool b;
|
||||
UnserializeFromVector(s, b);
|
||||
m_blinded_issuance = b;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
known = false;
|
||||
|
|
@ -936,6 +1025,12 @@ struct PSBTInput
|
|||
if (!m_issuance_inflation_keys_commitment.IsNull() && m_issuance_inflation_keys_rangeproof.empty()) {
|
||||
throw std::ios_base::failure("Issuance inflation keys commitment provided without inflation keys rangeproof");
|
||||
}
|
||||
if ((m_explicit_value.has_value() || !m_value_proof.empty()) && (!m_explicit_value.has_value() || m_value_proof.empty())) {
|
||||
throw std::ios_base::failure("Input explicit value and value proof must be provided together");
|
||||
}
|
||||
if ((!m_explicit_asset.IsNull() || !m_asset_proof.empty()) && (m_explicit_asset.IsNull() || m_asset_proof.empty())) {
|
||||
throw std::ios_base::failure("Input explicit asset and asset proof must be provided together");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -207,6 +207,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||
{ "rawreissueasset", 1, "reissuances" },
|
||||
{ "getnewblockhex", 0, "min_tx_age" },
|
||||
{ "getnewblockhex", 1, "proposed_parameters" },
|
||||
{ "getnewblockhex", 2, "commit_data" },
|
||||
{ "testproposedblock", 1, "acceptnonstd" },
|
||||
{ "issueasset", 0, "assetamount" },
|
||||
{ "issueasset", 1, "tokenamount" },
|
||||
|
|
|
|||
|
|
@ -1277,7 +1277,7 @@ static RPCHelpMan getnewblockhex()
|
|||
"\nGets hex representation of a proposed, unmined new block\n",
|
||||
{
|
||||
{"min_tx_age", RPCArg::Type::NUM, RPCArg::Default{0}, "How many seconds a transaction must have been in the mempool to be included in the block proposal. This may help with faster block convergence among functionaries using compact blocks."},
|
||||
{"proposed_parameters", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED , "Parameters to be used in dynamic federations blocks as proposals. During a period of `-dynamic_epoch_length` blocks, 4/5 of total blocks must signal these parameters for the proposal to become activated in the next epoch.",
|
||||
{"proposed_parameters", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "Parameters to be used in dynamic federations blocks as proposals. During a period of `-dynamic_epoch_length` blocks, 4/5 of total blocks must signal these parameters for the proposal to become activated in the next epoch.",
|
||||
{
|
||||
{"signblockscript", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "Hex-encoded block signing script to propose"},
|
||||
{"max_block_witness", RPCArg::Type::NUM, RPCArg::Optional::NO, "Total size in witness bytes that are allowed in the dynamic federations block witness for blocksigning"},
|
||||
|
|
@ -1289,7 +1289,11 @@ static RPCHelpMan getnewblockhex()
|
|||
},
|
||||
},
|
||||
"proposed_parameters"},
|
||||
{"commit_data", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED_NAMED_ARG, "Data in hex to be committed to in an additional coinbase output."},
|
||||
{"commit_data", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "Array of data in hex to be committed to in additional coinbase outputs.",
|
||||
{
|
||||
{"", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "Hex encoded string for commit data"},
|
||||
},
|
||||
},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::STR_HEX, "blockhex", "the block hex",
|
||||
|
|
@ -1346,18 +1350,31 @@ static RPCHelpMan getnewblockhex()
|
|||
proposed.m_serialize_type = 2;
|
||||
}
|
||||
|
||||
// Any commitment required for non-consensus reasons.
|
||||
// This will be placed in the first coinbase output.
|
||||
CScript data_commitment;
|
||||
// Any commitments required for non-consensus reasons.
|
||||
// These will be placed in the first coinbase outputs.
|
||||
std::vector<CScript> data_commitments;
|
||||
if (!request.params[2].isNull()) {
|
||||
std::vector<unsigned char> data_bytes = ParseHex(request.params[2].get_str());
|
||||
data_commitment = CScript() << OP_RETURN << data_bytes;
|
||||
UniValue commitments(UniValue::VARR);
|
||||
|
||||
// backwards compatibility: attempt to parse as a string first
|
||||
if (request.params[2].isStr()) {
|
||||
UniValue hex = request.params[2].get_str();
|
||||
commitments.push_back(hex);
|
||||
} else {
|
||||
commitments = request.params[2].get_array();
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < commitments.size(); i++) {
|
||||
std::vector<unsigned char> data_bytes = ParseHex(commitments[i].get_str());
|
||||
CScript data_commitment = CScript() << OP_RETURN << data_bytes;
|
||||
data_commitments.push_back(data_commitment);
|
||||
}
|
||||
}
|
||||
|
||||
CScript feeDestinationScript = Params().GetConsensus().mandatory_coinbase_destination;
|
||||
if (feeDestinationScript == CScript()) feeDestinationScript = CScript() << OP_TRUE;
|
||||
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(chainman.ActiveChainstate(), *node.mempool, Params()).CreateNewBlock(feeDestinationScript, std::chrono::seconds(required_wait), &proposed, data_commitment.empty() ? nullptr : &data_commitment));
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(chainman.ActiveChainstate(), *node.mempool, Params()).CreateNewBlock(feeDestinationScript, std::chrono::seconds(required_wait), &proposed, data_commitments.empty() ? nullptr : &data_commitments));
|
||||
if (!pblocktemplate.get()) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Wallet keypool empty");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -991,13 +991,13 @@ static RPCHelpMan createblindedaddress()
|
|||
"\nCreates a blinded address using the provided blinding key.\n",
|
||||
{
|
||||
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The unblinded address to be blinded."},
|
||||
{"blinding_key", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The blinding public key. This can be obtained for a given address using `validateaddress`."},
|
||||
{"blinding_key", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The blinding public key. This can be obtained for a given address using `getaddressinfo` (`confidential_key` field)."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::STR, "blinded_address", "The blinded address"
|
||||
},
|
||||
RPCExamples{
|
||||
"\nCreate a multisig address from 2 addresses\n"
|
||||
"\nCreate a blinded address\n"
|
||||
+ HelpExampleCli("createblindedaddress", "HEZk3iQi1jC49bxUriTtynnXgWWWdAYx16 ec09811118b6febfa5ebe68642e5091c418fbace07e655da26b4a845a691fc2d") +
|
||||
"\nAs a json rpc call\n"
|
||||
+ HelpExampleRpc("createblindedaddress", "HEZk3iQi1jC49bxUriTtynnXgWWWdAYx16, ec09811118b6febfa5ebe68642e5091c418fbace07e655da26b4a845a691fc2d")
|
||||
|
|
|
|||
|
|
@ -1214,6 +1214,11 @@ static RPCHelpMan decodepsbt()
|
|||
{RPCResult::Type::STR_HEX, "", "hex-encoded witness data (if any)"},
|
||||
}},
|
||||
{RPCResult::Type::STR_HEX, "utxo_rangeproof", "The rangeproof for the UTXO"},
|
||||
{RPCResult::Type::NUM, "explicit_value", /*optional=*/true, "The explicit value for this input"},
|
||||
{RPCResult::Type::STR_HEX, "value_proof", /*optional=*/true, "The explicit value proof for this input"},
|
||||
{RPCResult::Type::STR_HEX, "explicit_asset", /*optional=*/true, "The explicit asset for this input"},
|
||||
{RPCResult::Type::STR_HEX, "asset_proof", /*optional=*/true, "The explicit asset proof for this input"},
|
||||
{RPCResult::Type::BOOL, "blinded_issuance", /*optional=*/true, "Whether the issuance should be blinded prior to signing"},
|
||||
{RPCResult::Type::OBJ_DYN, "unknown", "The unknown global fields",
|
||||
{
|
||||
{RPCResult::Type::STR_HEX, "key", "(key-value pair) An unknown key-value pair"},
|
||||
|
|
@ -1596,6 +1601,45 @@ static RPCHelpMan decodepsbt()
|
|||
in.pushKV("utxo_rangeproof", HexStr(input.m_utxo_rangeproof));
|
||||
}
|
||||
|
||||
if (input.m_explicit_value.has_value()) {
|
||||
in.pushKV("explicit_value", ValueFromAmount(*input.m_explicit_value));
|
||||
}
|
||||
if (!input.m_value_proof.empty()) {
|
||||
in.pushKV("value_proof", HexStr(input.m_value_proof));
|
||||
}
|
||||
if (!input.m_explicit_asset.IsNull()) {
|
||||
in.pushKV("explicit_asset", input.m_explicit_asset.GetHex());
|
||||
}
|
||||
if (!input.m_asset_proof.empty()) {
|
||||
in.pushKV("asset_proof", HexStr(input.m_asset_proof));
|
||||
}
|
||||
|
||||
if (input.m_blinded_issuance.has_value()) {
|
||||
in.pushKV("blinded_issuance", *input.m_blinded_issuance);
|
||||
}
|
||||
|
||||
switch (VerifyBlindProofs(input)) {
|
||||
case BlindProofResult::OK:
|
||||
// all good
|
||||
break;
|
||||
case BlindProofResult::NOT_FULLY_BLINDED:
|
||||
in.pushKV("status", "ERROR: Proofs provided for unblinded input");
|
||||
break;
|
||||
case BlindProofResult::MISSING_VALUE_PROOF:
|
||||
in.pushKV("status", "WARNING: has confidential and explicit values but no proof connecting them");
|
||||
break;
|
||||
case BlindProofResult::MISSING_ASSET_PROOF:
|
||||
in.pushKV("status", "WARNING: has confidential and explicit assets but no proof connecting them");
|
||||
break;
|
||||
case BlindProofResult::INVALID_VALUE_PROOF:
|
||||
in.pushKV("status", "ERROR: has invalid value proof, the value may be a lie!");
|
||||
break;
|
||||
case BlindProofResult::INVALID_ASSET_PROOF:
|
||||
in.pushKV("status", "ERROR: has invalid asset proof, the asset may be a lie!");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Proprietary
|
||||
if (!input.m_proprietary.empty()) {
|
||||
UniValue proprietary(UniValue::VARR);
|
||||
|
|
|
|||
135
test/functional/rpc_getnewblockhex.py
Executable file
135
test/functional/rpc_getnewblockhex.py
Executable file
|
|
@ -0,0 +1,135 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Test getnewblockhex
|
||||
"""
|
||||
from io import BytesIO
|
||||
|
||||
from test_framework.messages import CBlock
|
||||
from test_framework.p2p import (
|
||||
P2PDataStore,
|
||||
)
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
hex_str_to_bytes,
|
||||
)
|
||||
|
||||
class GetNewBlockHexTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = False
|
||||
self.num_nodes = 1
|
||||
|
||||
def run_test(self):
|
||||
self.log.info("Starting test...")
|
||||
self.bootstrap_p2p()
|
||||
|
||||
node = self.nodes[0]
|
||||
|
||||
height = node.getblockcount()
|
||||
assert_equal(height, 200)
|
||||
|
||||
self.log.info("Call getnewblockhex with no args")
|
||||
hex = node.getnewblockhex()
|
||||
(height, hash) = self.mine_block(hex)
|
||||
assert_equal(height, 201)
|
||||
|
||||
self.log.info("Call getnewblockhex with single string commitment")
|
||||
hex = node.getnewblockhex(0, None, "1234")
|
||||
assert "6a021234" in hex
|
||||
(height, hash) = self.mine_block(hex)
|
||||
assert_equal(height, 202)
|
||||
block = node.getblock(hash, 2)
|
||||
vout = block["tx"][0]["vout"]
|
||||
assert_equal(vout[0]["scriptPubKey"]["hex"], "6a021234")
|
||||
|
||||
self.log.info("Call getnewblockhex with single string commitment with spaces")
|
||||
# ParseHex only validates hex chars, so spaces skipped
|
||||
hex = node.getnewblockhex(0, None, "1234 5678")
|
||||
assert "6a0412345678" in hex
|
||||
(height, hash) = self.mine_block(hex)
|
||||
assert_equal(height, 203)
|
||||
block = node.getblock(hash, 2)
|
||||
vout = block["tx"][0]["vout"]
|
||||
assert_equal(vout[0]["scriptPubKey"]["hex"], "6a0412345678")
|
||||
|
||||
self.log.info("Call getnewblockhex with single commitment")
|
||||
hex = node.getnewblockhex(0, None, ["1234"])
|
||||
assert "6a021234" in hex
|
||||
(height, hash) = self.mine_block(hex)
|
||||
assert_equal(height, 204)
|
||||
block = node.getblock(hash, 2)
|
||||
vout = block["tx"][0]["vout"]
|
||||
assert_equal(vout[0]["scriptPubKey"]["hex"], "6a021234")
|
||||
|
||||
self.log.info("Call getnewblockhex with multiple commitments")
|
||||
hex = node.getnewblockhex(0, None, ["1234", "deadbeef"])
|
||||
assert "6a021234" in hex
|
||||
assert "6a04deadbeef" in hex
|
||||
(height, hash) = self.mine_block(hex)
|
||||
assert_equal(height, 205)
|
||||
block = node.getblock(hash, 2)
|
||||
vout = block["tx"][0]["vout"]
|
||||
assert_equal(vout[0]["scriptPubKey"]["hex"], "6a021234")
|
||||
assert_equal(vout[1]["scriptPubKey"]["hex"], "6a04deadbeef")
|
||||
|
||||
hex = node.getnewblockhex(0, None, ["1234", "dead", "cafe", "babe"])
|
||||
assert "6a021234" in hex
|
||||
assert "6a02dead" in hex
|
||||
assert "6a02cafe" in hex
|
||||
assert "6a02babe" in hex
|
||||
(height, hash) = self.mine_block(hex)
|
||||
assert_equal(height, 206)
|
||||
block = node.getblock(hash, 2)
|
||||
vout = block["tx"][0]["vout"]
|
||||
assert_equal(vout[0]["scriptPubKey"]["hex"], "6a021234")
|
||||
assert_equal(vout[1]["scriptPubKey"]["hex"], "6a02dead")
|
||||
assert_equal(vout[2]["scriptPubKey"]["hex"], "6a02cafe")
|
||||
assert_equal(vout[3]["scriptPubKey"]["hex"], "6a02babe")
|
||||
|
||||
self.log.info("Done.")
|
||||
|
||||
def mine_block(self, hex):
|
||||
"""Mine and submit a block from a given hex template.
|
||||
|
||||
Returns a tuple of the new chain height and the block hash."""
|
||||
|
||||
bytes = hex_str_to_bytes(hex)
|
||||
block = CBlock()
|
||||
block.deserialize(BytesIO(bytes))
|
||||
block.solve()
|
||||
self.send_blocks([block], success=True)
|
||||
height = self.nodes[0].getblockcount()
|
||||
return (height, block.hash)
|
||||
|
||||
def bootstrap_p2p(self, timeout=10):
|
||||
"""Add a P2P connection to the node.
|
||||
|
||||
Helper to connect and wait for version handshake."""
|
||||
self.helper_peer = self.nodes[0].add_p2p_connection(P2PDataStore())
|
||||
# We need to wait for the initial getheaders from the peer before we
|
||||
# start populating our blockstore. If we don't, then we may run ahead
|
||||
# to the next subtest before we receive the getheaders. We'd then send
|
||||
# an INV for the next block and receive two getheaders - one for the
|
||||
# IBD and one for the INV. We'd respond to both and could get
|
||||
# unexpectedly disconnected if the DoS score for that error is 50.
|
||||
self.helper_peer.wait_for_getheaders(timeout=timeout)
|
||||
|
||||
def reconnect_p2p(self, timeout=60):
|
||||
"""Tear down and bootstrap the P2P connection to the node.
|
||||
|
||||
The node gets disconnected several times in this test. This helper
|
||||
method reconnects the p2p and restarts the network thread."""
|
||||
self.nodes[0].disconnect_p2ps()
|
||||
self.bootstrap_p2p(timeout=timeout)
|
||||
|
||||
def send_blocks(self, blocks, success=True, reject_reason=None, force_send=False, reconnect=False, timeout=960):
|
||||
"""Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block.
|
||||
|
||||
Call with success = False if the tip shouldn't advance to the most recent block."""
|
||||
self.helper_peer.send_blocks_and_test(blocks, self.nodes[0], success=success, reject_reason=reject_reason, force_send=force_send, timeout=timeout, expect_disconnect=reconnect)
|
||||
|
||||
if reconnect:
|
||||
self.reconnect_p2p(timeout=timeout)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
GetNewBlockHexTest().main()
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -108,6 +108,7 @@ BASE_SCRIPTS = [
|
|||
'feature_assetsdir.py',
|
||||
'feature_initial_reissuance_token.py',
|
||||
'feature_progress.py',
|
||||
'rpc_getnewblockhex.py',
|
||||
# Longest test should go first, to favor running tests in parallel
|
||||
'wallet_hd.py --legacy-wallet',
|
||||
'wallet_hd.py --descriptors',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue