forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
add ehf special tx #4577
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
Merged
Merged
add ehf special tx #4577
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // Copyright (c) 2021-2022 The Dash Core developers | ||
| // Distributed under the MIT software license, see the accompanying | ||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| #include <consensus/validation.h> | ||
| #include <evo/mnhftx.h> | ||
| #include <evo/specialtx.h> | ||
| #include <llmq/commitment.h> | ||
| #include <llmq/signing.h> | ||
|
|
||
| #include <chain.h> | ||
| #include <chainparams.h> | ||
| #include <validation.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| extern const std::string CBLSIG_REQUESTID_PREFIX = "clsig"; | ||
|
|
||
| bool MNHFTx::Verify(const CBlockIndex* pQuorumIndex) const | ||
| { | ||
| if (nVersion == 0 || nVersion > CURRENT_VERSION) { | ||
| return false; | ||
| } | ||
|
|
||
| Consensus::LLMQType llmqType = Params().GetConsensus().llmqTypeMnhf; | ||
| int signOffset{llmq::GetLLMQParams(llmqType).dkgInterval}; | ||
|
|
||
| const uint256 requestId = ::SerializeHash(std::make_pair(CBLSIG_REQUESTID_PREFIX, pQuorumIndex->nHeight)); | ||
| return llmq::CSigningManager::VerifyRecoveredSig(llmqType, pQuorumIndex->nHeight, requestId, pQuorumIndex->GetBlockHash(), sig, 0) || | ||
| llmq::CSigningManager::VerifyRecoveredSig(llmqType, pQuorumIndex->nHeight, requestId, pQuorumIndex->GetBlockHash(), sig, signOffset); | ||
| } | ||
|
|
||
| bool CheckMNHFTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main) | ||
| { | ||
| MNHFTxPayload mnhfTx; | ||
| if (!GetTxPayload(tx, mnhfTx)) { | ||
| return state.DoS(100, false, REJECT_INVALID, "bad-mnhf-payload"); | ||
| } | ||
|
|
||
| if (mnhfTx.nVersion == 0 || mnhfTx.nVersion > MNHFTxPayload::CURRENT_VERSION) { | ||
| return state.DoS(100, false, REJECT_INVALID, "bad-mnhf-version"); | ||
| } | ||
|
|
||
| const CBlockIndex* pindexQuorum = LookupBlockIndex(mnhfTx.signal.quorumHash); | ||
| if (!pindexQuorum) { | ||
| return state.DoS(100, false, REJECT_INVALID, "bad-mnhf-quorum-hash"); | ||
| } | ||
|
|
||
| if (pindexQuorum != pindexPrev->GetAncestor(pindexQuorum->nHeight)) { | ||
| // not part of active chain | ||
| return state.DoS(100, false, REJECT_INVALID, "bad-mnhf-quorum-hash"); | ||
| } | ||
|
|
||
| if (!Params().GetConsensus().llmqs.count(Params().GetConsensus().llmqTypeMnhf)) { | ||
| return state.DoS(100, false, REJECT_INVALID, "bad-mnhf-type"); | ||
| } | ||
|
|
||
| if (!mnhfTx.signal.Verify(pindexQuorum)) { | ||
| return state.DoS(100, false, REJECT_INVALID, "bad-mnhf-invalid"); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| std::string MNHFTx::ToString() const | ||
| { | ||
| return strprintf("MNHFTx(nVersion=%d, quorumHash=%s, sig=%s)", | ||
| nVersion, quorumHash.ToString(), sig.ToString()); | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Copyright (c) 2021-2022 The Dash Core developers | ||
| // Distributed under the MIT software license, see the accompanying | ||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| #ifndef BITCOIN_EVO_MNHFTX_H | ||
| #define BITCOIN_EVO_MNHFTX_H | ||
|
|
||
| #include <bls/bls.h> | ||
| #include <primitives/transaction.h> | ||
| #include <sync.h> | ||
| #include <threadsafety.h> | ||
| #include <univalue.h> | ||
|
|
||
| class CBlockIndex; | ||
| class CValidationState; | ||
| extern CCriticalSection cs_main; | ||
|
|
||
| // mnhf signal special transaction | ||
| class MNHFTx | ||
| { | ||
| public: | ||
| static constexpr uint16_t CURRENT_VERSION = 1; | ||
|
|
||
| uint16_t nVersion{CURRENT_VERSION}; | ||
| uint256 quorumHash; | ||
| CBLSSignature sig; | ||
|
|
||
| MNHFTx() = default; | ||
| bool Verify(const CBlockIndex* pQuorumIndex) const; | ||
|
|
||
| SERIALIZE_METHODS(MNHFTx, obj) | ||
| { | ||
| READWRITE(obj.nVersion, obj.quorumHash, obj.sig); | ||
| } | ||
|
|
||
| std::string ToString() const; | ||
|
|
||
| void ToJson(UniValue& obj) const | ||
| { | ||
| obj.clear(); | ||
| obj.setObject(); | ||
| obj.pushKV("version", (int)nVersion); | ||
| obj.pushKV("quorumHash", quorumHash.ToString()); | ||
| obj.pushKV("sig", sig.ToString()); | ||
| } | ||
| }; | ||
|
|
||
| class MNHFTxPayload | ||
| { | ||
| public: | ||
| static constexpr uint16_t CURRENT_VERSION = 1; | ||
|
|
||
| uint16_t nVersion{CURRENT_VERSION}; | ||
| MNHFTx signal; | ||
|
|
||
| SERIALIZE_METHODS(MNHFTxPayload, obj) | ||
| { | ||
| READWRITE(obj.nVersion, obj.signal); | ||
| } | ||
|
|
||
| void ToJson(UniValue& obj) const | ||
| { | ||
| obj.setObject(); | ||
| obj.pushKV("version", (int)nVersion); | ||
|
|
||
| UniValue mnhfObj; | ||
| signal.ToJson(mnhfObj); | ||
| obj.pushKV("signal", mnhfObj); | ||
| } | ||
| }; | ||
|
|
||
| bool CheckMNHFTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||
|
|
||
| #endif // BITCOIN_EVO_MNHFTX_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // Copyright (c) 2021 The Dash Core developers | ||
| // Distributed under the MIT software license, see the accompanying | ||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| #include <bls/bls.h> | ||
| #include <consensus/validation.h> | ||
| #include <evo/mnhftx.h> | ||
| #include <evo/specialtx.h> | ||
| #include <primitives/transaction.h> | ||
| #include <uint256.h> | ||
| #include <util/strencodings.h> | ||
|
|
||
| #include <boost/test/unit_test.hpp> | ||
| #include <test/setup_common.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
|
|
||
| bool VerifyMNHFTx(const CTransaction& tx, CValidationState& state) | ||
| { | ||
| MNHFTxPayload mnhfTx; | ||
| if (!GetTxPayload(tx, mnhfTx)) { | ||
| return state.DoS(100, false, REJECT_INVALID, "bad-mnhf-payload"); | ||
| } | ||
|
|
||
| if (mnhfTx.nVersion == 0 || mnhfTx.nVersion > MNHFTxPayload::CURRENT_VERSION) { | ||
| return state.DoS(100, false, REJECT_INVALID, "bad-mnhf-version"); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| static CMutableTransaction CreateMNHFTx(const uint256& mnhfTxHash, const CBLSSignature& cblSig, const uint16_t& versionBit) | ||
| { | ||
| MNHFTxPayload extraPayload; | ||
| extraPayload.nVersion = 1; | ||
| extraPayload.signal.nVersion = versionBit; | ||
| extraPayload.signal.quorumHash = mnhfTxHash; | ||
| extraPayload.signal.sig = cblSig; | ||
|
|
||
| CMutableTransaction tx; | ||
| tx.nVersion = 3; | ||
| tx.nType = TRANSACTION_MNHF_SIGNAL; | ||
| SetTxPayload(tx, extraPayload); | ||
|
|
||
| return tx; | ||
| } | ||
|
|
||
| BOOST_FIXTURE_TEST_SUITE(specialtx_tests, BasicTestingSetup) | ||
|
|
||
| BOOST_AUTO_TEST_CASE(verify_mnhf_specialtx_tests) | ||
| { | ||
| int count = 10; | ||
| uint16_t ver = 2; | ||
|
|
||
| std::vector<CBLSSignature> vec_sigs; | ||
| std::vector<CBLSPublicKey> vec_pks; | ||
| std::vector<CBLSSecretKey> vec_sks; | ||
|
|
||
| CBLSSecretKey sk; | ||
| uint256 hash = GetRandHash(); | ||
| for (int i = 0; i < count; i++) { | ||
| sk.MakeNewKey(); | ||
| vec_pks.push_back(sk.GetPublicKey()); | ||
| vec_sks.push_back(sk); | ||
| } | ||
|
|
||
| CBLSSecretKey ag_sk = CBLSSecretKey::AggregateInsecure(vec_sks); | ||
| CBLSPublicKey ag_pk = CBLSPublicKey::AggregateInsecure(vec_pks); | ||
|
|
||
| BOOST_CHECK(ag_sk.IsValid()); | ||
| BOOST_CHECK(ag_pk.IsValid()); | ||
|
|
||
| uint256 verHash = uint256S(itostr(ver)); | ||
| auto sig = ag_sk.Sign(verHash); | ||
| BOOST_CHECK(sig.VerifyInsecure(ag_pk, verHash)); | ||
|
|
||
| const CMutableTransaction tx = CreateMNHFTx(hash, sig, ver); | ||
| CValidationState state; | ||
| BOOST_CHECK(VerifyMNHFTx(CTransaction(tx), state)); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_SUITE_END() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.