> For the complete documentation index, see [llms.txt](https://elacitylabs.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://elacitylabs.gitbook.io/docs/protocol/protocol-v2/technical-documentation/storage_and_restrictions.md).

# Storage and Restrictions

This document summarizes recent changes to token transfer restrictions and introduces new tools for contract storage investigation.

## 1. Transfer Restriction Checker

The ELACITY DRM system uses an "exclusive transfer" mechanism to regulate the movement of sensitive tokens within operative contracts. Recent updates have refined these restrictions to support new use cases, such as Smart Accounts and decentralized trading.

### 1.1 support\_for\_smart\_accounts\_elacity\_1958

To ensure compatibility with Smart Accounts (which are contract-based wallets), the ownership verification logic in `ExclusiveTransferrableTokens` was updated.

* **Change**: The `tx.origin` check in `_checkOwnerLater()` has been disabled for contract-based senders.
* **Rationale**: Previously, the system enforced that the `tx.origin` must be the contract owner. However, when a Smart Account interacts with an operative contract, the `msg.sender` is the Smart Account contract itself, while `tx.origin` is the EOA signer. This discrepancy caused legitimate transfers to fail.
* **Impact**: Smart Accounts can now successfully manage and transfer exclusive tokens they own.
* **Verification**: Tests for this behavior can be found in `test/SmartAccountMinting.test.ts`.

### 1.2 disabling\_restriction\_for\_royalty\_tokens

The restriction on transferring `ROYALTY_SHARE` tokens (ID 2) has been disabled across the ecosystem to facilitate easier trading and distribution of royalty rights.

* **Implementation**: The call to `allowTransferOf` (or its equivalent in factories) for token ID `2` has been commented out in the following files:
  * `contracts/assets/DigitalAsset.sol`
  * `contracts/channel/factories/MultiChannelFactory.sol`
  * `contracts/channel/factories/StandardChannelFactory.sol`
* **Effect**: Since the `ROYALTY_SHARE` token is no longer registered as an exclusive token during the initialization/minting flow, it behaves as a standard ERC-1155 token. It can be transferred by its owner without requiring authorization from the `AuthorityGateway` or `TradeGateway`.
* **Reasoning**: This change (part of ELACITY-2152) allows users to freely trade their royalty stakes without central gatekeeping, while sensitive tokens like `ACCESS_TOKEN` (1) and `DISTRIBUTION_RIGHT` (3) remain restricted.
* **Verification**: Updated tests in `test/Tokens.test.ts` (see "ELACITY-2152: should succeed when attempting to transfer royalty shares") confirm that these transfers now bypass exclusivity checks.

***

## 2. Storage Investigation Tools

Recent debugging efforts (ELACITY-2152) have introduced new tools and configurations to assist in auditing contract storage and state.

### 2.1 Storage Layout Configuration

To facilitate storage layout analysis, `remix.config.json` has been added to the project, and `compiler_config.json` was updated/replaced.

* **Configuration**: The compiler settings now explicitly include `storageLayout` in the `outputSelection`.
* **Benefit**: This allows developers using Remix or other compatible tools to see the exact storage slot and offset for every variable in the contract, which is essential for manual state verification and ensuring upgrade safety.

### 2.2 Token Restriction Checker Task

A new Hardhat task `check-restriction` has been added in `tasks/check-auth.ts`. This tool is specifically designed to verify if a token is marked as exclusive and if an operator is authorized, by directly querying the contract's storage.

* **Usage**:

  ```bash
  npx hardhat check-restriction --contract <CONTRACT_ADDRESS> --operator <OPERATOR_ADDRESS> [options]
  ```

  * **Options**:
  * `--token`: The token ID to check (default: `2`).
  * `--type`: Preset for contract layout (`channel`, `operative`, or `custom`).
  * `--exclusiveSlot`: Manual override for the `_exclusiveTokens` mapping slot.
  * `--allowedSlot`: Manual override for the `_allowedTransfer` mapping slot.
* **Features**:
  * **Preset Logic**: Automatically adjusts base slots for `_exclusiveTokens` and `_allowedTransfer` mappings based on the contract type.
    * `channel`: Uses slot 1 for `_exclusiveTokens` and slot 2 for `_allowedTransfer`.
    * `operative`: Uses slot 0 for `_exclusiveTokens` and slot 1 for `_allowedTransfer`.
  * **Storage Complexity**: The need for these presets arises from the complex inheritance tree in our upgradeable contracts. When a contract like `DigitalAssetPrivate` inherits from multiple modules, the storage slots of the base `ExclusiveTransferrableTokens` shift depending on the order of inheritance and the number of variables in preceding modules. The current values (1/2 and 0/1) match the storage layout of the latest contract versions.
  * **Direct Storage Access**: Uses `provider.getStorage()` to check values at computed mapping slots, bypassing contract getters.
  * **Educational**: Prints the computed storage slots, which can be cross-referenced with block explorers.

### 2.3 Channel Factory Checker task

A specific task `check-channel-factory` has been added in `tasks/check-channel-factories.ts` to audit the `factories` nested mapping in `ChannelCore.sol`.

* **Usage**:

  ```bash
  npx hardhat check-channel-factory --contract <CHANNEL_CORE_ADDRESS> --type <1|2> --scope <1|2>
  ```
* **Features**:
  * **Nested Mapping Logic**: Correcty computes slots for `mapping(uint8 => mapping(uint8 => address))` by performing double keccak256 operations as defined by the Solidity storage layout.
  * **Context**: Useful for verifying that the `ChannelCore` registry has been correctly initialized with the intended factory addresses for Standard and Multi-channels.

### 2.4 ERC-7201 calculator

Located at `scripts/calaculate-slot.js`, this utility remains a core tool for calculating storage slots for namespaced storage as defined in **ERC-7201**.

* **Usage**:

  ```bash
  node scripts/calaculate-slot.js <namespace_string>
  ```
* **Example**:

  ```bash
  node scripts/calaculate-slot.js openzeppelin.storage.ERC1155
  ```
* **Functionality**: It calculates the `keccak256(uint256(keccak256(id)) - 1) & ~0xff` slot, helping developers identify where namespaced data is stored.
