Skip to content

Conversation

nonam3e
Copy link
Contributor

@nonam3e nonam3e commented Feb 10, 2025

This PR adds POW algorithm

cuda-backend-branch: feat/blake-pow

false; /**< True to run the pow solver asynchronously, false to run synchronously. Default is false. */
ConfigExtension* ext = nullptr; /**< Pointer to backend-specific configuration extensions. Default is nullptr. */
};
const uint8_t BLOCK_LEN = 64;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not in the config struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh this value is unused, forgot to delete it


eIcicleError pow_solver(
Hash hasher,
uint8_t* challenge,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consistency maybe make it std::byte* like hash APIs

uint32_t padding_size,
uint8_t bits,
const PowConfig& config,
bool* found,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other ICICLE APIs in C++ use reference for outputs, not pointers so probably better to make it consistent.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(1) I now noticed that you support them being device memory. Also the found boolean? This is a little confusing I think.
(2) Please add description to the API. It's unclear what should be the size of nonce for example etc.

use icicle_core::hash::{Hasher, HasherHandle};
use icicle_runtime::{config::ConfigExtension, errors::eIcicleError, memory::HostOrDeviceSlice, IcicleStreamHandle};

const PADDING_SIZE: u32 = 24;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be in the config I think

#[derive(Debug, Clone)]
pub struct PowConfig {
pub stream: IcicleStreamHandle, // `icicleStreamHandle` is represented as a raw pointer.
pub is_challenge_on_device: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the 'on-device' fields private? We usually set them instead of the users so they don't need to care about it.


let hasher = Blake3::new(0).unwrap();

let err = pow_solver(&hasher, input_host, BITS, &cfg, found_host, nonce_host, mined_hash_host);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(1) I am not sure I understand this API. How do you define the threshold value for the hash result?
(2) can you verify that with the nonce you found, the hashing indeed succeeds? in this test I mean

Copy link
Collaborator

@yshekel yshekel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, I left a few comments.
Is it equivalent to other implementations? which?

@LeonHibnik
Copy link
Contributor

Overall looks good, I left a few comments. Is it equivalent to other implementations? which?

@yshekel it should be equivalent to this

Copy link
Contributor

@LeonHibnik LeonHibnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a comment here and couple in cuda impl

@nonam3e
Copy link
Contributor Author

nonam3e commented Feb 11, 2025

added proof_of_work_check to verify mined solutions, resolved comments as well

* @return eIcicleError Error code indicating success or failure of the operation.
*/
eIcicleError pow_solver(
Hash& hasher,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why hasher and challenge not const?

* @return eIcicleError Error code indicating success or failure of the verification process.
*/
eIcicleError pow_check(
Hash& hasher,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

*
* @return eIcicleError Error code indicating success or failure of the verification process.
*/
eIcicleError pow_check(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mayber pow_verify? I think clearer than pow_check

Copy link
Collaborator

@yshekel yshekel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left small comments and then I will approve

uint8_t solution_bits,
const PowConfig& config,
bool& found,
uint64_t& nonce,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this always on host?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I changed it because they are just single values

@LeonHibnik LeonHibnik requested a review from yshekel February 12, 2025 13:24
@nonam3e nonam3e merged commit b59a498 into main Feb 13, 2025
15 checks passed
@nonam3e nonam3e deleted the feat/blake-pow branch February 13, 2025 09:02
mickeyasa pushed a commit that referenced this pull request Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants