Skip to content

Commit

Permalink
remove (and unconditionally enable) the NO_RELATIVE_CONDITIONS_ON_EPH…
Browse files Browse the repository at this point in the history
…EMERAL flag. This soft-fork has activated
  • Loading branch information
arvidn committed Jun 4, 2024
1 parent a521169 commit 3869222
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 56 deletions.
81 changes: 37 additions & 44 deletions crates/chia-consensus/src/gen/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
));
}
}

Expand Down Expand Up @@ -4330,8 +4329,7 @@ fn test_assert_ephemeral_wrong_parent() {
)]
fn test_relative_condition_on_ephemeral(
#[case] condition: ConditionOpcode,
#[case] mut expect_error: Option<ErrorCode>,
#[values(0, NO_RELATIVE_CONDITIONS_ON_EPHEMERAL)] no_rel_conds_on_ephemeral: u32,
#[case] expect_error: Option<ErrorCode>,
) {
// this test ensures that we disallow relative conditions (including
// assert-my-birth conditions) on ephemeral coin spends.
Expand All @@ -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
Expand All @@ -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)]
Expand Down
4 changes: 0 additions & 4 deletions crates/chia-consensus/src/gen/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
1 change: 0 additions & 1 deletion wheel/generate_type_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...
Expand Down
1 change: 0 additions & 1 deletion wheel/python/chia_rs/chia_rs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...
Expand Down
8 changes: 2 additions & 6 deletions wheel/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)?;
Expand Down

0 comments on commit 3869222

Please sign in to comment.