Feature/contract security upgrades 259 263 264#295
Open
Joycejay17 wants to merge 3 commits intoceejaylaboratory:mainfrom
Open
Feature/contract security upgrades 259 263 264#295Joycejay17 wants to merge 3 commits intoceejaylaboratory:mainfrom
Joycejay17 wants to merge 3 commits intoceejaylaboratory:mainfrom
Conversation
…tory#259) - Add storage keys for LastRelayerActivity, EmergencyMode, and LockedBalance - Initialize emergency mode and activity timestamp in initialize() - Update last relayer activity timestamp on each process_message() - Add activate_emergency_mode() - auto-activates after 72h of inactivity, admin can activate earlier - Add emergency_withdraw() - allows users to withdraw locked assets in emergency mode - Add deactivate_emergency_mode() - admin can deactivate emergency mode - Add view helpers: is_emergency_mode(), last_relayer_activity(), time_since_last_activity() - Fix Cargo.toml to include lib.path
…ratory#263) - Add UpgradeProposal struct for tracking upgrade proposals - Add storage keys for AdminList, UpgradeProposal, and Approval tracking - Change initialize() to accept 5 admin addresses instead of single admin - Add propose_upgrade() - any admin can propose an upgrade - Add approve_upgrade() - admins can approve, requires 3/5 approvals to execute - Add cancel_upgrade() - any admin can cancel a pending proposal - Add execute_upgrade() - internal function to execute approved upgrades - Add replace_admin() - replace an admin in the multi-sig list - Deprecate upgrade() and set_admin() - now panic with deprecation message - Add view helpers: get_admin_list(), get_upgrade_proposal(), has_approved() - Update tests to work with multi-sig admin list - Fix Vec indexing issues by using get() instead of [] - Fix ownership issues by cloning values appropriately
…eejaylaboratory#264) - Add Minter, Burner, Pauser roles to AccessRole enum - Update has_role() to handle special roles (exact match) vs hierarchical roles - Add has_any_role() and require_any_role() for checking multiple roles - Add revoke_specific_role() for revoking specific roles instantly - Add is_minter(), is_burner(), is_pauser() helper functions - Admin automatically has all special role permissions - Update tests to verify new special roles and revocation functions - Special roles (10+) are non-hierarchical, hierarchical roles (0-2) maintain Admin > Moderator > Contributor hierarchy
|
@Joycejay17 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Contract Security Enhancements
Overview
This PR implements three critical security enhancements for the AnchorPoint smart contracts:
Changes Made
#259: Emergency Exit Logic for Bridge Funds
File:
src/bridge/lib.rsAdded emergency mode functionality to protect users' funds if the bridge relayer becomes unresponsive:
Storage Keys Added:
LastRelayerActivity- Tracks timestamp of last relayer activityEmergencyMode- Boolean flag for emergency stateLockedBalance- Tracks user locked balances (for future use)Functions Added:
activate_emergency_mode(caller)- Activates emergency mode. Auto-activates after 72 hours (259,200 seconds) of relayer inactivity. Admin can activate earlier manually.emergency_withdraw(user, token, amount)- Allows users to withdraw their locked assets when emergency mode is activedeactivate_emergency_mode(admin)- Admin can deactivate emergency mode once relayer is back onlineFunctions Modified:
initialize()- Now initializes emergency mode flag and activity timestampprocess_message()- Updates last relayer activity timestamp on each successful messageView Helpers Added:
is_emergency_mode()- Returns current emergency mode statelast_relayer_activity()- Returns timestamp of last relayer activitytime_since_last_activity()- Returns elapsed time since last activity in secondsSecurity Benefit: Users can withdraw their funds even if the relayer is unresponsive for 72+ hours, preventing fund lockup scenarios.
#263: Multi-sig Requirement for Upgrades
File:
src/upgradeable/lib.rsRefactored the upgradeable contract to require 3-out-of-5 administrator approvals before executing upgrades:
Struct Added:
UpgradeProposal- Tracks upgrade proposals with wasm_hash, proposed_at, approval_count, and executed flagStorage Keys Added:
AdminList- Stores the 5 administrator addressesUpgradeProposal- Stores the current pending upgrade proposalApproval(Address)- Tracks which admins have approved the current proposalFunctions Modified:
initialize(admin_list)- Now accepts a Vec of 5 administrator addresses instead of a single adminupgrade()- DEPRECATED - Now panics with deprecation messageFunctions Added:
propose_upgrade(admin, new_wasm_hash)- Any admin can propose an upgrade (counts as first approval)approve_upgrade(admin)- Admins can approve a pending proposal. Auto-executes when 3/5 approvals reachedcancel_upgrade(admin)- Any admin can cancel a pending proposalexecute_upgrade(proposal)- Internal function that executes the upgrade with sufficient approvalsreplace_admin(proposer, old_admin, new_admin)- Replace an admin in the multi-sig listset_admin()- DEPRECATED - Now panics with deprecation messageView Helpers Added:
get_admin_list()- Returns all 5 administrator addressesget_upgrade_proposal()- Returns the current upgrade proposal, if anyhas_approved(admin)- Returns whether an admin has approved the current proposalTests Updated:
get()instead of[]Security Benefit: Prevents single-point-of-failure and rogue upgrades by requiring consensus among multiple administrators.
#264: Access Control Lists (ACL) System
File:
src/auth/rbac.rsExtended the RBAC system with special functional roles (MINTER, BURNER, PAUSER):
Roles Added to AccessRole Enum:
Minter(10) - Can mint tokensBurner(11) - Can burn tokensPauser(12) - Can pause/unpause contract operationsFunctions Modified:
has_role()- Updated to handle special roles (exact match) vs hierarchical roles (Admin > Moderator > Contributor)revoke_role()- Enhanced to emit the revoked role in the event and validate role exists before revokingFunctions Added:
has_any_role(address, roles)- Check if address has any of the specified rolesrequire_any_role(address, roles)- Panic if address doesn't have any of the specified rolesrevoke_specific_role(admin, target, role)- Revoke a specific role from a target address (instant revocation)is_minter(address)- Check if address can perform minter operationsis_burner(address)- Check if address can perform burner operationsis_pauser(address)- Check if address can perform pauser operationsContract Functions Added:
revoke_specific_role(from, target, role)- Contract wrapper for revoking specific rolesis_minter(address)- Contract wrapper for minter checkis_burner(address)- Contract wrapper for burner checkis_pauser(address)- Contract wrapper for pauser checkTests Updated:
Security Benefit: Provides granular access control for different contract operations with instant revocation capability.
Additional Fixes
Cargo.tomlfiles insrc/bridgeandsrc/liquidationto includelib.pathfor proper compilationTesting
Closes
Closes #259 - Contract: Add emergency exit logic for bridge funds
Closes #263 - Contract: Add multi-sig requirement for upgrades
Closes #264 - Contract: Implement access control lists (ACL)