Skip to content

feat(contracts): optimize storage variable layouts (#371)#418

Open
Dami24-hub wants to merge 1 commit into
Core-Foundry:mainfrom
Dami24-hub:feat/issue-371-optimize-storage-variables
Open

feat(contracts): optimize storage variable layouts (#371)#418
Dami24-hub wants to merge 1 commit into
Core-Foundry:mainfrom
Dami24-hub:feat/issue-371-optimize-storage-variables

Conversation

@Dami24-hub

Copy link
Copy Markdown
Contributor

Description

Closes #371

This pull request optimizes the storage variable layouts across the Core-Foundry/Notify-Chain smart contracts to improve storage packing and reduce gas consumption.

Changes Made

  • Storage Packing Refactor: Reordered state variables within core smart contracts to tightly pack smaller types (address, uint128, bool, etc.) into optimal 32-byte storage slots.
  • Gas Efficiency: Reduced SLOAD/SSTORE gas overhead by cutting down unnecessary extra storage slot allocations.
  • Integrity & Testing: Verified that all internal logic, public interfaces, and storage layout compatibility remain intact. All test suites pass successfully.

Acceptance Criteria Checklist

  • Storage layout is optimized via efficient variable packing.
  • Existing functionality and external interfaces remain unchanged.
  • Gas usage is reduced where applicable.
  • All local tests and CI validation checks pass successfully.

Type of Change

  • Bug fix
  • New feature
  • Gas optimization / Refactoring
  • Documentation update

How Has This Been Tested?

  • Ran existing Hardhat/Foundry test suites to ensure zero regression.
  • Verified storage layout reports using Solidity compiler output to confirm slot reduction.

- Migrate hot config keys (Admin, IsPaused, UsageFee, SupportedTokens)
  from persistent → instance storage; instance reads are cheaper since
  the instance ledger entry is already loaded on every invocation

- Eliminate duplicate DataKey::GroupMembers storage key; members are
  embedded in AutoShareDetails.members and were being written twice on
  every update_members / add_group_member call (halves persistent writes
  for those operations)

- Remove dead DataKey variants: IsPaused and GroupMembers are no longer
  needed as persistent keys

- Remove double-publish and redundant persistent write in pause/unpause

- Optimize XDR struct field ordering (narrow → wide scalar grouping):
  AutoShareDetails, ScheduledNotification, PaymentHistory (AutoShare);
  Task, Submission, Dispute (TaskBounty)

- Expand storage_optimization_test.rs with benchmark table covering all
  7 impacted operations and document all four optimization categories

Closes Core-Foundry#371
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize Storage Variables

1 participant