Add invariant tests for spending limits across redelegation chains

未关闭
#216 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
53/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
solidity

调研方向

Read test/DelegationChainWithCaveatsTest.t.sol for existing chain test setup and documents/CaveatEnforcers.md for hook order. The proposed file is test/invariants/RedelegationSpendLimit.invariant.t.sol; begin by tracing how those tests construct links and inspect spentMap. Done means the stated balance, per-link limit, disabled-link, and redelegator-balance properties hold across generated redemption and toggle sequences.

由索引模型根据 Issue 内容生成。

描述

Description

I'd like to add Foundry invariant tests for the amount enforcers when they sit on more than one link of a delegation chain.

The suite has no invariant or fuzz tests today, and the test files for the cumulative enforcers use root delegations only. Limits on a redelegation appear in fixed integration scenarios such as _createAdapterRedelegation in VedaLending.t.sol. A tree of delegations has more states than those reach: siblings sharing a parent's budget, batched redemptions, links disabled and re-enabled between spends.

Technical Details
  • One new test file, test/invariants/RedelegationSpendLimit.invariant.t.sol. No change to src/, foundry.toml or CI; run length is set inline with forge-config.
  • A handler redeems down a fixed four-link tree, singly and in two-context batches, and disables or re-enables links between calls. Each link carries ERC20TransferAmountEnforcer, and sibling limits add up to more than their parent's.
  • Ghost totals per link are compared with spentMap and token balances after every call.

I have a working draft. On main at b4b8c41 all the properties below hold over 256 runs of 128 calls, in under 20 seconds. To check the tests can fail, I weakened four things in a local copy and each was caught: the enforcer's limit check, storing spent, the disabled-delegation check, and running beforeHook on every link.

Acceptance Criteria

Over any sequence of redemptions, batches and enable or disable calls:

  • The root delegator's balance falls by at most the root link's limit.
  • spentMap for each link stays within that link's limit.
  • spentMap for each link equals what left through it, so reverted redemptions count nothing.
  • Nothing moves through a disabled link.
  • Redelegators' balances don't move.

Scenario:

  • GIVEN a root link limited to 100, with redelegations to A (60) and B (70)
  • WHEN A and B redeem in any order and any amounts
  • THEN root pays at most 100, A's path at most 60 and B's at most 70
References
  • test/DelegationChainWithCaveatsTest.t.sol, the fixed three-level chain with per-call limits
  • documents/CaveatEnforcers.md, hook order across a chain

If this is useful, I'll open the PR against this issue. The native, period and streaming enforcers could follow separately if you want them.

AI use: an AI assistant helped write the tests and this issue; I reviewed both before posting.

主要语言
Solidity
星标
230
派生
122
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MetaMask/delegation-framework 的其他 Issue

查看 MetaMask/delegation-framework 的全部 Issue

相似的 Issue

更多 Blockchain Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。