Concrete Storage

Technical Information

Introduction

This document serves as a guide to the organization of our namespaces and pointers within the concrete storage system, which is utilized for data setting and retrieval.

Namespace and Pointers

NameSpace

A namespace within a protocol serves a critical role in access control and organization. Each contract is assigned a unique namespace, which acts as a key to unlock specific functionalities within the system.

Pointers

Pointers act as the identifier of the specific data to be set or retrieved. To break it down further when dealing with pointers like Loan.User.Id.LoanDetails, each part of the term provides specific context about the information it represents. Here's an explanation of each part:

Note all pointers are case-sensitive please use camel case with a period between sections. Following all addresses are to be marked with "|" as the key value unless there is a specific context to otherwise.

  • Prefix ("Loan"): This part categorizes the overall domain or subject area of the information. It acts as a broad classifier that tells you the general category of the data you're dealing with. In this case, the prefix "Loan" indicates that the information pertains to a loan or is within the context of loans.

  • Intermediate ("User.Id"): This segment specifies the association or the specific entity within the broader category that the information is tied to. It provides a linkage or a relational context. Here, "User.Id" suggests that the information is related to a particular user, identified by an ID. This ID is unique to the user within the loan system and connects the user to the loan details.

  • Suffix ("LoanDetails"): The suffix gives you a direct indication of the type of information you can expect. It defines the subset of data within the category that will be provided. "LoanDetails" implies that the information you will receive is detailed data about the loan, such as the loan amount, etc.

Now all together, Loan.User.Id.LoanDetails can be interpreted as a structured way to denote that you are looking at the loan details specific to a particular user identified by an ID within the loan system. The prefix sets the stage, the middle points to the specific entity, and the suffix tells you what detailed information you will get about that entity.

Constructing keys and pointers

In our storage architecture, we've implemented a specialized library named StorageKey to manage the mapping of key-value types to storage slots. This library streamlines the process of generating unique keys for each entry in our storage mappings, ensuring that each piece of data is correctly associated with its corresponding identifier.

To illustrate, consider a standard Solidity mapping for tracking user balances:

mapping(address => uint256) public balances;

In our enhanced storage system, we convert the key from an address to a bytes32 type, resulting in a mapping like this:

mapping(bytes32 => uint256) public balances;

Now to generate a unique key for the mapping above, we use the StorageKey library's CreateKey function. For example:

bytes32 uniqueKey = concreteStorage.CreateKey("Protocol", "Token.User.Balance", address(0x2));
concreteStorage.setUint(uniqureKey, uint(balance));

Here, "Protocol" represents the namespace, "Token.User.Balance" is the pointer, and address(0x2) is the specific key-value data. This method allows us to maintain a clear organizational structure within our storage system. Lastly, we can use the newly created key and call the set uint function from storage, and set the balance for the user.

Breaking it down further, each mapping serves as a distinct storage map. The keys in these maps are constructed from two primary components:

  • The namespace of the key, occupying the first 4 bytes, which categorizes the data.

  • The identifier for the entry, filling the remaining 28 bytes, which would be the pointer and the key value which will uniquely identifies each data point within its category to the key-value data.

By employing this two-part key structure, we ensure that our storage system is both organized and efficient.

Last updated