fix: fix: Debug failing round-trip-safe attack in evolution fitness (#595)

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 <noreply@anthropic.com>
This commit is contained in:
openhands 2026-03-12 07:57:31 +00:00
parent bd291bc9b9
commit acfdd2b22e

View file

@ -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 buysell 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")) {