Skip to content

Commit

Permalink
validation: check auxpow PoW before other checks
Browse files Browse the repository at this point in the history
block: check parent coinbase for input

Ported from dogecoin/dogecoin@51cbc1f
  • Loading branch information
edtubbs committed Dec 18, 2024
1 parent 77cf47f commit cb5b767
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ dogecoin_bool check(void *ctx, uint256* hash, uint32_t chainid, dogecoin_chainpa
uint256* chain_merkle_root = check_merkle_branch(hash, chain_merkle_branch, block->aux_merkle_index);
vector_free(chain_merkle_branch, true);

// Check that there is at least one input in the parent coinbase transaction
if (block->parent_coinbase->vin->len == 0) {
printf("Aux POW coinbase has no inputs\n");
dogecoin_free(chain_merkle_root);
return false;
}

// Convert the root hash to a human-readable format (hex)
unsigned char vch_roothash[64]; // Make sure it's large enough to hold the hash
memcpy(vch_roothash, hash_to_string((uint8_t*)chain_merkle_root), 64); // Copy the data
Expand Down
16 changes: 8 additions & 8 deletions src/validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,6 @@ dogecoin_bool check_auxpow(dogecoin_auxpow_block* block, dogecoin_chainparams* p
}

/* We have auxpow. Check it. */
uint256 block_header_hash;
dogecoin_block_header_hash(block->header, block_header_hash);
uint32_t chainid = get_chainid(block->header->version);
if (!block->header->auxpow->check(block, &block_header_hash, chainid, params)) {
printf("%s:%d:%s : AUX POW is not valid : %s\n", __FILE__, __LINE__, __func__, strerror(errno));
return false;
}

uint256 parent_hash;
cstring* s2 = cstr_new_sz(64);
dogecoin_block_header_serialize(s2, block->parent_header);
Expand All @@ -113,5 +105,13 @@ dogecoin_bool check_auxpow(dogecoin_auxpow_block* block, dogecoin_chainparams* p
return false;
}

uint256 block_header_hash;
dogecoin_block_header_hash(block->header, block_header_hash);
uint32_t chainid = get_chainid(block->header->version);
if (!block->header->auxpow->check(block, &block_header_hash, chainid, params)) {
printf("%s:%d:%s : AUX POW is not valid : %s\n", __FILE__, __LINE__, __func__, strerror(errno));
return false;
}

return true;
}

0 comments on commit cb5b767

Please sign in to comment.