From 3869222b05e9dec99f24e57b827f0127dcbfc999 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 31 May 2024 17:01:45 +0200 Subject: [PATCH] remove (and unconditionally enable) the NO_RELATIVE_CONDITIONS_ON_EPHEMERAL flag. This soft-fork has activated --- crates/chia-consensus/src/gen/conditions.rs | 81 ++++++++++----------- crates/chia-consensus/src/gen/flags.rs | 4 - wheel/generate_type_stubs.py | 1 - wheel/python/chia_rs/chia_rs.pyi | 1 - wheel/src/api.rs | 8 +- 5 files changed, 39 insertions(+), 56 deletions(-) diff --git a/crates/chia-consensus/src/gen/conditions.rs b/crates/chia-consensus/src/gen/conditions.rs index f752463ce..199b90de6 100644 --- a/crates/chia-consensus/src/gen/conditions.rs +++ b/crates/chia-consensus/src/gen/conditions.rs @@ -18,8 +18,7 @@ use super::sanitize_int::{sanitize_uint, SanitizedUint}; use super::validation_error::{first, next, rest, ErrorCode, ValidationErr}; use crate::consensus_constants::ConsensusConstants; use crate::gen::flags::{ - AGG_SIG_ARGS, COND_ARGS_NIL, DISALLOW_INFINITY_G1, NO_RELATIVE_CONDITIONS_ON_EPHEMERAL, - NO_UNKNOWN_CONDS, STRICT_ARGS_COUNT, + AGG_SIG_ARGS, COND_ARGS_NIL, DISALLOW_INFINITY_G1, NO_UNKNOWN_CONDS, STRICT_ARGS_COUNT, }; use crate::gen::messages::{Message, SpendId}; use crate::gen::spend_visitor::SpendVisitor; @@ -1330,7 +1329,7 @@ pub fn validate_conditions( ret: &SpendBundleConditions, state: ParseState, spends: NodePtr, - flags: u32, + _flags: u32, ) -> Result<(), ValidationErr> { if ret.removal_amount < ret.addition_amount { // The sum of removal amounts must not be less than the sum of addition @@ -1432,15 +1431,15 @@ pub fn validate_conditions( } } - if (flags & NO_RELATIVE_CONDITIONS_ON_EPHEMERAL) != 0 { - for spend_idx in state.assert_not_ephemeral { - // make sure this coin was NOT created in this block - if is_ephemeral(a, spend_idx, &state.spent_coins, &ret.spends) { - return Err(ValidationErr( - ret.spends[spend_idx].parent_id, - ErrorCode::EphemeralRelativeCondition, - )); - } + for spend_idx in state.assert_not_ephemeral { + // make sure this coin was NOT created in this block + // because consensus rules do not allow relative conditions on + // ephemeral spends + if is_ephemeral(a, spend_idx, &state.spent_coins, &ret.spends) { + return Err(ValidationErr( + ret.spends[spend_idx].parent_id, + ErrorCode::EphemeralRelativeCondition, + )); } } @@ -4330,8 +4329,7 @@ fn test_assert_ephemeral_wrong_parent() { )] fn test_relative_condition_on_ephemeral( #[case] condition: ConditionOpcode, - #[case] mut expect_error: Option, - #[values(0, NO_RELATIVE_CONDITIONS_ON_EPHEMERAL)] no_rel_conds_on_ephemeral: u32, + #[case] expect_error: Option, ) { // this test ensures that we disallow relative conditions (including // assert-my-birth conditions) on ephemeral coin spends. @@ -4341,11 +4339,6 @@ fn test_relative_condition_on_ephemeral( let cond = condition as u8; - if no_rel_conds_on_ephemeral == 0 { - // if we allow relative conditions, all cases should pass - expect_error = None; - } - // the coin11 value is the coinID computed from (H1, H1, 123). // coin11 is the first coin we spend in this case. // 51 is CREATE_COIN @@ -4360,34 +4353,34 @@ fn test_relative_condition_on_ephemeral( ))" ); - let flags = no_rel_conds_on_ephemeral; - - if let Some(err) = expect_error { - assert_eq!(cond_test_flag(&test, flags).unwrap_err().1, err); - return; - } - - // we don't expect any error - let (a, conds) = cond_test_flag(&test, flags).unwrap(); + match expect_error { + Some(err) => { + assert_eq!(cond_test(&test).unwrap_err().1, err); + } + None => { + // we don't expect any error + let (a, conds) = cond_test(&test).unwrap(); - assert_eq!(conds.reserve_fee, 0); - assert_eq!(conds.cost, CREATE_COIN_COST); + assert_eq!(conds.reserve_fee, 0); + assert_eq!(conds.cost, CREATE_COIN_COST); - assert_eq!(conds.spends.len(), 2); - let spend = &conds.spends[0]; - assert_eq!(*spend.coin_id, test_coin_id(H1, H1, 123)); - assert_eq!(a.atom(spend.puzzle_hash).as_ref(), H1); - assert_eq!(spend.agg_sig_me.len(), 0); - assert_eq!(spend.flags, ELIGIBLE_FOR_DEDUP); + assert_eq!(conds.spends.len(), 2); + let spend = &conds.spends[0]; + assert_eq!(*spend.coin_id, test_coin_id(H1, H1, 123)); + assert_eq!(a.atom(spend.puzzle_hash).as_ref(), H1); + assert_eq!(spend.agg_sig_me.len(), 0); + assert_eq!(spend.flags, ELIGIBLE_FOR_DEDUP); - let spend = &conds.spends[1]; - assert_eq!( - *spend.coin_id, - test_coin_id((&(*conds.spends[0].coin_id)).into(), H2, 123) - ); - assert_eq!(a.atom(spend.puzzle_hash).as_ref(), H2); - assert_eq!(spend.agg_sig_me.len(), 0); - assert!((spend.flags & ELIGIBLE_FOR_DEDUP) != 0); + let spend = &conds.spends[1]; + assert_eq!( + *spend.coin_id, + test_coin_id((&(*conds.spends[0].coin_id)).into(), H2, 123) + ); + assert_eq!(a.atom(spend.puzzle_hash).as_ref(), H2); + assert_eq!(spend.agg_sig_me.len(), 0); + assert!((spend.flags & ELIGIBLE_FOR_DEDUP) != 0); + } + } } #[cfg(test)] diff --git a/crates/chia-consensus/src/gen/flags.rs b/crates/chia-consensus/src/gen/flags.rs index aa3720810..03f28ade6 100644 --- a/crates/chia-consensus/src/gen/flags.rs +++ b/crates/chia-consensus/src/gen/flags.rs @@ -14,9 +14,6 @@ pub const COND_ARGS_NIL: u32 = 0x40000; // currently supported for those conditions. This is meant for mempool-mode pub const STRICT_ARGS_COUNT: u32 = 0x80000; -// disallow relative height- and time conditions on ephemeral spends -pub const NO_RELATIVE_CONDITIONS_ON_EPHEMERAL: u32 = 0x0020_0000; - // enable softfork condition. Enabling this flag is a hard fork pub const ENABLE_SOFTFORK_CONDITION: u32 = 0x0040_0000; @@ -46,7 +43,6 @@ pub const MEMPOOL_MODE: u32 = CLVM_MEMPOOL_MODE | NO_UNKNOWN_CONDS | COND_ARGS_NIL | STRICT_ARGS_COUNT - | NO_RELATIVE_CONDITIONS_ON_EPHEMERAL | ANALYZE_SPENDS | ENABLE_MESSAGE_CONDITIONS | DISALLOW_INFINITY_G1; diff --git a/wheel/generate_type_stubs.py b/wheel/generate_type_stubs.py index d352d9ee7..91ef41b71 100644 --- a/wheel/generate_type_stubs.py +++ b/wheel/generate_type_stubs.py @@ -315,7 +315,6 @@ def confirm_not_included_already_hashed( ENABLE_MESSAGE_CONDITIONS: int = ... DISALLOW_INFINITY_G1: int = ... MEMPOOL_MODE: int = ... -NO_RELATIVE_CONDITIONS_ON_EPHEMERAL: int = ... ENABLE_BLS_OPS: int = ... ENABLE_SECP_OPS: int = ... ENABLE_BLS_OPS_OUTSIDE_GUARD: int = ... diff --git a/wheel/python/chia_rs/chia_rs.pyi b/wheel/python/chia_rs/chia_rs.pyi index 328cc80fe..5659dedd0 100644 --- a/wheel/python/chia_rs/chia_rs.pyi +++ b/wheel/python/chia_rs/chia_rs.pyi @@ -58,7 +58,6 @@ ENABLE_SOFTFORK_CONDITION: int = ... ENABLE_MESSAGE_CONDITIONS: int = ... DISALLOW_INFINITY_G1: int = ... MEMPOOL_MODE: int = ... -NO_RELATIVE_CONDITIONS_ON_EPHEMERAL: int = ... ENABLE_BLS_OPS: int = ... ENABLE_SECP_OPS: int = ... ENABLE_BLS_OPS_OUTSIDE_GUARD: int = ... diff --git a/wheel/src/api.rs b/wheel/src/api.rs index 6af8cf7fb..650e1812b 100644 --- a/wheel/src/api.rs +++ b/wheel/src/api.rs @@ -4,8 +4,8 @@ use chia_consensus::consensus_constants::ConsensusConstants; use chia_consensus::gen::conditions::MempoolVisitor; use chia_consensus::gen::flags::{ AGG_SIG_ARGS, ALLOW_BACKREFS, ANALYZE_SPENDS, COND_ARGS_NIL, DISALLOW_INFINITY_G1, - ENABLE_MESSAGE_CONDITIONS, ENABLE_SOFTFORK_CONDITION, MEMPOOL_MODE, - NO_RELATIVE_CONDITIONS_ON_EPHEMERAL, NO_UNKNOWN_CONDS, STRICT_ARGS_COUNT, + ENABLE_MESSAGE_CONDITIONS, ENABLE_SOFTFORK_CONDITION, MEMPOOL_MODE, NO_UNKNOWN_CONDS, + STRICT_ARGS_COUNT, }; use chia_consensus::gen::owned_conditions::{OwnedSpend, OwnedSpendBundleConditions}; use chia_consensus::gen::run_puzzle::run_puzzle as native_run_puzzle; @@ -402,10 +402,6 @@ pub fn chia_rs(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add("ENABLE_FIXED_DIV", ENABLE_FIXED_DIV)?; m.add("ENABLE_SOFTFORK_CONDITION", ENABLE_SOFTFORK_CONDITION)?; m.add("ENABLE_MESSAGE_CONDITIONS", ENABLE_MESSAGE_CONDITIONS)?; - m.add( - "NO_RELATIVE_CONDITIONS_ON_EPHEMERAL", - NO_RELATIVE_CONDITIONS_ON_EPHEMERAL, - )?; m.add("MEMPOOL_MODE", MEMPOOL_MODE)?; m.add("ALLOW_BACKREFS", ALLOW_BACKREFS)?; m.add("ANALYZE_SPENDS", ANALYZE_SPENDS)?;