From Role Base Access Control to a Role & Permission Access Control on Blockchain.
Having read a great article “ Role Based Access Control for the Ethereum Blockchain” from Alberto Cuesta Cañada in Hackernoon https://hackernoon.com/role-based-access-control-for-the-ethereum-blockchain-bcc9dfbcfe5c.
I decided to embrace his advise and extended the capability offered by Alberto’s RBAC smart contract implementation , it was not a easy task and yet it was very joyful to understand further more details of solidity complexities when it comes to the usage of data structures ( mapping, arrays, list, etc).
I have worked with solidity in the past to develop proof of concepts for my customers, had suffered the shortcomings of the language and yet find extremely difficult to find out someone who can explain things in a easy-to-understand manner. In this regard Julien Klepatch and his youtube channel https://www.youtube.com/channel/UCZM8XQjNOyG2ElPpEUtNasA/channels was very useful for me to grasp a better knowledge.
After spending some time listening and going back and foward between the videos and Alberto’s RBAC smart contract code it became clear that I’d like to develop a function that allowed to assign permissions to an address, thus will be far more intuitive to grant permission to an account an to group accounts based on the assigned role.
So after researched for solidity patterns https://ethereum.stackexchange.com/questions/13167/are-there-well-solved-and-simple-storage-patterns-for-solidityto deal with
Mapping with Struct
Strengths
- Random access by unique Id
- Assurance of Id Uniqueness
- Enclose arrays, mappings, structs within each “record”
Weaknesses
- Unable to enumerate the keys
- Unable to count the keys
- Needs a manual check to distinguish a default from an explicitly “all 0” record
Mapped Structs with Index
Strengths
- Random access by unique Id or row number
- Assurance of Id uniqueness
- Enclose arrays, mappings and structs within each “record”
- List maintains order of declaration
- Count the records
- Enumerate the Ids
- “Soft” delete an item by setting a boolean
Weaknesses
- Uncontrolled growth of the list
Mapped Structs with Delete-enabled Index
Strengths
- Random access by unique Id or row number
- Assurance of Id uniqueness
- Enclose arrays, mapping and structs within each “record”
- Count the records
- Enumerate the ids
- Logically control the size of the active list with delete function
Weaknesses
- Marginally increased code complexity
- Marginally higher storage costs
- Key list is inherently unordered
Array of Structs with Unique Ids
Strengths
- Random access by Row number
- Assurance of Id uniqueness
- Enclose arrays, mappings and structs with each “record”
Weaknesses
- No random access by Id
- Uncontrolled growth of the list
The path was clear to implement the functions that I envisioned to work on Alberto’s RBAC smart contract. Finally I put it together in a new smart contract called RPAC.sol and below just the depicted the new struct Permission and functions to manipulate them.
I encourage you to deploy and customize it for any purpose in the implementation of your use case.
https://github.com/mauriciomferz/RPAC/blob/master/RPAC.sol
Published at Tue, 15 Oct 2019 14:21:24 +0000
{flickr|100|campaign}
