Skip to content

Commit

Permalink
validate block signature as part of run_block_generator(). There is a…
Browse files Browse the repository at this point in the history
…n opt-out for tests and maybe we'll need it in production too
  • Loading branch information
arvidn committed Oct 8, 2024
1 parent ee48cd2 commit f3dcac8
Show file tree
Hide file tree
Showing 25 changed files with 600 additions and 129 deletions.
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 @@ -72,6 +72,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.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

0 comments on commit f3dcac8

Please sign in to comment.