From 958ef783a4143314fbfb81cebc42956a12cfc5b7 Mon Sep 17 00:00:00 2001 From: FiveMovesAhead Date: Mon, 17 Mar 2025 13:10:08 +0800 Subject: [PATCH] Require a minimum number of nonces. --- tig-protocol/src/contracts/benchmarks.rs | 13 +++++++++---- tig-structs/src/config.rs | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tig-protocol/src/contracts/benchmarks.rs b/tig-protocol/src/contracts/benchmarks.rs index 3625fbd..08f211b 100644 --- a/tig-protocol/src/contracts/benchmarks.rs +++ b/tig-protocol/src/contracts/benchmarks.rs @@ -18,10 +18,6 @@ pub async fn submit_precommit( return Err(anyhow!("Invalid settings.player_id. Must be {}", player_id)); } - if num_nonces == 0 { - return Err(anyhow!("Invalid num_nonces. Must be greater than 0")); - } - let config = ctx.get_config().await; let latest_block_id = ctx.get_latest_block_id().await; @@ -44,6 +40,15 @@ pub async fn submit_precommit( return Err(anyhow!("Invalid challenge '{}'", settings.challenge_id)); } + // verify min nonces + let min_nonces = config.benchmarks.min_nonces[&settings.challenge_id]; + if num_nonces < min_nonces { + return Err(anyhow!( + "Invalid num_nonces. Must be at least {}", + min_nonces + )); + } + // verify algorithm is active if !ctx .get_algorithm_state(&settings.algorithm_id) diff --git a/tig-structs/src/config.rs b/tig-structs/src/config.rs index 719f301..58e67a3 100644 --- a/tig-structs/src/config.rs +++ b/tig-structs/src/config.rs @@ -68,6 +68,7 @@ serializable_struct_with_getters! { min_per_nonce_fee: PreciseNumber, min_base_fee: PreciseNumber, runtime_configs: HashMap, + min_nonces: HashMap, } } serializable_struct_with_getters! {