Skip to content

[contracts] fork tests do not snapshot gas — silent liquidation cost regressions undetected #274

@obchain

Description

@obchain

Refs #53

File: contracts/test/CharonLiquidatorFork.t.sol, _assertHappyPath()

Problem:
No gas snapshot is taken for executeLiquidation calls. Gas consumption is a profit-critical metric for a liquidation bot: a 50k gas increase per liquidation changes profit/loss calculation and may make marginal opportunities unprofitable. The fork test environment, with real Aave V3 state, is the most accurate place to baseline this.

Fix:
Add gas measurement to _assertHappyPath():

uint256 gasBefore = gasleft();
liquidator.executeLiquidation(_params(m));
uint256 gasUsed = gasBefore - gasleft();
emit log_named_uint(string.concat(m.name, " gas"), gasUsed);

For regression detection, integrate with forge snapshot:
forge snapshot --match-test test_fork

Add a .gas-snapshot file (gitignored or tracked) and fail CI when gas increases beyond a threshold using forge snapshot --check.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions