KomodoPlatform / zebra

An ongoing Rust implementation of a Komodo node. 🦓
Apache License 2.0
3 stars 5 forks source link

implement merkleroot opret in easy-mined block rule #30

Closed DeckerSU closed 1 year ago

DeckerSU commented 1 year ago

https://github.com/KomodoPlatform/komodo/blob/master/src/main.cpp#L5144-L5157

if ( height > nDecemberHardforkHeight && ASSETCHAINS_SYMBOL[0] == 0 ) // December 2019 hardfork
    {
        int32_t notaryid;
        int32_t special = komodo_chosennotary(&notaryid,height,pubkey33,tiptime);
        if (notaryid > 0 || ( notaryid == 0 && height > nS5HardforkHeight ) ) {
            CScript merkleroot = CScript();
            CBlock blockcopy = block; // block shouldn't be changed below, so let's make it's copy
            CBlock *pblockcopy = (CBlock *)&blockcopy;
            if (!komodo_checkopret(pblockcopy, merkleroot)) {
                fprintf(stderr, "failed or missing merkleroot expected.%s != merkleroot.%s\n", komodo_makeopret(pblockcopy, false).ToString().c_str(), merkleroot.ToString().c_str());
                return state.DoS(100, error("CheckBlock: failed or missing merkleroot opret in easy-mined"),REJECT_INVALID, "failed-merkle-opret-in-easy-mined");
            }
        }
    }

Notary proof txes must contain specially prepared merkle in OP_RETURN of a second vout. Example:

OP_RETURN example:

"vout": [
    {
      "value": 0.00005000,
      "interest": 0.00000000,
      "valueZat": 5000,
      "n": 0,
      "scriptPubKey": {
        "asm": "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9 OP_CHECKSIG",
        "hex": "21020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9ac",
        "reqSigs": 1,
        "type": "pubkey",
        "addresses": [
          "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA"
        ]
      }
    },
    {
      "value": 0.00000000,
      "interest": 0.00000000,
      "valueZat": 0,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_RETURN 08622318f80582f117b8b1421e81eca925afc2743cad610f0b16e0f0740fda82",
        "hex": "6a2008622318f80582f117b8b1421e81eca925afc2743cad610f0b16e0f0740fda82",
        "type": "nulldata"
      }
    }
  ]
DeckerSU commented 1 year ago

I'll probably continue to work on this issue in the patch-komodo-check-deposit branch, related to this issue. Probably this check will be implemented directly in: https://github.com/KomodoPlatform/zebra/blob/b275bd1088b1a544890b23a55468394df6330933/zebra-consensus/src/transaction/check.rs#L241 because it perfectly fits its (this function) architecture.