Skip to content

perf: pack the reward-rate baseline, seed Veda engines and trim vault and spend reads - #131

Merged
Slokh merged 1 commit into
mainfrom
perf/earn-spend-gas-batch
Nov 23, 2026
Merged

Slokh merged 1 commit into
mainfrom
perf/earn-spend-gas-batch

Conversation

@Slokh

@Slokh Slokh commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

What changed

EarnVault

  • The reward-rate baseline is packed beside earnFees (a uint96, with a marker that sends a wider value to its own slot), so initialization writes no slot of its own for it. rewardRateBaseline() keeps its selector and uint256 return. Storage layout changes; this applies to new vaults only.
  • The managed engine-share count is written once, together with the anchor, on deposits, in-kind deposits and redeems.

EarnFees

  • accrueFees and _accrueFees no longer allocate a FeePreview and a remainder array that the call then replaces.

CardSpender

  • The vault's asset() is read only when the destination was not credited (_revertNotCredited), where it still reverts IncorrectAssetForVault for a vault whose asset is not the spend's token.

Deployment

  • veda engines are now seeded with 1 base unit by the seed-engine activation step, like erc4626 and propamm engines. Held deposits and solved payouts no longer take the engine's base-asset balance from zero and back on every call. deployment.md describes why the unit is inert.

Gas

Tempo TIP-20 (snapshots/):

Path Before After
Earn card spend (router) 423,715 420,618
Rain Earn spend, public 211,561 208,464
Fee-active deposit, no new yield 164,098 163,106
Fee-active deposit charging yield 466,496 465,442
Fee-active redeem, no new yield 152,911 152,032
Async request into an empty queue 1,393,752 1,392,876
Deposit, returning holder 393,565 393,199
Partial redeem 130,752 130,499

EarnFactory.deploy writes one slot fewer (about 250,000 gas less on Tempo). A seeded Veda engine saves about 250,000 gas on each deposit, solve-and-forward and exact withdraw on Tempo, which these snapshots do not cover.

Checks

pnpm verify passes. The solar-verify specs for EarnVault, EarnFees and CardSpender verify as on main.

Deploy

Needs a vault factory release (new EarnVault and EarnFees implementations) and new card spenders for the CardSpender change. Existing Veda engines can be seeded by running the seed-engine step. No router or engine release.

@tempoxyz-bot

tempoxyz-bot commented Nov 23, 2026 •

Copy link
Copy Markdown

👁️ Cyclops Security Review

✅ Reviewed 8585a23 (latest) · Coverage: partial · ⚠️ 1 open finding · report
⚠️ Not checked: The slot packing of earnFees with _rewardRateBaseline and the memory behaviour of the EarnFees destructuring were judged from Solidity source semantics; the bytecode and storage layout emitted by the pinned solar compiler were not inspected
⚠️ Not checked: EarnVault: managed engine-share count written once with the anchor on deposit, in-kind deposit, redeem, exact withdraw and async request: ruled out without reading the cited code at this commit
⚠️ Not checked: EarnVault: reward-rate baseline packed as uint96 beside earnFees with a wide-slot fallback: ruled out without reading the cited code at this commit
⚠️ 10 more unchecked questions are listed in the report
ℹ️ Not verifiable from the source alone (needs running code or deployed state): No Forge or Vitest run backs these conclusions. The checkout has no lib/, node_modules/ or pinned solar compiler (.solar/), and installing them would modify the assigned repository. The only exec (7 more in the report)

# Severity Finding Introduced Status
1 🟢 Low Direct CardSpender spends can settle when vault asset differs from token 8585a23 🟠 Open

@Slokh
Slokh merged commit 3981c7b into main Nov 23, 2026
23 of 24 checks passed
@Slokh
Slokh deleted the perf/earn-spend-gas-batch branch November 23, 2026 21:15

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

Comment thread src/spend/CardSpender.sol
Comment on lines +278 to +280
// A vault whose asset is not `s.token` cannot credit the destination, so the credit check refuses it,
// naming it then (_revertNotCredited) instead of reading the vault's asset on every spend.
if (s.fromVault != 0 && !PROVIDER.isAllowedVault(s.vault)) revert VaultNotAllowed(s.vault);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low (exposure and trigger unconfirmed): Direct CardSpender spends can settle when vault asset differs from token

_check no longer requires a direct Earn spend's vault asset to equal CardSpend.token; the asset is read only after a failed credit check. A balance delta from another source satisfies that check: the vault's own fee mint lets a spend in its EarnShare to its EarnFees settle. Other mismatches still revert, sometimes under a different error.

Valid? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants