MerosCrypto / Meros

An instant and feeless cryptocurrency for the future, secured by the Merit Caching Consensus Mechanism.
https://meroscrypto.io
Other
82 stars 19 forks source link

Meros miscorrectly believes some Blocks don't have all their inputs already mentioned. #233

Closed kayabaNerve closed 4 years ago

kayabaNerve commented 4 years ago

Block which a seed node rejected:

{
    "hash": "632A9EC63888B7224183F549B6BB7FCF6ED6934DF1828DF71B0FA95ED53F0300",
    "header": {
        "version": 0,
        "last": "6FE158DA1371ED0D8D0A15E4C1E8ED1E539282D5C9A0B3E29907098B1BBE1A00",
        "contents": "D644BAC3453EA592E1CAB483529249021047D86E3B0619E5905401287C4FEDB1",
        "significant": 1,
        "sketchSalt": "00000000",
        "sketchCheck": "E98CB443800F777115751DE0836B855699450214F9B940955F2CF7B9DA7ACE12",
        "time": 1595694309,
        "proof": 52456,
        "signature": "9663D6FE2804EE90102A6BBEC4C60950DDAAF893A43D3369721A45CEAF739A0C0C49F058DDDF652E03091595BE530E6F",
        "miner": 0
    },
    "aggregate": "833FA1753F5E92794B415DA61B252A789B7B7D0FE7AB009DB63A659D8FC8C3CEEE500956F0D46DEA85941DB0881A787A",
    "transactions": [
        {
            "hash": "5CA7E22C5EC890ED237BF07540EC302DC0C61BFB1612863E2CF123BDD0239B5A",
            "holders": [
                0,
                3
            ]
        },
        {
            "hash": "B8FA90301342CFE64C3660DE0A97F922424C606B3EE7482A05367C03DD8542B0",
            "holders": [
                0,
                3
            ]
        },
        {
            "hash": "DEFF862D069A9F2AB03BE8DC9FC636A75C4D06E3B69F01ADAF305C399BE6C151",
            "holders": [
                0,
                2,
                3
            ]
        }
    ],
    "elements": []
}
"5CA7E22C5EC890ED237BF07540EC302DC0C61BFB1612863E2CF123BDD0239B5A": {
    "inputs": [
        {
            "hash": "4D45524F535F444556454C4F5045525F544553544E45545F3500000000000000"
        }
    ],
    "outputs": [],
    "hash": "5CA7E22C5EC890ED237BF07540EC302DC0C61BFB1612863E2CF123BDD0239B5A",
    "descendant": "Data",
    "data": "D17E9033A920FE04347242AF694BB78B37C805436C7AD613F4D11E3795761700",
    "signature": "5C291DB91A91FBF6AB5D23083B70D01290E2473EA4A5A954ED97019A4237FB5AF6DA3A08A75C03B2E84B69EB98F6472DE21F30B8727789C2F89FE02288943B04",
    "proof": 0,
    "argon": "0BE6B0FB92B51DB91FF15B5585F28C52F1994763164F56256E0D2E05904CD600"
}

"B8FA90301342CFE64C3660DE0A97F922424C606B3EE7482A05367C03DD8542B0": {
    "inputs": [
        {
            "hash": "DEFF862D069A9F2AB03BE8DC9FC636A75C4D06E3B69F01ADAF305C399BE6C151"
        }
    ],
    "outputs": [],
    "hash": "B8FA90301342CFE64C3660DE0A97F922424C606B3EE7482A05367C03DD8542B0",
    "descendant": "Data",
    "data": "546869732069732061206261736963204461746120746573742E",
    "signature": "86A5E14F08614B6D3C1F599448A36FE921E1E9BE2B0A0865C43FE18BE5046FF6453259C216353B46CD53CB304982793D7A0824F43275164DAF42BA01618E7004",
    "proof": 5,
    "argon": "4524D5461158DB18B6B8AC9ED284137E227412DD892E047549EE90B42449300E"
}

"DEFF862D069A9F2AB03BE8DC9FC636A75C4D06E3B69F01ADAF305C399BE6C151": {
    "inputs": [
        {
            "hash": "0000000000000000000000000000000000000000000000000000000000000000"
        }
    ],
    "outputs": [],
    "hash": "DEFF862D069A9F2AB03BE8DC9FC636A75C4D06E3B69F01ADAF305C399BE6C151",
    "descendant": "Data",
    "data": "DC0D2EEB08CE1240ADE63ACBE01D7375446BFB61A45F0A671EB8179FA4DEC8A3",
    "signature": "E75C83B2751FD6C1A99FA223C7E09E718028EB6106D973977B329EB6D55C5B942C708B5709B87D1CE31B4B0005F72A229B729FD1C0DB6A19139A76BC6BF78B0B",
    "proof": 4,
    "argon": "27ACBB80DC3C2ACA88AB4CE0D7AB1DBD04B2169D81FDBA32C03833B3B89CE715"
}

