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:
parent
bd291bc9b9
commit
acfdd2b22e
1 changed files with 11 additions and 6 deletions
|
|
@ -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")) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue