Skip to content

Commit

Permalink
Merge pull request #326 from Chia-Network/limit-announces
Browse files Browse the repository at this point in the history
enable LIMIT_ANNOUNCES unconditionally
  • Loading branch information
arvidn authored Nov 30, 2023
2 parents e4a4512 + a8cc9c3 commit b4da25b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 88 deletions.
6 changes: 1 addition & 5 deletions generator-tests/duplicate-coin-announce.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
ff01ffffffa00101010101010101010101010101010101010101010101010101010101010101ffff02ffff01ff02ff04ffff04ff02ffff04ffff04ffff013cffff04ffff02ff06ffff04ff02ffff04ff05ff80808080ff808080ffff04ff0bff8080808080ffff04ffff01ffff02ffff03ff0bffff01ff04ff05ffff02ff04ffff04ff02ffff04ff05ffff04ffff11ff0bffff010180ff808080808080ff8080ff0180ff17ffff0161ff0580ffff01ff821ff8ff835aca30808080ff7bffff80ffff018080808080
SPENDS:
- coin id: f57957e3b245f232d0674608664a26de273e59ecdc4caa6f137dabf81ace66bd ph: 6518aeb99223230501dc1b875fe7cd52f5d27b70db50e17a10159b5e6f814d06
cost: 10057710909
removal_amount: 123
addition_amount: 0
FAILED: 144
STRICT:
FAILED: 117
77 changes: 10 additions & 67 deletions src/gen/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use super::opcodes::{
use super::sanitize_int::{sanitize_uint, SanitizedUint};
use super::validation_error::{first, next, rest, ErrorCode, ValidationErr};
use crate::gen::flags::{
AGG_SIG_ARGS, COND_ARGS_NIL, LIMIT_ANNOUNCES, NO_RELATIVE_CONDITIONS_ON_EPHEMERAL,
NO_UNKNOWN_CONDS, STRICT_ARGS_COUNT,
AGG_SIG_ARGS, COND_ARGS_NIL, NO_RELATIVE_CONDITIONS_ON_EPHEMERAL, NO_UNKNOWN_CONDS,
STRICT_ARGS_COUNT,
};
use crate::gen::spend_visitor::SpendVisitor;
use crate::gen::validation_error::check_nil;
Expand Down Expand Up @@ -834,11 +834,7 @@ pub fn parse_conditions<V: SpendVisitor>(
max_cost: &mut Cost,
visitor: &mut V,
) -> Result<(), ValidationErr> {
let mut announce_countdown: u32 = if (flags & LIMIT_ANNOUNCES) != 0 {
1024
} else {
u32::MAX
};
let mut announce_countdown: u32 = 1024;

while let Some((mut c, next)) = next(a, iter)? {
iter = next;
Expand Down Expand Up @@ -4200,103 +4196,50 @@ fn test_softfork_condition_failures(#[case] conditions: &str, #[case] expected_e

#[cfg(test)]
#[rstest]
#[case(CREATE_PUZZLE_ANNOUNCEMENT, 1000, LIMIT_ANNOUNCES, None)]
#[case(CREATE_PUZZLE_ANNOUNCEMENT, 1000, None)]
#[case(
CREATE_PUZZLE_ANNOUNCEMENT,
1025,
LIMIT_ANNOUNCES,
Some(ErrorCode::TooManyAnnouncements)
)]
#[case(
ASSERT_PUZZLE_ANNOUNCEMENT,
1024,
LIMIT_ANNOUNCES,
Some(ErrorCode::AssertPuzzleAnnouncementFailed)
)]
#[case(
ASSERT_PUZZLE_ANNOUNCEMENT,
1025,
LIMIT_ANNOUNCES,
Some(ErrorCode::TooManyAnnouncements)
)]
#[case(CREATE_COIN_ANNOUNCEMENT, 1000, LIMIT_ANNOUNCES, None)]
#[case(
CREATE_COIN_ANNOUNCEMENT,
1025,
LIMIT_ANNOUNCES,
Some(ErrorCode::TooManyAnnouncements)
)]
#[case(CREATE_COIN_ANNOUNCEMENT, 1000, None)]
#[case(CREATE_COIN_ANNOUNCEMENT, 1025, Some(ErrorCode::TooManyAnnouncements))]
#[case(
ASSERT_COIN_ANNOUNCEMENT,
1024,
LIMIT_ANNOUNCES,
Some(ErrorCode::AssertCoinAnnouncementFailed)
)]
#[case(
ASSERT_COIN_ANNOUNCEMENT,
1025,
LIMIT_ANNOUNCES,
Some(ErrorCode::TooManyAnnouncements)
)]
#[case(ASSERT_COIN_ANNOUNCEMENT, 1025, Some(ErrorCode::TooManyAnnouncements))]
#[case(
ASSERT_CONCURRENT_SPEND,
1024,
LIMIT_ANNOUNCES,
Some(ErrorCode::AssertConcurrentSpendFailed)
)]
#[case(
ASSERT_CONCURRENT_SPEND,
1025,
LIMIT_ANNOUNCES,
Some(ErrorCode::TooManyAnnouncements)
)]
#[case(ASSERT_CONCURRENT_SPEND, 1025, Some(ErrorCode::TooManyAnnouncements))]
#[case(
ASSERT_CONCURRENT_PUZZLE,
1024,
LIMIT_ANNOUNCES,
Some(ErrorCode::AssertConcurrentPuzzleFailed)
)]
#[case(
ASSERT_CONCURRENT_PUZZLE,
1025,
LIMIT_ANNOUNCES,
Some(ErrorCode::TooManyAnnouncements)
)]
#[case(CREATE_PUZZLE_ANNOUNCEMENT, 1025, 0, None)]
#[case(
ASSERT_PUZZLE_ANNOUNCEMENT,
1025,
0,
Some(ErrorCode::AssertPuzzleAnnouncementFailed)
)]
#[case(CREATE_COIN_ANNOUNCEMENT, 1025, 0, None)]
#[case(
ASSERT_COIN_ANNOUNCEMENT,
1025,
0,
Some(ErrorCode::AssertCoinAnnouncementFailed)
)]
#[case(
ASSERT_CONCURRENT_SPEND,
1025,
0,
Some(ErrorCode::AssertConcurrentSpendFailed)
)]
#[case(
ASSERT_CONCURRENT_PUZZLE,
1025,
0,
Some(ErrorCode::AssertConcurrentPuzzleFailed)
)]
#[case(ASSERT_CONCURRENT_PUZZLE, 1025, Some(ErrorCode::TooManyAnnouncements))]
fn test_limit_announcements(
#[case] cond: ConditionOpcode,
#[case] count: i32,
#[case] flags: u32,
#[case] expect_err: Option<ErrorCode>,
) {
let r = cond_test_cb(
"((({h1} ({h1} (123 ({} )))",
flags,
0,
Some(Box::new(move |a: &mut Allocator| -> NodePtr {
let mut rest: NodePtr = a.null();

Expand Down
11 changes: 0 additions & 11 deletions src/gen/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ pub const ENABLE_SOFTFORK_CONDITION: u32 = 0x400000;
// normal, just like all other conditions. Setting this flag is a hard fork
pub const AGG_SIG_ARGS: u32 = 0x800000;

// When enabled, each spend is limited in the number of announcements it is
// allowed to create and assert, to no more than 1000. This includes:
// CREATE_COIN_ANNOUNCEMENT
// CREATE_PUZZLE_ANNOUNCEMENT
// ASSERT_COIN_ANNOUNCEMENT
// ASSERT_PUZZLE_ANNOUNCEMENT
// ASSERT_CONCURRENT_SPEND
// ASSERT_CONCURRENT_PUZZLE
pub const LIMIT_ANNOUNCES: u32 = 0x1000000;

// when this flag is set, the block generator serialization is allowed to
// contain back-references
pub const ALLOW_BACKREFS: u32 = 0x2000000;
Expand All @@ -54,5 +44,4 @@ pub const MEMPOOL_MODE: u32 = CLVM_MEMPOOL_MODE
| COND_ARGS_NIL
| STRICT_ARGS_COUNT
| NO_RELATIVE_CONDITIONS_ON_EPHEMERAL
| LIMIT_ANNOUNCES
| ANALYZE_SPENDS;
1 change: 0 additions & 1 deletion wheel/chia_rs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def run_puzzle(
COND_ARGS_NIL: int = ...
NO_UNKNOWN_CONDS: int = ...
STRICT_ARGS_COUNT: int = ...
LIMIT_ANNOUNCES: int = ...
AGG_SIG_ARGS: int = ...
LIMIT_HEAP: int = ...
ENABLE_SOFTFORK_CONDITION: int = ...
Expand Down
1 change: 0 additions & 1 deletion wheel/generate_type_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ def run_puzzle(
COND_ARGS_NIL: int = ...
NO_UNKNOWN_CONDS: int = ...
STRICT_ARGS_COUNT: int = ...
LIMIT_ANNOUNCES: int = ...
AGG_SIG_ARGS: int = ...
LIMIT_HEAP: int = ...
ENABLE_SOFTFORK_CONDITION: int = ...
Expand Down
5 changes: 2 additions & 3 deletions wheel/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use chia::allocator::make_allocator;
use chia::gen::conditions::MempoolVisitor;
use chia::gen::flags::{
AGG_SIG_ARGS, ALLOW_BACKREFS, ANALYZE_SPENDS, COND_ARGS_NIL, ENABLE_SOFTFORK_CONDITION,
LIMIT_ANNOUNCES, LIMIT_OBJECTS, MEMPOOL_MODE, NO_RELATIVE_CONDITIONS_ON_EPHEMERAL,
NO_UNKNOWN_CONDS, STRICT_ARGS_COUNT,
LIMIT_OBJECTS, MEMPOOL_MODE, NO_RELATIVE_CONDITIONS_ON_EPHEMERAL, NO_UNKNOWN_CONDS,
STRICT_ARGS_COUNT,
};
use chia::gen::run_puzzle::run_puzzle as native_run_puzzle;
use chia::gen::solution_generator::solution_generator as native_solution_generator;
Expand Down Expand Up @@ -351,7 +351,6 @@ pub fn chia_rs(py: Python, m: &PyModule) -> PyResult<()> {
m.add("COND_ARGS_NIL", COND_ARGS_NIL)?;
m.add("NO_UNKNOWN_CONDS", NO_UNKNOWN_CONDS)?;
m.add("STRICT_ARGS_COUNT", STRICT_ARGS_COUNT)?;
m.add("LIMIT_ANNOUNCES", LIMIT_ANNOUNCES)?;
m.add("AGG_SIG_ARGS", AGG_SIG_ARGS)?;
m.add("ENABLE_FIXED_DIV", ENABLE_FIXED_DIV)?;
m.add("ENABLE_SOFTFORK_CONDITION", ENABLE_SOFTFORK_CONDITION)?;
Expand Down

0 comments on commit b4da25b

Please sign in to comment.