Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Oct 9, 2024
1 parent 082f6ef commit e6414dd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
32 changes: 14 additions & 18 deletions crates/chia-consensus/src/gen/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::gen::messages::{Message, SpendId};
use crate::gen::spend_visitor::SpendVisitor;
use crate::gen::validation_error::check_nil;
use chia_bls::{aggregate_verify, BlsCache, PublicKey, Signature};
use chia_protocol::Bytes32;
use chia_protocol::{Bytes, Bytes32};
use chia_sha2::Sha256;
use clvmr::allocator::{Allocator, NodePtr, SExp};
use clvmr::cost::Cost;
Expand Down Expand Up @@ -785,7 +785,7 @@ pub struct ParseState {
// DONT_VALIDATE_SIGNATURE flag is set
// TODO: We would probably save heap allocations by turning this into a
// blst_pairing object.
pub pkm_pairs: Vec<(PublicKey, Vec<u8>)>,
pub pkm_pairs: Vec<(PublicKey, Bytes)>,
}

// returns (parent-id, puzzle-hash, amount, condition-list)
Expand Down Expand Up @@ -1136,7 +1136,7 @@ pub fn parse_conditions<V: SpendVisitor>(
let mut msg = a.atom(msg).as_ref().to_vec();
msg.extend((*spend.coin_id).as_slice());
msg.extend(constants.agg_sig_me_additional_data.as_slice());
state.pkm_pairs.push((to_key(a, pk)?, msg));
state.pkm_pairs.push((to_key(a, pk)?, msg.into()));
}
}
Condition::AggSigParent(pk, msg) => {
Expand All @@ -1145,7 +1145,7 @@ pub fn parse_conditions<V: SpendVisitor>(
let mut msg = a.atom(msg).as_ref().to_vec();
msg.extend(a.atom(spend.parent_id).as_ref());
msg.extend(constants.agg_sig_parent_additional_data.as_slice());
state.pkm_pairs.push((to_key(a, pk)?, msg));
state.pkm_pairs.push((to_key(a, pk)?, msg.into()));
}
}
Condition::AggSigPuzzle(pk, msg) => {
Expand All @@ -1154,7 +1154,7 @@ pub fn parse_conditions<V: SpendVisitor>(
let mut msg = a.atom(msg).as_ref().to_vec();
msg.extend(a.atom(spend.puzzle_hash).as_ref());
msg.extend(constants.agg_sig_puzzle_additional_data.as_slice());
state.pkm_pairs.push((to_key(a, pk)?, msg));
state.pkm_pairs.push((to_key(a, pk)?, msg.into()));
}
}
Condition::AggSigAmount(pk, msg) => {
Expand All @@ -1163,7 +1163,7 @@ pub fn parse_conditions<V: SpendVisitor>(
let mut msg = a.atom(msg).as_ref().to_vec();
msg.extend(u64_to_bytes(spend.coin_amount).as_slice());
msg.extend(constants.agg_sig_amount_additional_data.as_slice());
state.pkm_pairs.push((to_key(a, pk)?, msg));
state.pkm_pairs.push((to_key(a, pk)?, msg.into()));
}
}
Condition::AggSigPuzzleAmount(pk, msg) => {
Expand All @@ -1173,7 +1173,7 @@ pub fn parse_conditions<V: SpendVisitor>(
msg.extend(a.atom(spend.puzzle_hash).as_ref());
msg.extend(u64_to_bytes(spend.coin_amount).as_slice());
msg.extend(constants.agg_sig_puzzle_amount_additional_data.as_slice());
state.pkm_pairs.push((to_key(a, pk)?, msg));
state.pkm_pairs.push((to_key(a, pk)?, msg.into()));
}
}
Condition::AggSigParentAmount(pk, msg) => {
Expand All @@ -1183,7 +1183,7 @@ pub fn parse_conditions<V: SpendVisitor>(
msg.extend(a.atom(spend.parent_id).as_ref());
msg.extend(u64_to_bytes(spend.coin_amount).as_slice());
msg.extend(constants.agg_sig_parent_amount_additional_data.as_slice());
state.pkm_pairs.push((to_key(a, pk)?, msg));
state.pkm_pairs.push((to_key(a, pk)?, msg.into()));
}
}
Condition::AggSigParentPuzzle(pk, msg) => {
Expand All @@ -1193,7 +1193,7 @@ pub fn parse_conditions<V: SpendVisitor>(
msg.extend(a.atom(spend.parent_id).as_ref());
msg.extend(a.atom(spend.puzzle_hash).as_ref());
msg.extend(constants.agg_sig_parent_puzzle_additional_data.as_slice());
state.pkm_pairs.push((to_key(a, pk)?, msg));
state.pkm_pairs.push((to_key(a, pk)?, msg.into()));
}
}
Condition::AggSigUnsafe(pk, msg) => {
Expand All @@ -1204,7 +1204,7 @@ pub fn parse_conditions<V: SpendVisitor>(
if (flags & DONT_VALIDATE_SIGNATURE) == 0 {
state
.pkm_pairs
.push((to_key(a, pk)?, a.atom(msg).as_ref().to_vec()));
.push((to_key(a, pk)?, a.atom(msg).as_ref().to_vec().into()));
}
}
Condition::Softfork(cost) => {
Expand Down Expand Up @@ -4760,14 +4760,10 @@ fn test_agg_sig(
b"foobar",
));
}
match cond_test_sig(puzzle.as_str(), &signature, cache, 0) {
Ok(..) => {
assert!(expect_pass);
}
Err(..) => {
assert!(!expect_pass);
}
}
assert_eq!(
expect_pass,
cond_test_sig(puzzle.as_str(), &signature, cache, 0).is_ok()
);
}

// the message condition takes a mode-parameter. This is a 6-bit integer that
Expand Down
4 changes: 2 additions & 2 deletions crates/chia-consensus/src/spendbundle_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::gen::solution_generator::calculate_generator_length;
use crate::gen::validation_error::ValidationErr;
use crate::spendbundle_validation::get_flags_for_height_and_constants;
use chia_bls::PublicKey;
use chia_protocol::SpendBundle;
use chia_protocol::{Bytes, SpendBundle};
use clvm_utils::tree_hash;
use clvmr::allocator::Allocator;
use clvmr::chia_dialect::ChiaDialect;
Expand Down Expand Up @@ -46,7 +46,7 @@ pub fn run_spendbundle(
height: u32,
flags: u32,
constants: &ConsensusConstants,
) -> Result<(SpendBundleConditions, Vec<(PublicKey, Vec<u8>)>), ValidationErr> {
) -> Result<(SpendBundleConditions, Vec<(PublicKey, Bytes)>), ValidationErr> {
let flags = get_flags_for_height_and_constants(height, constants) | flags | MEMPOOL_MODE;

// below is an adapted version of the code from run_block_generators::run_block_generator2()
Expand Down
2 changes: 1 addition & 1 deletion crates/chia-consensus/src/spendbundle_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn validate_clvm_and_signature(
for (pk, msg) in pkm_pairs {
aug_msg.clear();
aug_msg.extend_from_slice(&pk.to_bytes());
aug_msg.extend(&msg);
aug_msg.extend(&*msg);
let aug_hash = hash_to_g2(&aug_msg);
let pairing = aug_hash.pair(&pk);

Expand Down

0 comments on commit e6414dd

Please sign in to comment.