crytic / crytic/slither

[Bug]: IndexError: list index out of range when lowering `NewStructure`

Open
#2,204 1 comment 0 reactions 0 assignees View on GitHub
bug Need more info
Dominant language
Python
Stars
6.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

### Describe the issue:

Getting this quite a bit putting slither onto a new project. Is there a workaround or way to ignore?

### Code example to reproduce the issue:

```Solidity
function _checkStakedNfts(
address account,
uint256 activeBountyId
) internal returns (bool) {
bool failedBounty;
// Get user ActiveBounty component
(, , , , , uint256[] memory entityInputs) = ActiveBountyComponent(
_gameRegistry.getComponent(ACTIVE_BOUNTY_COMPONENT_ID)
).getValue(activeBountyId);
// Check that user still owns all the NFTs they staked for the bounty
uint256 tokenId;
address tokenContract;
NFTActiveBountyComponent nftActiveBountyComponent = NFTActiveBountyComponent(
_gameRegistry.getComponent(NFT_ACTIVE_BOUNTY_COMPONENT_ID)
);
for (uint256 i = 0; i < entityInputs.length; ++i) {
(tokenContract, tokenId) = EntityLibrary.entityToToken(
entityInputs[i]
);
NFTActiveBountyComponentStruct
memory nftActiveBounty = nftActiveBountyComponent
.getLayoutValue(entityInputs[i]);
// Get NFT current owner address
address nftOwner = IERC721(tokenContract).ownerOf(tokenId);
if (nftActiveBounty.shouldCheckNft == true) {
// If activeBountyId matches and caller is owner then clear the component
if (
activeBountyId == nftActiveBounty.activeBountyId &&
account == nftOwner
) {
nftActiveBountyComponent.setLayoutValue(
entityInputs[i],
NFTActiveBountyComponentStruct(0, address(0), true)
);
} else {
// Otherwise mark bounty as failed
failedBounty = true;
}
} else {
// Only verify ownership
if (account != nftOwner) {
failedBounty = true;
}
}
}
return failedBounty;
}
```

Another
```Solidity
function _checkAndSetNftActiveBountyComponent(
NFTActiveBountyComponent nftActiveBountyComponent,
uint256 entityId,
uint256 activeBountyId,
address account
) internal {
NFTActiveBountyComponentStruct
memory nftActiveBounty = nftActiveBountyComponent.getLayoutValue(
entityId
);
// If the Pirate is on Bounty that belongs to caller wallet and its activeBountyId is not 0 then revert
if (
nftActiveBounty.walletUsed == account &&
nftActiveBounty.activeBountyId != 0
) {
revert BountyStillRunning();
}
// NFTActiveBountyComponent on this NFT: activeBountyId, walletUsed, timeLock, shouldCheckNft (for existing cases)
nftActiveBountyComponent.setLayoutValue(
entityId,
NFTActiveBountyComponentStruct(activeBountyId, account, true)
);
}
```

### Version:

0.10.0

### Relevant log output:

```shell
'npx hardhat clean' running (wd: /home/mattvv/pop/pirates-web-ts/packages/hardhat-ts)
'npx hardhat clean --global' running (wd: /home/mattvv/pop/pirates-web-ts/packages/hardhat-ts)
'npx hardhat compile --force' running (wd: /home/mattvv/pop/pirates-web-ts/packages/hardhat-ts)
ERROR:SlitherSolcParsing:
Failed to generate IR for BountySystem._checkStakedNfts. Please open an issue https://github.com/crytic/slither/issues.
BountySystem._checkStakedNfts (contracts/bounty/BountySystem.sol#596-642):
(entityInputs) = ActiveBountyComponent(_gameRegistry.getComponent(ID)).getValue(activeBountyId)
nftActiveBountyComponent = NFTActiveBountyComponent(_gameRegistry.getComponent(ID))
i = 0
i < entityInputs.length
(tokenContract,tokenId) = EntityLibrary.entityToToken(entityInputs[i])
nftActiveBounty = nftActiveBountyComponent.getLayoutValue(entityInputs[i])
nftOwner = IERC721(tokenContract).ownerOf(tokenId)
nftActiveBounty.shouldCheckNft == true
activeBountyId == nftActiveBounty.activeBountyId && account == nftOwner
nftActiveBountyComponent.setLayoutValue(entityInputs[i],Layout(0,address(0),true))
failedBounty = true
account != nftOwner
failedBounty = true
++ i
failedBounty
Traceback (most recent call last):
File "/home/mattvv/.local/bin/slither", line 8, in
sys.exit(main())
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/__main__.py", line 727, in main
main_impl(all_detector_classes=detectors, all_printer_classes=printers)
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/__main__.py", line 833, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/__main__.py", line 107, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/__main__.py", line 80, in process_single
slither = Slither(target, ast_format=ast, **vars(args))
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/slither.py", line 144, in __init__
self._init_parsing_and_analyses(kwargs.get("skip_analyze", False))
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/slither.py", line 164, in _init_parsing_and_analyses
raise e
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/slither.py", line 160, in _init_parsing_and_analyses
parser.analyze_contracts()
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 539, in analyze_contracts
self._convert_to_slithir()
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 765, in _convert_to_slithir
raise e
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 750, in _convert_to_slithir
func.generate_slithir_and_analyze()
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/core/declarations/function.py", line 1767, in generate_slithir_and_analyze
node.slithir_generation()
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/core/cfg/node.py", line 716, in slithir_generation
self._irs = convert_expression(expression, self) # type:ignore
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/slithir/convert.py", line 118, in convert_expression
result = apply_ir_heuristics(result, node, is_solidity)
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/slithir/convert.py", line 2016, in apply_ir_heuristics
convert_constant_types(irs)
File "/home/mattvv/.local/lib/python3.10/site-packages/slither/slithir/convert.py", line 1943, in convert_constant_types
e = st.elems_ordered[idx]
IndexError: list index out of range
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.