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

[CHIA-1562] validate block signature as part of run_block_generator() #745

Merged
merged 6 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crates/chia-bls/src/bls_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ impl BlsCache {

aggregate_verify_gt(sig, iter)
}

pub fn update(&mut self, aug_msg: &[u8], gt: GTElement) {
let mut hasher = Sha256::new();
hasher.update(aug_msg.as_ref());
let hash: [u8; 32] = hasher.finalize();
self.cache.lock().expect("cache").put(hash, gt);
}
}

#[cfg(feature = "py-bindings")]
Expand Down
9 changes: 7 additions & 2 deletions crates/chia-consensus/benches/run-generator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use chia_bls::Signature;
use chia_consensus::consensus_constants::TEST_CONSTANTS;
use chia_consensus::gen::flags::ALLOW_BACKREFS;
use chia_consensus::gen::flags::{ALLOW_BACKREFS, DONT_VALIDATE_SIGNATURE};
use chia_consensus::gen::run_block_generator::{run_block_generator, run_block_generator2};
use clvmr::serde::{node_from_bytes, node_to_bytes_backrefs};
use clvmr::Allocator;
Expand Down Expand Up @@ -55,7 +56,9 @@ fn run(c: &mut Criterion) {
gen,
&block_refs,
11_000_000_000,
ALLOW_BACKREFS,
ALLOW_BACKREFS | DONT_VALIDATE_SIGNATURE,
&Signature::default(),
None,
&TEST_CONSTANTS,
);
let _ = black_box(conds);
Expand All @@ -74,6 +77,8 @@ fn run(c: &mut Criterion) {
&block_refs,
11_000_000_000,
ALLOW_BACKREFS,
&Signature::default(),
None,
&TEST_CONSTANTS,
);
let _ = black_box(conds);
Expand Down
1 change: 1 addition & 0 deletions crates/chia-consensus/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ chia-protocol = { workspace = true }
chia-sha2 = { workspace = true }
chia-traits = { workspace = true }
chia-consensus = { workspace = true }
chia-bls = { workspace = true }
hex-literal = { workspace = true }

[[bin]]
Expand Down
12 changes: 10 additions & 2 deletions crates/chia-consensus/fuzz/fuzz_targets/parse-spends.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![no_main]
use libfuzzer_sys::fuzz_target;

use chia_bls::Signature;
use chia_consensus::gen::conditions::{parse_spends, MempoolVisitor};
use chia_fuzz::{make_list, BitCursor};
use clvmr::{Allocator, NodePtr};
Expand All @@ -14,7 +15,14 @@ fuzz_target!(|data: &[u8]| {
// spends is a list of spends
let input = a.new_pair(input, NodePtr::NIL).unwrap();
for flags in &[0, STRICT_ARGS_COUNT, NO_UNKNOWN_CONDS] {
let _ret =
parse_spends::<MempoolVisitor>(&a, input, 33_000_000_000, *flags, &TEST_CONSTANTS);
let _ret = parse_spends::<MempoolVisitor>(
&a,
input,
33_000_000_000,
*flags,
&Signature::default(),
None,
&TEST_CONSTANTS,
);
}
});
5 changes: 5 additions & 0 deletions crates/chia-consensus/fuzz/fuzz_targets/run-generator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![no_main]
use chia_bls::Signature;
use chia_consensus::allocator::make_allocator;
use chia_consensus::consensus_constants::TEST_CONSTANTS;
use chia_consensus::gen::flags::ALLOW_BACKREFS;
Expand All @@ -15,6 +16,8 @@ fuzz_target!(|data: &[u8]| {
[],
110_000_000,
ALLOW_BACKREFS,
&Signature::default(),
None,
&TEST_CONSTANTS,
);
drop(a1);
Expand All @@ -26,6 +29,8 @@ fuzz_target!(|data: &[u8]| {
[],
110_000_000,
ALLOW_BACKREFS,
&Signature::default(),
None,
&TEST_CONSTANTS,
);
drop(a2);
Expand Down
3 changes: 1 addition & 2 deletions crates/chia-consensus/src/fast_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ pub fn fast_forward_singleton(
#[cfg(test)]
mod tests {
use super::*;
use crate::consensus_constants::ConsensusConstants;
use crate::consensus_constants::TEST_CONSTANTS;
use crate::gen::conditions::MempoolVisitor;
use crate::gen::conditions::{
Expand All @@ -173,7 +172,7 @@ mod tests {
use clvmr::chia_dialect::ChiaDialect;
use clvmr::reduction::Reduction;
use clvmr::run_program::run_program;
use clvmr::serde::{node_from_bytes, node_from_bytes_backrefs, node_to_bytes};
use clvmr::serde::{node_from_bytes, node_to_bytes};
use hex_literal::hex;
use rstest::rstest;
use std::fs;
Expand Down
Loading