Potential uninitialized entropySlots reading in getNextEntropy , causing 0 entropy mint
pep7siup Follow with anonymousjoe, boredpukar and 3 others
Originally disclosed on Code4rena
Submitted by pep7siup, also found by anonymousjoe, boredpukar, amaron, shaflow2, and d3e4
The getNextEntropy function can be called at any time without waiting for the write entropy batches process to finish. This could lead to the function returning an uninitialized entropy value of 000000, resulting in users losing funds to mint useless tokens and not being eligible for future airdrops as they get 0 shares. This vulnerability can severely impact the users’ trust and the protocol’s functionality.
Proof of Concept
Found in contracts/EntropyGenerator/EntropyGenerator.sol at Line 103:
If
currentSlotIndex > lastInitializedIndex(writeEntropyBatchprocess not complete),getEntropywould return entropy = 000000 instead of revert. Which leads to user mint entities with 0 entropy.
101: function getNextEntropy() public onlyAllowedCaller returns (uint256) {
102: require(currentSlotIndex <= maxSlotIndex, 'Max slot index reached.');
103:@> uint256 entropy = getEntropy(currentSlotIndex, currentNumberIndex);
104:
...
120: }
POC
Apply following POC via git apply POC.patch and run yarn test. The test confirms getNextEntropy did return entropy 0 instead of revert.
diff --git a/test/EntropyGenerator.test.ts b/test/EntropyGenerator.test.ts
index 69551f5..f7e8698 100644
--- a/test/EntropyGenerator.test.ts
+++ b/test/EntropyGenerator.test.ts
@@ -3,7 +3,7 @@ import { ethers } from 'hardhat';
import { EntropyGenerator } from '../typechain-types';
import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
-describe('EntropyGenerator', function () {
+describe.only('EntropyGenerator', function () {
let entropyGenerator: EntropyGenerator;
let owner: HardhatEthersSigner;
let allowedCaller: HardhatEthersSigner;
@@ -32,6 +32,15 @@ describe('EntropyGenerator', function () {
expect(updatedCaller).to.equal(allowedCaller);
});
+ it('getNextEntropy returns 0 entropy if entropySlots not properly init', async function () {
+ // call getNextEntropy when write entropy batches not finished
+ await expect(
+ entropyGenerator.connect(allowedCaller).getNextEntropy()
+ ).to.emit(entropyGenerator, 'EntropyRetrieved').withArgs(0);
+
+ // @audit: should revert getNextEntropy if entropySlots not properly init
+ });
+
it('should write entropy batches 1', async function () {
// Write entropy batch 1
await entropyGenerator.writeEntropyBatch1();
Tools Used
Hardhat
Recommended Mitigation Steps
Only allow getNextEntropy call if currentSlotIndex < lastInitializedIndex to ensure that the entropy slots are properly initialized:
function getNextEntropy() public onlyAllowedCaller returns (uint256) {
...
+ require(currentSlotIndex < lastInitializedIndex, 'Slot not initialized');
uint256 entropy = getEntropy(currentSlotIndex, currentNumberIndex);
Abdessamed (warden) commented:
@Koolex Sorry for dropping a comment now, but this is a completely invalid issue. The
entropySlotswill be initialized just after the deployment. This is confirmed by the deploy script.
Please check this for more context.
Abdessamed (warden) commented:
@Koolex - The validity of this issue is based on the timeframe after deployment where the entropies are not initialized, as stated by the sponsor:
This is a valid issue as there could be a timeframe where there is no initialised entropy. Better yet, we should put a batch in constructor to be sure of mitigation.
However, this information was not accessible during the audit and the deployment script I pointed out above contradicts this fact and demonstrates that entropies will be initiated just after the deployment.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in TraitForge. Code4rena made it public on 13 September 2024. Found in the 2024-07-traitforge audit contest (finding M-01), also found by 5 other wardens.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.