-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
The function signature for Blockchain.getStorage / Blockchain.putStorage encourages boilerplate code and this results in unsafe implementations.
- Assumption: every contract using Blockchain.putStorage are implementing hashmaps/arrays
- Assumption: every contract using Blockchain.putStorage has 2 or more hashmaps/arrays
- Now therefore, the following will be best practice for every contract:
private enum StorageSlots {
NamesArray,
BalancesHashMap
}
Blockchain.putStorage(
Blockchain.blake2b(
AionBuffer.allocate(SOMETHING_GOES_HERE)
.putInt(StorageSlots.NamesArray.toString())
// .put* PUT OTHER STUFF HERE
.getArray();
),
SOME_VALUE
);Therefore, in every case, the boilerplate can be factored out at least to:
Blockchain.putStorage(
STORGE_SLOT,
SUB_SLOT,
SOME_VALUE
);where SUB_SLOT can be null or any value. And then this new function will apply Blockchain.blake2b to SUB_SLOT.
In every case it seems that this API would be safer, semantic and reduce verbosity, therefore I recommend that this replace the existing API.
References
- --NO LINK YET-- Will's upcoming AIP
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels