Skip to content

Commit

Permalink
remove ENABLE_SOFTFORK_CONDITION flag. enable it unconditionally (sin…
Browse files Browse the repository at this point in the history
…ce the hard fork has activated)
  • Loading branch information
arvidn committed Jul 8, 2024
1 parent 2a38a3f commit dc4494e
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 156 deletions.
11 changes: 2 additions & 9 deletions crates/chia-consensus/fuzz/fuzz_targets/parse-cond-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use chia_consensus::gen::conditions::parse_args;
use clvmr::allocator::Allocator;
use fuzzing_utils::{make_list, BitCursor};

use chia_consensus::gen::flags::{
ENABLE_MESSAGE_CONDITIONS, ENABLE_SOFTFORK_CONDITION, STRICT_ARGS_COUNT,
};
use chia_consensus::gen::flags::{ENABLE_MESSAGE_CONDITIONS, STRICT_ARGS_COUNT};

use chia_consensus::gen::opcodes::{
AGG_SIG_AMOUNT, AGG_SIG_ME, AGG_SIG_PARENT, AGG_SIG_PARENT_AMOUNT, AGG_SIG_PARENT_PUZZLE,
Expand All @@ -22,12 +20,7 @@ fuzz_target!(|data: &[u8]| {
let mut a = Allocator::new();
let input = make_list(&mut a, &mut BitCursor::new(data));

for flags in &[
0,
STRICT_ARGS_COUNT,
ENABLE_SOFTFORK_CONDITION,
ENABLE_MESSAGE_CONDITIONS,
] {
for flags in &[0, STRICT_ARGS_COUNT, ENABLE_MESSAGE_CONDITIONS] {
for op in &[
AGG_SIG_ME,
AGG_SIG_UNSAFE,
Expand Down
5 changes: 1 addition & 4 deletions crates/chia-consensus/fuzz/fuzz_targets/parse-conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use fuzzing_utils::{make_list, BitCursor};
use std::collections::HashSet;
use std::sync::Arc;

use chia_consensus::gen::flags::{
ENABLE_MESSAGE_CONDITIONS, ENABLE_SOFTFORK_CONDITION, NO_UNKNOWN_CONDS, STRICT_ARGS_COUNT,
};
use chia_consensus::gen::flags::{ENABLE_MESSAGE_CONDITIONS, NO_UNKNOWN_CONDS, STRICT_ARGS_COUNT};

fuzz_target!(|data: &[u8]| {
let mut a = Allocator::new();
Expand Down Expand Up @@ -46,7 +44,6 @@ fuzz_target!(|data: &[u8]| {
0,
STRICT_ARGS_COUNT,
NO_UNKNOWN_CONDS,
ENABLE_SOFTFORK_CONDITION,
ENABLE_MESSAGE_CONDITIONS,
] {
let mut coin_spend = Spend {
Expand Down
5 changes: 1 addition & 4 deletions crates/chia-consensus/fuzz/fuzz_targets/parse-spends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use clvmr::{Allocator, NodePtr};
use fuzzing_utils::{make_list, BitCursor};

use chia_consensus::consensus_constants::TEST_CONSTANTS;
use chia_consensus::gen::flags::{
ENABLE_MESSAGE_CONDITIONS, ENABLE_SOFTFORK_CONDITION, NO_UNKNOWN_CONDS, STRICT_ARGS_COUNT,
};
use chia_consensus::gen::flags::{ENABLE_MESSAGE_CONDITIONS, NO_UNKNOWN_CONDS, STRICT_ARGS_COUNT};

fuzz_target!(|data: &[u8]| {
let mut a = Allocator::new();
Expand All @@ -19,7 +17,6 @@ fuzz_target!(|data: &[u8]| {
0,
STRICT_ARGS_COUNT,
NO_UNKNOWN_CONDS,
ENABLE_SOFTFORK_CONDITION,
ENABLE_MESSAGE_CONDITIONS,
] {
let _ret =
Expand Down
78 changes: 20 additions & 58 deletions crates/chia-consensus/src/gen/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ pub fn parse_args(
}
256..=65535 => {
// All of these conditions are unknown
// but they have costs (when ENABLE_SOFTFORK_CONDITION is enabled)
// but they have costs
if (flags & NO_UNKNOWN_CONDS) != 0 {
Err(ValidationErr(c, ErrorCode::InvalidConditionOpcode))
} else {
Expand Down Expand Up @@ -1470,8 +1470,6 @@ fn u64_to_bytes(n: u64) -> Vec<u8> {
#[cfg(test)]
use crate::consensus_constants::TEST_CONSTANTS;
#[cfg(test)]
use crate::gen::flags::ENABLE_SOFTFORK_CONDITION;
#[cfg(test)]
use clvmr::number::Number;
#[cfg(test)]
use clvmr::serde::node_to_bytes;
Expand Down Expand Up @@ -1888,7 +1886,7 @@ fn test_strict_args_count(
"((({{h1}} ({{h2}} (123 ((({} ({} ( 1337 )))))",
condition as u8, arg
),
flags | ENABLE_SOFTFORK_CONDITION,
flags,
);
if flags == 0 {
// two of the cases won't pass, even when garbage at the end is allowed.
Expand Down Expand Up @@ -1933,7 +1931,7 @@ fn test_message_strict_args_count(
&format!(
"((({{h1}} ({{h2}} (123 (((66 ({mode} ({msg} {arg} {extra1} ) ((67 ({mode} ({msg} {extra2} ) ))))"
),
flags | ENABLE_SOFTFORK_CONDITION | ENABLE_MESSAGE_CONDITIONS,
flags | ENABLE_MESSAGE_CONDITIONS,
);
if flags == 0 {
ret.unwrap();
Expand Down Expand Up @@ -1985,7 +1983,7 @@ fn test_extra_arg(
"((({{h1}} ({{h2}} (123 ((({} ({} ( 1337 ) {} ))))",
condition as u8, arg, extra_cond
),
ENABLE_SOFTFORK_CONDITION | MEMPOOL_MODE,
MEMPOOL_MODE,
)
.unwrap_err()
.1,
Expand All @@ -1997,7 +1995,7 @@ fn test_extra_arg(
"((({{h1}} ({{h2}} (123 ((({} ({} ( 1337 ) {} ))))",
condition as u8, arg, extra_cond
),
ENABLE_SOFTFORK_CONDITION,
0,
)
.unwrap();

Expand Down Expand Up @@ -2252,7 +2250,7 @@ fn test_missing_arg(#[case] condition: ConditionOpcode) {
assert_eq!(
cond_test_flag(
&format!("((({{h1}} ({{h2}} (123 ((({} )))))", condition as u8),
ENABLE_SOFTFORK_CONDITION
0
)
.unwrap_err()
.1,
Expand Down Expand Up @@ -3030,7 +3028,7 @@ fn test_single_agg_sig_me(
) {
let (a, conds) = cond_test_flag(
&format!("((({{h1}} ({{h2}} (123 ((({condition} ({{pubkey}} ({{msg1}} )))))"),
ENABLE_SOFTFORK_CONDITION | mempool,
mempool,
)
.unwrap();

Expand Down Expand Up @@ -3068,7 +3066,7 @@ fn test_duplicate_agg_sig(
// aggregated, and so must all copies of the public keys
let (a, conds) =
cond_test_flag(&format!("((({{h1}} ({{h2}} (123 ((({} ({{pubkey}} ({{msg1}} ) (({} ({{pubkey}} ({{msg1}} ) ))))", condition as u8, condition as u8),
ENABLE_SOFTFORK_CONDITION | mempool)
mempool)
.unwrap();

assert_eq!(conds.cost, AGG_SIG_COST * 2);
Expand Down Expand Up @@ -3108,7 +3106,7 @@ fn test_agg_sig_invalid_pubkey(
"((({{h1}} ({{h2}} (123 ((({} ({{h2}} ({{msg1}} )))))",
condition as u8
),
ENABLE_SOFTFORK_CONDITION | mempool
mempool
)
.unwrap_err()
.1,
Expand All @@ -3135,7 +3133,7 @@ fn test_agg_sig_infinity_pubkey(
"((({{h1}} ({{h2}} (123 ((({} (0xc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ({{msg1}} )))))",
condition as u8
),
ENABLE_SOFTFORK_CONDITION | mempool
mempool
);

if mempool != 0 {
Expand Down Expand Up @@ -3174,7 +3172,7 @@ fn test_agg_sig_invalid_msg(
"((({{h1}} ({{h2}} (123 ((({} ({{pubkey}} ({{longmsg}} )))))",
condition as u8
),
ENABLE_SOFTFORK_CONDITION | mempool
mempool
)
.unwrap_err()
.1,
Expand All @@ -3196,7 +3194,7 @@ fn test_agg_sig_exceed_cost(#[case] condition: ConditionOpcode) {
assert_eq!(
cond_test_cb(
"((({h1} ({h2} (123 ({} )))",
ENABLE_SOFTFORK_CONDITION,
0,
Some(Box::new(move |a: &mut Allocator| -> NodePtr {
let mut rest: NodePtr = a.nil();

Expand Down Expand Up @@ -3260,7 +3258,7 @@ fn test_agg_sig_extra_arg(#[case] condition: ConditionOpcode) {
"((({{h1}} ({{h2}} (123 ((({} ({{pubkey}} ({{msg1}} ( 1337 ) ))))",
condition as u8
),
ENABLE_SOFTFORK_CONDITION,
0,
)
.unwrap();

Expand All @@ -3283,7 +3281,7 @@ fn test_agg_sig_extra_arg(#[case] condition: ConditionOpcode) {
"((({{h1}} ({{h2}} (123 ((({} ({{pubkey}} ({{msg1}} ( 1337 ) ))))",
condition as u8
),
MEMPOOL_MODE | ENABLE_SOFTFORK_CONDITION,
MEMPOOL_MODE,
)
.unwrap_err()
.1,
Expand Down Expand Up @@ -3406,7 +3404,7 @@ fn test_agg_sig_unsafe_invalid_msg(
) {
let ret = cond_test_flag(
format!("((({{h1}} ({{h2}} (123 ((({opcode} ({{pubkey}} ({msg} )))))").as_str(),
ENABLE_SOFTFORK_CONDITION,
0,
);
if opcode == AGG_SIG_UNSAFE {
assert_eq!(ret.unwrap_err().1, ErrorCode::InvalidMessage);
Expand Down Expand Up @@ -4282,42 +4280,9 @@ fn test_relative_condition_on_ephemeral(
#[case("((0xff01 )", 106)]
fn test_softfork_condition(#[case] conditions: &str, #[case] expected_cost: Cost) {
// SOFTFORK (90)
let (_, spends) = cond_test_flag(
&format!("((({{h1}} ({{h2}} (1234 ({conditions}))))"),
ENABLE_SOFTFORK_CONDITION,
)
.unwrap();
assert_eq!(spends.cost, expected_cost);

// when NO_UNKNOWN_CONDS is enabled, any SOFTFORK condition is an error
// (because we don't know of any yet)
assert_eq!(
cond_test_flag(
&format!("((({{h1}} ({{h2}} (1234 ({conditions}))))"),
ENABLE_SOFTFORK_CONDITION | NO_UNKNOWN_CONDS
)
.unwrap_err()
.1,
ErrorCode::InvalidConditionOpcode
);

// if softfork conditions aren't enabled, they are just plain unknown
// conditions (that don't incur a cost
let (_, spends) =
cond_test_flag(&format!("((({{h1}} ({{h2}} (1234 ({conditions}))))"), 0).unwrap();
assert_eq!(spends.cost, 0);

// if softfork conditions aren't enabled, but we don't allow unknown
// conditions (mempool mode) they fail
assert_eq!(
cond_test_flag(
&format!("((({{h1}} ({{h2}} (1234 ({conditions}))))"),
NO_UNKNOWN_CONDS
)
.unwrap_err()
.1,
ErrorCode::InvalidConditionOpcode
);
assert_eq!(spends.cost, expected_cost);
}

#[cfg(test)]
Expand All @@ -4332,12 +4297,9 @@ fn test_softfork_condition(#[case] conditions: &str, #[case] expected_cost: Cost
fn test_softfork_condition_failures(#[case] conditions: &str, #[case] expected_err: ErrorCode) {
// SOFTFORK (90)
assert_eq!(
cond_test_flag(
&format!("((({{h1}} ({{h2}} (1234 ({conditions}))))"),
ENABLE_SOFTFORK_CONDITION
)
.unwrap_err()
.1,
cond_test_flag(&format!("((({{h1}} ({{h2}} (1234 ({conditions}))))"), 0)
.unwrap_err()
.1,
expected_err
);
}
Expand Down Expand Up @@ -4536,7 +4498,7 @@ fn test_eligible_for_ff_invalid_agg_sig_me(
))"
);

let (_a, cond) = cond_test_flag(test, ENABLE_SOFTFORK_CONDITION).expect("cond_test");
let (_a, cond) = cond_test_flag(test, 0).expect("cond_test");
assert!(cond.spends.len() == 1);
let flags = cond.spends[0].flags;
if eligible {
Expand Down
3 changes: 0 additions & 3 deletions crates/chia-consensus/src/gen/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ pub const NO_UNKNOWN_CONDS: u32 = 0x20000;
// currently supported for those conditions. This is meant for mempool-mode
pub const STRICT_ARGS_COUNT: u32 = 0x80000;

// enable softfork condition. Enabling this flag is a hard fork
pub const ENABLE_SOFTFORK_CONDITION: u32 = 0x0040_0000;

// when this flag is set, the block generator serialization is allowed to
// contain back-references
pub const ALLOW_BACKREFS: u32 = 0x0200_0000;
Expand Down
Loading

0 comments on commit dc4494e

Please sign in to comment.