From acfdd2b22e9fb756e559bad7c4a719eaf1238dc9 Mon Sep 17 00:00:00 2001 From: openhands Date: Thu, 12 Mar 2026 07:57:31 +0000 Subject: [PATCH] fix: fix: Debug failing round-trip-safe attack in evolution fitness (#595) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After a buy→sell round-trip the net price movement is near zero, so recenter() reverts with "amplitude not reached" and aborts the whole AttackRunner script. Wrap the recenter() call in a try/catch so amplitude failures are caught and logged as a skipped step rather than propagating as a fatal revert. When recenter is skipped, no state snapshot is emitted and the attack sequence continues — matching the intended semantics: round-trip trading should not cause the fitness scorer to crash. Co-Authored-By: Claude Sonnet 4.6 --- onchain/script/backtesting/AttackRunner.s.sol | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/onchain/script/backtesting/AttackRunner.s.sol b/onchain/script/backtesting/AttackRunner.s.sol index 351ee35..10d2bd7 100644 --- a/onchain/script/backtesting/AttackRunner.s.sol +++ b/onchain/script/backtesting/AttackRunner.s.sol @@ -252,13 +252,18 @@ contract AttackRunner is Script { _executeSell(line); } else if (_eq(op, "recenter")) { vm.startBroadcast(RECENTER_PK); - // Capture direction: true = price moved up, false = price moved down. - // recenter() reverts (not returns false) when amplitude is insufficient, - // so a successful call is always a real recenter regardless of direction. - _lastRecenterIsUp = ILM(lmAddr).recenter(); - _hasRecentered = true; + // recenter() reverts when amplitude is insufficient (price hasn't moved far enough + // from the anchor center). Use try/catch so attacks with round-trip buy→sell cycles + // — where the net price movement is near zero — don't abort the whole script. + // A caught revert means no state change occurred; skip the snapshot for this step. + try ILM(lmAddr).recenter() returns (bool isUp) { + _lastRecenterIsUp = isUp; + _hasRecentered = true; + isRecenter = true; + } catch { + console.log("recenter: skipped (amplitude not reached)"); + } vm.stopBroadcast(); - isRecenter = true; } else if (_eq(op, "stake")) { _executeStake(line); } else if (_eq(op, "unstake")) {