fix: close protocol-pause bypass via admin-whitelist collision (#26) - #32
Merged
elizabetheonoja-art merged 1 commit intoJun 24, 2026
Conversation
…ty-Protocol#26) Three velocity-limit admin functions accepted an arbitrary parameter and only called , allowing any self-authorizing address to impersonate the contract admin: - set_velocity_limit_config - apply_velocity_override - revoke_velocity_override Additionally, revoke_velocity_override referenced DataKey::VelocityOverrideGlobal and DataKey::VelocityOverride (not present in the DataKey enum), creating a key-collision — the existence check always failed, and revoked the wrong key. Fixes: - Add stored-admin identity check before require_auth in all three functions - Replace DataKey::VelocityOverride* with velocity_limit::VelocityDataKey::VelocityOverride - Remove redundant require_auth from velocity_limit::apply_override and set_velocity_config (auth is enforced by the caller in lib.rs) - Add 5 regression tests covering non-admin rejection and happy-path flows
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
Closes #26 — Protocol-Pause Bypass via Admin-Whitelist Collision
Root Causes Fixed
1. Admin-Whitelist Collision (auth bypass)
Three velocity-limit admin functions accepted an arbitrary
admin: Addressparameter and only calledadmin.require_auth(). Since any transaction source satisfies its ownrequire_auth(), any address could pose as the contract admin.Affected functions:
set_velocity_limit_configapply_velocity_overriderevoke_velocity_overrideFix: Each function now checks
admin == get_admin_or_panic(&env)beforerequire_auth().2. Storage Key Collision (protocol-pause bypass)
revoke_velocity_overridereferencedDataKey::VelocityOverrideGlobalandDataKey::VelocityOverride(u64)— variants that do not exist in theDataKeyenum. The actual overrides are stored underVelocityDataKey::VelocityOverride(scope)invelocity_limit.rs. This meant the existence check always missed the real key, making overrides impossible to revoke and silently bypassing the circuit-breaker.Fix: Use
velocity_limit::VelocityDataKey::VelocityOverride(meter_id)consistently.3. Double auth in velocity_limit.rs
apply_overrideandset_velocity_configduplicatedadmin.require_auth()even though the callers inlib.rsalready perform the verified check.Fix: Removed the redundant inner
require_authcalls.Tests Added
5 regression tests in
src/test.rs:test_configure_velocity_limits_rejects_non_admintest_configure_velocity_limits_succeeds_for_real_admintest_apply_velocity_override_rejects_non_admintest_apply_and_revoke_velocity_override_by_admintest_revoke_velocity_override_rejects_non_adminCI
All CI steps pass:
cargo fmt --check,cargo clippy -- -D warnings,cargo test,cargo build --target wasm32-unknown-unknown --release.