Hi @PhABC
Thank you for your article and code URLs. Very thought provoking!
May I suggest the use of convention for assigning micro slots inside the uint256 data type. For example there are 77 (0-9) digits available. The factors of 77 are 1, 7, 11 and 77. Therefore the following options will explicitly segment the uint256 and ensure that as much of the uint256 is being used.
- 1, 77 digit integer with an individual value between 0 and 99999999999999999999999999999999999999999999999999999999999999999999999999999
- 77, 1 digit integers with an individual value between 0 and 9
- 7, 11 digit integers with an individual value between 0 and 99999999999
- 11, 7 digit integers with an individual value between 0 and 9999999
I have provided some Solidity code below which enforces the last bullet point from above; provides 11 unique slots, each of which can contain a maximum of 7 digits (total value of between 0 and 9999999).
pragma solidity ^0.5.0;
// The following contract uses a fixed convention which provides 11 unique micro-slots, each with 7 digits between 0 and 9.
// Each of the functions are designed to explicitly return the appropriate slot.
// Warning: This is a prototype for research purposes and it is not to be used to transact real value yet.
contract MicroSlots{
// This variable must be set to 77 digits between 0 and 9
uint256 private value = 76543210000000000000000000000000000000000055555554444444333333322222221111111;
// TODO This contract needs modifiers which will only allow numbers between 1 and 9999999 to be set for each position
// Returns 1111111
function getPosition1() public view returns(uint256){
return ((value % (10 ** 7)) - (value % (10 ** (7 - 7)))) / (10 ** (7 - 7));
}
// Returns 2222222
function getPosition2() public view returns(uint256){
return ((value % (10 ** 14)) - (value % (10 ** (14 - 7)))) / (10 ** (14 - 7));
}
// Returns 3333333
function getPosition3() public view returns(uint256){
return ((value % (10 ** 21)) - (value % (10 ** (21 - 7)))) / (10 ** (21 - 7));
}
//Returns 4444444
function getPosition4() public view returns(uint256){
return ((value % (10 ** 28)) - (value % (10 ** (28 - 7)))) / (10 ** (28 - 7));
}
// Returns 5555555
function getPosition5() public view returns(uint256){
return ((value % (10 ** 35)) - (value % (10 ** (35 - 7)))) / (10 ** (35 - 7));
}
// Returns 0000000
function getPosition6() public view returns(uint256){
return ((value % (10 ** 42)) - (value % (10 ** (42 - 7)))) / (10 ** (42 - 7));
}
// Returns 0000000
function getPosition7() public view returns(uint256){
return ((value % (10 ** 49)) - (value % (10 ** (49 - 7)))) / (10 ** (49 - 7));
}
// Returns 0000000
function getPosition8() public view returns(uint256){
return ((value % (10 ** 56)) - (value % (10 ** (56 - 7)))) / (10 ** (56 - 7));
}
// Returns 0000000
function getPosition9() public view returns(uint256){
return ((value % (10 ** 63)) - (value % (10 ** (63 - 7)))) / (10 ** (63 - 7));
}
// Returns 0000000
function getPosition10() public view returns(uint256){
return ((value % (10 ** 70)) - (value % (10 ** (70 - 7)))) / (10 ** (70 - 7));
}
// Returns 7654321
function getPosition11() public view returns(uint256){
return ((value % (10 ** 77)) - (value % (10 ** (77 - 7)))) / (10 ** (77 - 7));
}
}
The above contract has been deployed on the Ropsten Testnet at the following address
0xc7b6ac40d8557de62a33f5bcec6c4dc443fbd0f3
The functions are all public view so please feel free to interact with it.
Again, thank you so much for your response!