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

feat: validate proof of work #33

Merged
Merged
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions src/validation.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ fn validate_prev_block_hash(self: @ChainState, block: @Block) -> Result<(), Byte
}

fn validate_proof_of_work(self: @ChainState, block: @Block) -> Result<(), ByteArray> {
// TODO: implement
Result::Ok(())
let target_u256: u256 = block.header.bits.clone().into();
maciejka marked this conversation as resolved.
Show resolved Hide resolved
maciejka marked this conversation as resolved.
Show resolved Hide resolved
if block.header.prev_block_hash.clone() <= target_u256 {
maciejka marked this conversation as resolved.
Show resolved Hide resolved
Result::Ok(())
} else {
Result::Err(
"Insufficient proof of work. Expected block hash {block.header.prev_block_hash} to be less than or equal to target {block.header.bits}."
maciejka marked this conversation as resolved.
Show resolved Hide resolved
)
}
}

fn validate_target(self: @ChainState, block: @Block) -> Result<(), ByteArray> {
Expand Down