Skip to content

Formally verified mulExpRay - #599

Open
duncancmt wants to merge 122 commits into
dcmt/expfrom
dcmt/mul-exp
Open

Formally verified mulExpRay#599
duncancmt wants to merge 122 commits into
dcmt/expfrom
dcmt/mul-exp

Conversation

@duncancmt

Copy link
Copy Markdown
Collaborator

No description provided.

duncancmt and others added 30 commits April 15, 2026 16:32
Solidity `bool` may be any nonzero value for truthy when it enters an
assembly block. This commit normalizes bool values at every site where
they are used in arithmetic, bitwise operations, ABI encoding for
external calls, or (transient) storage writes.

Utility libraries (highest leverage — inlined throughout codebase):
- Ternary: use iszero-inversion trick (single iszero, 3 gas) for
  ternary/maybeSwap; lt(0x00, c) for orZero
- FastLogic.and: rewrite via De Morgan (was wrong: and(2,1)=0)
- FastLogic.andNot: rewrite via gt(iszero(b), iszero(a))
- FastLogic.toUint, Math.toInt: normalize with lt(0x00, b)
- UnsafeMath.unsafeInc/Dec(bool), Math.inc/dec: normalize with lt(0x00, b)

External call encoding (mstore/mstore8/shl of bool):
- EkuboV2, EkuboV3, MaverickV2, PancakeInfinity, UniswapV3Fork,
  FlashAccountingCommon, SafePermit, Hanji: wrap bool in lt(0x00, x)

Transient storage:
- CurveTricrypto: clean on write and read

External callback data validation:
- EkuboV2: revert with empty reason if bool > 1

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- FastLogic.andNot: use iszero(or(iszero(a), b)) — cleaner formulation
- CurveTricrypto: remove redundant clean-on-read (write-side suffices)
- CrossChainReceiverFactory: normalize bool immutable in mul (london EVM,
  uses iszero(iszero) since no PUSH0)
- SettlerIntent.setSolver: normalize addNotRemove for xor/mul/sstore use
- EulerSwap: validate bool from external staticcall returndata; normalize
  zeroForOne before shl
- UniswapV2: normalize zeroForOne before shl in both getReserves and swap
- FlashAccountingCommon, UniswapV3Fork: upgrade silent and(0x01,...) mask
  to reverting validation for callback bool data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- FastLogic.and: mul(a, lt(0x00, b)) — cheaper than De Morgan
  (10 gas on Osaka vs 12; 11 on London vs 12)
- FastLogic.andNot: mul(a, iszero(b)) — 8 gas, no PUSH0 needed
- CrossChainReceiverFactory.deploy: normalize setOwnerNotCleanup
  bool before arithmetic use (iszero/iszero for London EVM)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…bility. Make 2 passes over `calls[]` to fix this.
duncancmt and others added 8 commits July 13, 2026 23:15
Use the largest Q72 bias accepted by the 0.3383-ulp cap and keep the compiled runtime, floor bracket, error bound, and monotonicity proofs synchronized.

Co-Authored-By: OpenAI Codex <codex@openai.com>
@duncancmt
duncancmt requested a review from e1Ru1o July 14, 2026 08:48
@duncancmt duncancmt self-assigned this Jul 14, 2026
@duncancmt
duncancmt requested a review from dekz as a code owner July 14, 2026 08:48
@immunefi-magnus

Copy link
Copy Markdown

🛡️ Immunefi PR Reviews

We noticed that your project isn't set up for automatic code reviews. If you'd like this PR reviewed by the Immunefi team, you can request it manually using the link below:

🔗 Send this PR in for review

Once submitted, we'll take care of assigning a reviewer and follow up here.

duncancmt and others added 17 commits July 14, 2026 15:23
Model the generated mulExpRay conversion sequence in the Lean seam proof. Cache complete Lake package trees and reuse them across formal proof builds.

Co-Authored-By: OpenAI Codex <codex@openai.com>
Sheriff is an Algebra Integral (v1.2.2) DEX on RobinHood chain
(app.sheriff.exchange). Wire it as UniV3 fork ID 41:

- New src/core/univ3forks/Sheriff.sol with the Algebra pool deployer
  (0x9ac30D72168a4498aE5C80226F4d3C86278e8f80), the Algebra Integral pool
  init code hash, and the fork ID constant.
- Wire the fork into RobinHood's _uniV3ForkInfo using the Algebra swap
  callback (algebraSwapCallback). The Algebra salt (keccak256(abi.encode(
  token0, token1)), no fee/tickSpacing) is produced by the existing
  poolId==0 path in _toPool.
- Add UNISWAPV3_FORKS.md and CHANGELOG.md entries.

The init code hash was verified by recomputing the USDG/WETH pool address
(0x536a7B19abB933bf6319e0b8817e733Bba166674) via CREATE2.
Use generated mixed interval-Horner/Kronecker and Bernstein cell certificates with variable-propagated Horner errors to certify the runtime core bound. Set the Solidity Q72 bias from the 0.3288640403604298097806-ulp bound, with reproducible formal generation and cache keys.

Co-Authored-By: OpenAI Codex <codex@openai.com>
Align emitted-Yul seams with normalized boolean helpers and the shared int128 upcast.

Co-Authored-By: OpenAI Codex <codex@openai.com>
Run cache actions on Node 24, pin workflow dependencies, suppress checkout initialization hints, and remove actionable Lean lints.

Co-Authored-By: OpenAI Codex <codex@openai.com>
State the revert condition as one inequality in bitlen(|y|) and the octave
index, with A-space never/always-revert thresholds as consequences. Round
all doc approximations to 4 significant figures.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mulExpRay computes the scale headroom as clz(ay) - (129 ^ (ay >> 127)).
scaleShiftTree and its normal-form lemmas mirror the new word tree, the
mulExpRay symbolic-execution reductions follow the emitted Yul's call
sites and fuel positions, and the wrapping_add_t_uint256 reduction is
removed along with the emitted function.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants