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

Move RSK output to be the last output #469

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
49 changes: 26 additions & 23 deletions src/bitcoin/StratumBitcoin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -805,29 +805,6 @@ bool StratumJobBitcoin::initFromGbt(
cbOut.push_back(rootStateTxOut);
}
#endif
//
// output[3] (optional): RSK merge mining
//
if (latestRskBlockJson.isInitialized()) {
DLOG(INFO) << "RSK blockhash: " << blockHashForMergedMining_;
string rskBlockTag =
"\x6a\x29\x52\x53\x4B\x42\x4C\x4F\x43\x4B\x3A"; // "RSKBLOCK:"
vector<char> rskTag(rskBlockTag.begin(), rskBlockTag.end());
vector<char> binBuf;

Hex2Bin(blockHashForMergedMining_.c_str(), binBuf);

rskTag.insert(std::end(rskTag), std::begin(binBuf), std::end(binBuf));

CTxOut rskTxOut;
rskTxOut.scriptPubKey = CScript(
(unsigned char *)rskTag.data(),
(unsigned char *)rskTag.data() + rskTag.size());
rskTxOut.nValue = AMOUNT_TYPE(0);

cbOut.push_back(rskTxOut);
}

//
// output[3] (optional): VCASH merge mining
//
Expand All @@ -852,6 +829,32 @@ bool StratumJobBitcoin::initFromGbt(
cbOut.push_back(vcashTxOut);
}

//
// output[3] (optional): RSK merge mining
//
// To avoid possible malleability attacks, RSK discards solutions with more than 128 bytes after RSK tag.
// Therefor, RSK output should be one of the last or the last output in the Coinbase.
//
if (latestRskBlockJson.isInitialized()) {
DLOG(INFO) << "RSK blockhash: " << blockHashForMergedMining_;
string rskBlockTag =
"\x6a\x29\x52\x53\x4B\x42\x4C\x4F\x43\x4B\x3A"; // "RSKBLOCK:"
vector<char> rskTag(rskBlockTag.begin(), rskBlockTag.end());
vector<char> binBuf;

Hex2Bin(blockHashForMergedMining_.c_str(), binBuf);

rskTag.insert(std::end(rskTag), std::begin(binBuf), std::end(binBuf));

CTxOut rskTxOut;
rskTxOut.scriptPubKey = CScript(
(unsigned char *)rskTag.data(),
(unsigned char *)rskTag.data() + rskTag.size());
rskTxOut.nValue = AMOUNT_TYPE(0);

cbOut.push_back(rskTxOut);
}

if (nmcAuxBits_ == 0u && latestVcashBlockJson.isInitialized()) {
nmcAuxBits_ = latestVcashBlockJson.getBits();
nmcRpcAddr_ = vcashdRpcAddress_;
Expand Down