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

validation: check auxpow PoW before other checks #237

Open
wants to merge 2 commits into
base: 0.1.4-dogebox-pre
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
goal: install
- name: x86_64-macos
host: x86_64-apple-darwin15
os: macos-12
os: macos-13
run-tests: true
dep-opts: "SPEED=slow V=1"
config-opts: "--enable-static --disable-shared --enable-test-passwd"
Expand Down
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;
}
Loading