fix(enforcers): LogicalOrWrapperEnforcer groups silently share stateful sub-enforcer state - #194
Open
SashaMIT wants to merge 2 commits into
Open
Conversation
LogicalOrWrapperEnforcer forwarded the raw delegation hash to every caveat in the selected group. Stateful enforcers key state by delegation hash (not terms), so all groups referencing the same stateful enforcer shared one state: the first-used group initialised it (period start, call counter, spent map) for every other group — invisibly to the delegator, and beyond what the header security notice covers. The forwarded hash is now namespaced by the selected group index (keccak256(delegationHash, groupIndex)); each group's budgets/periods are independent, and a shared budget remains expressible by placing caveats in a single group. Includes an isolation regression test (LimitedCallsEnforcer, limit 1 in two groups) that fails without the fix. Signed-off-by: SashaMIT <sash@ela.city> Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit edf621a. Configure here.
The afterHook assertion still read the raw delegation hash key, which was never locked, so it always passed. Point it at the namespaced key like the before-hook check. Signed-off-by: SashaMIT <sash@ela.city> Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
LogicalOrWrapperEnforcerforwards the raw_delegationHashto every caveat in the selected group.MultiTokenPeriodEnforcer,ERC20StreamingEnforcer,LimitedCallsEnforcer,NativeTokenPaymentEnforcer, …) key their state by delegation hash — terms are not part of the key.keccak256(abi.encode(delegationHash, groupIndex)), isolating each group's state. A deliberately shared budget remains expressible by placing the caveats in a single group. Verified that no in-repo enforcer uses the delegation hash for anything except state keying / event fields, so namespacing is safe.delegationHash+groupIndex(both available at redemption).Impact if unsolved
Any delegation using this wrapper with the same stateful enforcer in multiple groups gets cross-group interference the delegator never agreed to: e.g. a 100/day group and a 100/week group share one counter and one period start, so the daily path consumes the weekly path's budget (or vice versa), and the first redemption permanently pins the period anchor for both. The mismatch between documented semantics and actual state semantics is invisible at signing time.
Test plan
test_statefulEnforcerStateIsIsolatedPerGroup: two groups, sameLimitedCallsEnforcer(limit 1 each) — each group gets its own independent call allowance; fails without the fix (mutation-verified).LogicalOrWrapperEnforcerTest43/43; fulltest/enforcerssuite 581/581.Made with Cursor