From e5313b6a56674c4a4eacaa3485698ca429741503 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Thu, 7 May 2026 12:25:40 +0400 Subject: [PATCH] use forge-std boundPrivateKey for fuzzed keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit forge-std's StdUtils (already inherited via Test → FlowTest) exposes boundPrivateKey(uint256) which is the canonical helper for clamping a fuzzed value into the secp256k1 valid private-key range. Five manual occurrences of `(key % (SECP256K1_ORDER - 1)) + 1` and their identical "// Ensure the fuzzed key is within the valid range for secp256k1" comments are replaced. Closes #420. Co-Authored-By: Claude Opus 4.7 (1M context) --- test/src/concrete/Flow.expression.t.sol | 3 +-- test/src/concrete/Flow.signedContext.t.sol | 10 ++++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/test/src/concrete/Flow.expression.t.sol b/test/src/concrete/Flow.expression.t.sol index 4ee547d0..f2760611 100644 --- a/test/src/concrete/Flow.expression.t.sol +++ b/test/src/concrete/Flow.expression.t.sol @@ -55,8 +55,7 @@ contract FlowExpressionTest is FlowTest, IInterpreterCallerV2 { SignedContextV1[] memory signedContext = new SignedContextV1[](matrixCallerContext.length); { - // Ensure the fuzzed key is within the valid range for secp256k1 - uint256 aliceKey = (fuzzedKeyAlice % (SECP256K1_ORDER - 1)) + 1; + uint256 aliceKey = boundPrivateKey(fuzzedKeyAlice); for (uint256 i = 0; i < matrixCallerContext.length; i++) { signedContext[i] = vm.signContext(aliceKey, aliceKey, matrixCallerContext[i]); } diff --git a/test/src/concrete/Flow.signedContext.t.sol b/test/src/concrete/Flow.signedContext.t.sol index beabbeae..971218f9 100644 --- a/test/src/concrete/Flow.signedContext.t.sol +++ b/test/src/concrete/Flow.signedContext.t.sol @@ -23,9 +23,8 @@ contract FlowSignedContextTest is FlowTest { vm.assume(fuzzedKeyBob != fuzzedKeyAlice); (IFlowV5 flow, EvaluableV2 memory evaluable) = deployFlow(); - // Ensure the fuzzed key is within the valid range for secp256k1 - uint256 aliceKey = (fuzzedKeyAlice % (SECP256K1_ORDER - 1)) + 1; - uint256 bobKey = (fuzzedKeyBob % (SECP256K1_ORDER - 1)) + 1; + uint256 aliceKey = boundPrivateKey(fuzzedKeyAlice); + uint256 bobKey = boundPrivateKey(fuzzedKeyBob); SignedContextV1[] memory signedContexts = new SignedContextV1[](2); @@ -56,9 +55,8 @@ contract FlowSignedContextTest is FlowTest { vm.assume(fuzzedKeyBob != fuzzedKeyAlice); (IFlowV5 flow, EvaluableV2 memory evaluable) = deployFlow(); - // Ensure the fuzzed key is within the valid range for secp256k1 - uint256 aliceKey = (fuzzedKeyAlice % (SECP256K1_ORDER - 1)) + 1; - uint256 bobKey = (fuzzedKeyBob % (SECP256K1_ORDER - 1)) + 1; + uint256 aliceKey = boundPrivateKey(fuzzedKeyAlice); + uint256 bobKey = boundPrivateKey(fuzzedKeyBob); SignedContextV1[] memory signedContext = new SignedContextV1[](1); signedContext[0] = vm.signContext(aliceKey, aliceKey, context0);