The second transaction relies on the third. That said, their should be sort code in play to prevent this. Then there's the question of why one node allowed this (the miner) and yet another did not.

kayabaNerve commented 4 years ago

It could be a hash sort/packet sort disconnect.

kayabaNerve commented 4 years ago
    {
      "hash": "98A24AE3316BEAFA90B29F9F8161E879DBD0358F590338BE34ECFCF7C10A1300",
      "header": {
        "contents": "7022E89B3EA6C7548B6792A272EE650997426E3557C3DC96276D123487065149",
        "sketchCheck": "CF283D5C7E54E75202D5237C670102E590091B6347AA233F6EFE8DB12CD814AC",
        "time": 1595693721,
        "proof": 6880,
        "signature": "896A63C842F06575C118F329714073D8A09F04D8C0849FAD048BAD4D74E85120F9254FCE2EA07F14109D171AA4E797BF",
        "miner": 1
      },
      "aggregate": "AB982D547E1F38E02AEAA8566AD37D42CDC051A98A3DE208206EA742B5BCC5FF49C65E04C3F65F001DB96F597A65DD65",
      "transactions": [
        {
          "hash": "A93E25A54F933B515DD13BE4257C3AF84A47AE65ED85341FA5421754CBE8A6B9",
          "holders": [
            1
          ]
        },
        {
          "hash": "300F2D4BEC4D3C8F1A33F303526DD061BC3FFD4BB90D8B1AF1F80204C02082E0",
          "holders": [
            0,
            3
          ]
        },
        {
          "hash": "86F7B04B9AE7D04669E2E4383300BF2D5480CD6DDEE0D379B5119EDF7DC3B71E",
          "holders": [
            0,
            3
          ]
        }
      ]
    }
"A93E25A54F933B515DD13BE4257C3AF84A47AE65ED85341FA5421754CBE8A6B9": {
  "inputs": [
    {
      "hash": "4D45524F535F444556454C4F5045525F544553544E45545F3500000000000000"
    }
  ],
  "outputs": [],
  "hash": "A93E25A54F933B515DD13BE4257C3AF84A47AE65ED85341FA5421754CBE8A6B9",
  "descendant": "Data",
  "data": "C456BA3A2691B0E292A4C959D5687EBBB83E9F3473B073DC29AC1E5D1AB91300",
  "signature": "FCB406BF11DE863663605C8BB40F8166B2AA070EF72364B5AA2EFE39B53593638A78D975A59AAAF157FEBC147EFFBACC7301B71190BA2080E4AE11C45E92D401",
  "proof": 0,
  "argon": "FD103038724E0420A362C19AB482C04413C3C48C609BD244FE441591D15E54D9"
}

"300F2D4BEC4D3C8F1A33F303526DD061BC3FFD4BB90D8B1AF1F80204C02082E0": {
  "inputs": [
    {
      "hash": "4D45524F535F444556454C4F5045525F544553544E45545F3500000000000000"
    }
  ],
  "outputs": [],
  "hash": "300F2D4BEC4D3C8F1A33F303526DD061BC3FFD4BB90D8B1AF1F80204C02082E0",
  "descendant": "Data",
  "data": "7C42CAB126C3096993F74AB14A90E07243182BE4508075C714D96AF936A61400",
  "signature": "751F30A1DAA221E2EDF22394123EBFB1A8859623C0A50B01D492A678D9CD48762D1EC93A76EE0375BF1CF556BBCD730A8A42A7358DC9E7AE642381B187AE7C07",
  "proof": 0,
  "argon": "0000000000000000000000000000000000000000000000000000000000000000"
}

"86F7B04B9AE7D04669E2E4383300BF2D5480CD6DDEE0D379B5119EDF7DC3B71E": {
  "inputs": [
    {
      "hash": "903808BD94D4977C513245FEBCCF0FFDA145E6FB140BCF3B791FB2C79113BEE5",
      "nonce": 0
    },
    {
      "hash": "71D8387AEC0AF30DFDBAD04743B39B140F04D26FF5FAB129AD33064F332B669F",
      "nonce": 0
    },
    {
      "hash": "969C47A9717491317EFE421313564BE9C979E7E1F761070E4CEC65E7F3CDC239",
      "nonce": 0
    },
    {
      "hash": "98620075F16EC0B7CBC5B6932CC97FC932FCF791ECA1244403B04C7419F00E70",
      "nonce": 0
    },
    {
      "hash": "AEBE311ACF1265633AE3233324C93D58443030F0A9136883B03BCAF146531755",
      "nonce": 0
    },
    {
      "hash": "42655F1AF8EAD60ED86F4C97B8A8C666B63B3C1FAEB09BE7E69AC35B13FCB767",
      "nonce": 0
    },
    {
      "hash": "C916FC373026DB3896517A5D1CD3F4285658589920CA3C5DA8D4D0B3D1F78840",
      "nonce": 0
    },
    {
      "hash": "B985E0478453BEAA631005DC800C09F412BCCB683F063EC4EFA73CA6D4F6AEB4",
      "nonce": 0
    },
    {
      "hash": "5A62CC4A124718BA7FC398840A110ADCB3CD7DF4F6D94034FC7698B85748468C",
      "nonce": 1
    },
    {
      "hash": "A150F1A13124E98F6E077DD117CFAD4A324037CE0BAF99C7940FE95E0DA0F4F8",
      "nonce": 0
    }
  ],
  "outputs": [
    {
      "amount": "400000",
      "key": "818C65E6DB640E367025CAF8B77090F4A450396CA46505251F442CAA74BAA673"
    },
    {
      "amount": "11505",
      "key": "DC0D2EEB08CE1240ADE63ACBE01D7375446BFB61A45F0A671EB8179FA4DEC8A3"
    }
  ],
  "hash": "86F7B04B9AE7D04669E2E4383300BF2D5480CD6DDEE0D379B5119EDF7DC3B71E",
  "descendant": "Send",
  "signature": "2BCF78A4A8720EC71A79752F5305E35D3FB3CF4E3AC90FCEBE47FA461EB809E056EDF0D262C4D19632A27CB2B43ABB977FADFE500924526E61E0EC8E5CDAD203",
  "proof": 1,
  "argon": "8F2E242683AF0DFF7133D697671FE5BA02A7877C3584B472EC1F34A13A185A00"
}

is another.

kayabaNerve commented 4 years ago

Tried to reproduce with:

proto: PrototypeChain = PrototypeChain(1)

dataFilter: SpamFilter = SpamFilter(5)

edPrivKey: ed25519.SigningKey = ed25519.SigningKey(b'\0' * 32)
edPubKey: ed25519.VerifyingKey = edPrivKey.get_verifying_key()

datas: List[Data] = [Data(bytes(32), edPubKey.to_bytes())]
datas.append(Data(datas[0].hash, b'\0'))
counter: int = 1

packets: List[VerificationPacket] = [VerificationPacket(data.hash, [0]) for data in datas]
while Sketch.hash(bytes(4), packets[0]) < Sketch.hash(bytes(4), packets[1]):
  datas[1] = Data(datas[0].hash, counter.to_bytes(4, byteorder="little"))
  packets[1] = VerificationPacket(datas[1].hash, [0])
  counter += 1
for data in datas:
  data.sign(edPrivKey)
  data.beat(dataFilter)

proto.add(packets=packets)

Failed to. I'm honestly quite happy it wasn't there. Printing the sketch hashes now/looking to see which if these were in memory.

kayabaNerve commented 4 years ago

Confirmed that the first Block went child, origin.

kayabaNerve commented 4 years ago

None of the TXs from the first Block were already known to the node (except the Block's Data); it failed AFTER adding DEFF (original data).

kayabaNerve commented 4 years ago

Figured it out! It's a cross-chain Data.

https://github.com/MerosCrypto/Meros/issues/228 details how a Block's Data can survive chain re-organizations. The Data verified by the first Block is from an alt-chain. The Data override for the sync code is as follows:

        var first: bool = (tx of Data) and (tx.inputs[0].hash == Hash[256]())

        #Make sure we have already added every input.
        if not first:
          for input in tx.inputs:
            try:
              discard manager.functions.transactions.getTransaction(input.hash)

As we should always have every Block Data when syncing a Block, this is perfectly valid. That said, if a cross-chain Data slips through, this is the error it'll manifest with.