dogecoin / libdohj

Java library for adding altcoin support to bitcoinj
Apache License 2.0
108 stars 89 forks source link

Is "MergedMiningHeader missing from parent coinbase" a correct consensus rule? #15

Closed JeremyRand closed 8 years ago

JeremyRand commented 8 years ago

Hello!

I've been playing around with adding Namecoin support to libdohj. I don't have any code to release yet, but I have a quick question about an issue that I'm running into.

When libdohj processes this Namecoin MainNet block: https://namecoin.webbtc.com/block/5fb89c3b18c27bc38d351d516177cbd3504c95ca0494cbbbbd52f2fb5f2ff1ec , I get the error "MergedMiningHeader missing from parent coinbase". This is block height 19414. Namecoin MainNet's first auxpow block was at height 19200, so it looks like a lot of auxpow blocks passed verification before this one failed. I notice that while the previous block does contain the string "fabe6d6d" in the hex representation of its auxpow coinbase (which is the merged mining header), this block does not (although there is auxpow data present and the auxpow bit is set in the block version).

I then looked at the C++ source code for both Namecoin Core and Dogecoin Core. The libdohj auxpow verification code is pretty similar to both of the C++ implementations, except that I cannot find this particular error in either of the C++ implementations. Dogecoin Core instead uses the error "Aux POW chain merkle root must start in the first 20 bytes of the parent coinbase", which only is raised under a subset of circumstances. See https://github.com/dogecoin/dogecoin/blob/master/src/auxpow.cpp#L107 for the relevant function of Dogecoin Core, and https://github.com/dogecoin/libdohj/blob/master/src/main/java/org/bitcoinj/core/AuxPoW.java#L238 for the equivalent function in libdohj.

So, I'm a little bit confused on what the purpose is of this check in libdohj. Is this a consensus difference between libdohj and Dogecoin Core, which Dogecoin has just been lucky enough to not run into in the production blockchain?

Cheers.

-Jeremy Rand, namecoin.org

rnicoll commented 8 years ago

I think that's snuck in when I replaced our AuxPoW code (from UnitedScryptCoin) with Namecoin's implementation. The original test matches between the two implementations: https://github.com/dogecoin/dogecoin/blob/v1.8.2/src/auxpow.cpp#L52 - so 1.10 is slightly more tolerant of the block header format. Sorry about that everyone.

I'll get libdohj updated to match 1.10, as the dominant implementation right now.

rnicoll commented 8 years ago

Should be fixed in https://github.com/dogecoin/libdohj/commit/89cf3c6b1778632198c90335157fa7a9fe858623, could you check and close this if you're happy please.

JeremyRand commented 8 years ago

Thanks, I'll test this later today and see if it works.

JeremyRand commented 8 years ago

Namecoin now syncs to 100% with no issues, so looks like this is fixed (at least in the case of the specific auxpow coinbases found in the Namecoin blockchain). Thanks for the quick fix.