Skip to content

verity_contract rejects function-pointer parameters #1747

@fricoben

Description

@fricoben

What I was trying to do

Model TermMaxOrderV2._swapAndUpdateReserves, which takes a function pointer:

// contracts/v2/TermMaxOrderV2.sol:859-867
function _swapAndUpdateReserves(
    uint256 tokenAmtInOrOut,
    uint256 limitTokenAmt,
    OrderConfig memory orderConfig_,
    function(
      uint256,
      uint256,
      OrderConfig memory) internal view returns (uint256, uint256, uint256, uint256, bool) func
) private returns (uint256, uint256, int256, int256) {
    (uint256 netAmt, uint256 feeAmt, uint256 deltaFt, uint256 deltaXt, bool isNegetiveXt) =
        func(tokenAmtInOrOut, limitTokenAmt, orderConfig_);
    ...
}

https://github.com/term-structure/termmax-contract-v2/blob/64bd47b98e064c7fb91ab4a59b70520e0ec285d5/contracts/v2/TermMaxOrderV2.sol#L859-L884

What I tried

import Contracts.Common
open Verity hiding pure bind
open Verity.EVM.Uint256

verity_contract FnPtrRepro where
  storage dummy : Uint256 := slot 0

  function addOne (x : Uint256) : Uint256 := do
    return (add x 1)

  function apply (f : Uint256 -> Uint256, x : Uint256) : Uint256 := do
    return (f x)

Why it failed

Verity/Macro/Translate.lean:242 rejects function-typed parameters:

unsupported type 'Uint256 -> Uint256'; expected Uint256, Int256, Uint8,
  Address, Bytes32, Bool, String, Bytes, Array <type>, Tuple [...], Unit,
  or a user-defined type from the `types` or `inductive` section

Even if the parameter type were accepted, the bind-source checker at
Verity/Macro/Translate.lean:1889 rejects let x ← f ... whose source is
not getStorage or a direct internal helper call:

unsupported bind source; expected getStorage/getStorageAddr/...
  or a direct internal helper call

Reproduces on Verity 74d8fe20ffa2f5dbb94959f3dd40a62df6aa8224 (release
v1.0.0).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions