Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ERC4626PreviewAssertion

Git Source

Inherits: ERC4626BaseAssertion

Title: ERC4626PreviewAssertion

Author: Phylax Systems

Asserts that ERC-4626 preview functions are consistent with the actual results of the corresponding state-changing operations, and that rounding favors the vault. Invariants covered:

  • Preview consistency: for the same pre-state, previewDeposit(a) == shares minted by deposit(a) previewMint(s) == assets charged by mint(s) previewWithdraw(a) == shares burned by withdraw(a) previewRedeem(s) == assets returned by redeem(s)
  • Rounding direction (implicit in the inequality checks): previewDeposit rounds DOWN (returns fewer shares -> favors vault) previewMint rounds UP (returns more assets -> favors vault) previewWithdraw rounds UP (returns more shares -> favors vault) previewRedeem rounds DOWN (returns fewer assets -> favors vault)

In addition to return values, every operation proves the corresponding receiver/owner share delta, total-supply delta, and underlying-token movement. ERC-4626 does not define a universal preview-distance bound, so every concrete supported adapter must provide one.

Functions

_registerPreviewTriggers

Register the default trigger set for preview-consistency invariants.

Each ERC-4626 operation gets its own assertion function via registerFnCallTrigger.

function _registerPreviewTriggers() internal view;

_maxPreviewDeviation

Maximum acceptable deviation between a preview result and the actual result.

Must be derived from the concrete vault implementation; no generic default is sound.

function _maxPreviewDeviation() internal view virtual returns (uint256);

_assetCustodyAccount

Account whose underlying-token balance reflects ERC-4626 payments and payouts.

Standard vaults custody assets themselves. Managed-custody adapters such as LlamaLend must override this with the controller that actually receives and sends the underlying token.

function _assetCustodyAccount() internal view virtual returns (address);

assertDepositPreview

For the triggering deposit(assets, receiver) call, verifies: previewDeposit(assets) <= actualSharesMinted (ERC-4626 spec) actualSharesMinted - previewDeposit(assets) <= maxDeviation

function assertDepositPreview() external;

assertMintPreview

For the triggering mint(shares, receiver) call, verifies: previewMint(shares) >= actualAssetsCharged (ERC-4626 spec) previewMint(shares) - actualAssetsCharged <= maxDeviation

function assertMintPreview() external;

assertWithdrawPreview

For the triggering withdraw(assets, receiver, owner) call, verifies: previewWithdraw(assets) >= actualSharesBurned (ERC-4626 spec) previewWithdraw(assets) - actualSharesBurned <= maxDeviation

function assertWithdrawPreview() external;

assertRedeemPreview

For the triggering redeem(shares, receiver, owner) call, verifies: previewRedeem(shares) <= actualAssetsReturned (ERC-4626 spec) actualAssetsReturned - previewRedeem(shares) <= maxDeviation

function assertRedeemPreview() external;

_stripSelector

Strip the 4-byte selector from raw call input bytes.

function _stripSelector(bytes memory input) internal pure returns (bytes memory args);

_firstUint256Arg

Reads the first ABI argument from selector-prefixed calldata.

This also supports ERC-4626-compatible default-argument overloads whose first amount has the same ABI position as the canonical methods.

function _firstUint256Arg(bytes memory input) internal pure returns (uint256 value);

_receiver

function _receiver(bytes memory input, PhEvm.TriggerContext memory ctx) internal view returns (address);

_withdrawAccounts

function _withdrawAccounts(bytes memory input, PhEvm.TriggerContext memory ctx)
    internal
    view
    returns (address receiver, address owner);

_triggerCaller

function _triggerCaller(PhEvm.TriggerContext memory ctx) internal view returns (address);

_requirePaymentEffects

function _requirePaymentEffects(
    address payer,
    address custody,
    uint256 amount,
    PhEvm.ForkId memory pre,
    PhEvm.ForkId memory post,
    string memory operation
) internal view;

_requirePayoutEffects

function _requirePayoutEffects(
    address custody,
    address receiver,
    uint256 amount,
    PhEvm.ForkId memory pre,
    PhEvm.ForkId memory post,
    string memory operation
) internal view;

_addressArg

function _addressArg(bytes memory input, uint256 index) internal pure returns (address value);

_requireIncrease

function _requireIncrease(uint256 beforeValue, uint256 afterValue, uint256 amount, string memory reason)
    internal
    pure;

_requireDecrease

function _requireDecrease(uint256 beforeValue, uint256 afterValue, uint256 amount, string memory reason)
    internal
    pure;