Prepared by:
HALBORN
Last Updated 04/26/2024
Date of Engagement by: August 8th, 2022 - August 11th, 2022
0% of all REPORTED Findings have been addressed
All findings
5
Critical
0
High
0
Medium
1
Low
1
Informational
3
Seascape engaged Halborn to conduct a security audit on their smart contracts beginning on August 11th, 2022 and ending on August 12th, 2022. The security assessment was scoped to the smart contract provided in the GitHub repository blocklords/miner-smartcontract
The team at Halborn was provided a week for the engagement and assigned two full-time security engineers to audit the security of the smart contract. The security engineers are blockchain and smart-contract security experts with advanced penetration testing, smart-contract hacking, and deep knowledge of multiple blockchain protocols.
The purpose of this audit is to:
Ensure that smart contract functions operate as intended
Identify potential security issues with the smart contracts
In summary, Halborn identified some security risks that were mostly addressed by Seascape
team.
Halborn performed a combination of manual and automated security testing to balance efficiency, timeliness, practicality, and accuracy in regard to the scope of this audit. While manual testing is recommended to uncover flaws in logic, process, and implementation; automated testing techniques help enhance coverage of the code and can quickly identify items that do not follow the security best practices. The following phases and associated tools were used during the audit:
Research into architecture and purpose
Smart contract manual code review and walkthrough
Graphing out functionality and contract logic/connectivity/functions (solgraph
)
Manual assessment of use and safety for the critical Solidity variables and functions in scope to identify any arithmetic related vulnerability classes
Manual testing by custom scripts
Scanning of solidity files for vulnerabilities, security hotspots or bugs. (MythX
)
Static Analysis of security for scoped contract, and imported functions. (Slither
)
Testnet deployment (Brownie
, Remix IDE
)
IN-SCOPE: The security assessment was scoped to the following smart contract:
MineNFTFactory.sol
MinerGame.sol
MinerNFT.sol
NFTTypes.sol
CrownsToken.sol
MscpToken.sol
Commit ID:
Fixed commit ID:
Critical
0
High
0
Medium
1
Low
1
Informational
3
Impact x Likelihood
HAL-02
HAL-01
HAL-03
HAL-04
HAL-05
Security analysis | Risk level | Remediation Date |
---|---|---|
SIGNATURE NONCES ARE IMPLEMENTED INCORRECTLY | Medium | - |
REENTRANCY IN MINERGAME.EXPORTNFT FUNCTION | Low | - |
UNUSED STORAGE POINTER IN MINERGAME.GOLDCHANGETOKEN FUNCTION | Informational | - |
POSSIBLE MISUSE OF PUBLIC FUNCTIONS | Informational | - |
STATE VARIABLES MISSING CONSTANT MODIFIER | Informational | - |
// Medium
In the MinerGame
contract a nonce state variable is used to prevent signature replay attacks:
uint256 public nonce;
function importNft(uint256 _nftId, uint8 _v, bytes32 _r, bytes32 _s) external {
require(_nftId > 0, "MinerGame: nft Id invalid");
MineNFT nft = MineNFT(mineNft);
require(nft.ownerOf(_nftId) == msg.sender, "MinerGame: Not mineNft owner");
{
bytes memory prefix = "\x19Ethereum Signed Message:\n32";
bytes32 message = keccak256(abi.encodePacked(_nftId, msg.sender, address(this), nonce));
bytes32 hash = keccak256(abi.encodePacked(prefix, message));
address recover = ecrecover(hash, _v, _r, _s);
require(recover == verifier, "Verification failed about stakeToken");
}
nft.safeTransferFrom(msg.sender, address(this), _nftId);
nonce++;
PlayerParams storage _player = player[msg.sender];
_player.nftId = _nftId;
_player.stakeTime = block.timestamp;
mineOwners[_nftId] = msg.sender;
emit ImportNft(msg.sender, _nftId, block.timestamp);
}
\color{black} \color{white}
function goldChangeToken(uint256 _gold, uint8 _v, bytes32 _r, bytes32 _s) external {
require(_gold > 0, "MinerGame: The exchange amount must greater than zero");
uint256 chainId;
assembly {
chainId := chainid()
}
PlayerParams storage _player = player[msg.sender];
{
bytes memory prefix = "\x19Ethereum Signed Message:\n32";
bytes32 message = keccak256(abi.encodePacked(_gold, msg.sender, nonce, address(this), chainId));
bytes32 hash = keccak256(abi.encodePacked(prefix, message));
address recover = ecrecover(hash, _v, _r, _s);
require(recover == verifier, "Verification failed about stakeToken");
}
nonce++;
uint256 _tokenAmount = _gold * MULTIPLIER / ratio;
_safeTransfer(token[0], msg.sender, _tokenAmount);
emit GoldChangeToken(msg.sender, _gold, _tokenAmount, block.timestamp);
}
}
\color{black} \color{white}
This nonce
variable is increased every time the functions importNft()
or goldChangeToken()
are called. Although, the signer, does not really know the order in which the users are going to call these functions. Hence, if the backend for example generates a signature for a user and this user does not call the function right after that his signature will be invalid after someone else calls any of those functions.
// Low
In the MinerGame
contract the exportNft()
function is used to "unstake" the Mine NFT:
function exportNft(uint256 _nftId) external {
require(mineOwners[_nftId] == msg.sender, "MinerGame: Not the owner");
MineNFT nft = MineNFT(mineNft);
nft.safeTransferFrom(address(this), msg.sender, _nftId);
PlayerParams storage _player = player[msg.sender];
delete _player.nftId;
delete _player.stakeTime;
delete mineOwners[_nftId];
emit ExportNft(msg.sender, _nftId, block.timestamp);
}
\color{black} \color{white}
As we can see above, the Mine NFT is sent back to the user with a safeTransferFrom()
call. This safeTransferFrom()
calls check if the receiver is a smart contract and if so, it calls the _checkOnERC721Received hook.
This passed the control flow to the receiver and opens up a reentrancy vulnerability as the user, in this case the smart contract, got the NFT but the state variables player[msg.sender]
and mineOwners[_nftId]
are still not deleted/updated.
// Informational
In the MinerGame
contract the goldChangeToken()
creates an storage pointer to the player
mapping but then it does not make any use of it:
function goldChangeToken(uint256 _gold, uint8 _v, bytes32 _r, bytes32 _s) external {
require(_gold > 0, "MinerGame: The exchange amount must greater than zero");
uint256 chainId;
assembly {
chainId := chainid()
}
PlayerParams storage _player = player[msg.sender];
{
bytes memory prefix = "\x19Ethereum Signed Message:\n32";
bytes32 message = keccak256(abi.encodePacked(_gold, msg.sender, nonce, address(this), chainId));
bytes32 hash = keccak256(abi.encodePacked(prefix, message));
address recover = ecrecover(hash, _v, _r, _s);
require(recover == verifier, "Verification failed about stakeToken");
}
nonce++;
uint256 _tokenAmount = _gold * MULTIPLIER / ratio;
_safeTransfer(token[0], msg.sender, _tokenAmount);
emit GoldChangeToken(msg.sender, _gold, _tokenAmount, block.timestamp);
}
\color{black} \color{white}
// Informational
In multiple contracts there are functions marked as public
but they are never directly called within the same contract or in any of their descendants:
MineNFTFactory.sol
mint()
(MineNFTFactory.sol#34-37)setNft()
(MineNFTFactory.sol#42-44)addAdmin()
(MineNFTFactory.sol#47-50)renounceAdmin()
(MineNFTFactory.sol#53-56)addGenerator()
(MineNFTFactory.sol#85-88)removeGenerator()
(MineNFTFactory.sol#91-94)MineNFT.sol
mint()
(MineNFT.sol#35-46)setOwner()
(MineNFT.sol#48-50)setFactory()
(MineNFT.sol#52-54)setBaseUri()
(MineNFT.sol#56-58)MinerGame.sol
withdraw()
(MinerGame.sol#188-195)addToken()
(MinerGame.sol#198-206)setScale()
(MinerGame.sol#209-212)CrownsToken.sol
burn()
(CrownsToken.sol#96-98)burnFrom()
(CrownsToken.sol#111-118)name()
(CrownsToken.sol#127-129)symbol()
(CrownsToken.sol#135-137)decimals()
(CrownsToken.sol#148-150)totalSupply()
(CrownsToken.sol#155-157)balanceOf()
(CrownsToken.sol#162-164)transfer()
(CrownsToken.sol#173-176)approve()
(CrownsToken.sol#203-206)transferFrom()
(CrownsToken.sol#217-227)increaseAllowance()
(CrownsToken.sol#241-244)decreaseAllowance()
(CrownsToken.sol#260-268)MscpToken.sol
burn()
(MscpToken.sol#96-98)burnFrom()
(MscpToken.sol#111-118)name()
(MscpToken.sol#127-129)symbol()
(MscpToken.sol#135-137)decimals()
(MscpToken.sol#148-150)totalSupply()
(MscpToken.sol#155-157)balanceOf()
(MscpToken.sol#162-164)transfer()
(MscpToken.sol#173-176)approve()
(MscpToken.sol#203-206)transferFrom()
(MscpToken.sol#217-227)increaseAllowance()
(MscpToken.sol#241-244)decreaseAllowance()
(MscpToken.sol#260-268)// Informational
State variables can be declared as constant
or immutable
. In both cases, the variables cannot be modified after the contract has been constructed. For constant
variables, the value has to be fixed at compile-time, while for immutable
, it can still be assigned at construction time. The following state variables are missing the constant
modifier:
CrownsToken.sol
uint256 public limitSupply = 1111111111000000000000000000; /// 1.1 billion
MscpToken.sol
uint256 public limitSupply = 1111111111000000000000000000; /// 1.1 billion
Halborn used automated testing techniques to enhance the coverage of certain areas of the smart contracts in scope. Among the tools used was Slither, a Solidity static analysis framework. After Halborn verified the smart contracts in the repository and was able to compile them correctly into their abis and binary format, Slither was run against the contracts. This tool can statically verify mathematical relationships between Solidity variables to detect invalid or inconsistent usage of the contracts' APIs across the entire code-base.
MineNFTFactory.sol
MinerGame.sol
MineNFT.sol
NFTTypes.sol
No issues found by Slither.
CrownsToken.sol
MscpToken.sol
The reentrancies flagged were checked individually and are all false positives except the one mentioned in the findings.
No major issues found by Slither.
Halborn strongly recommends conducting a follow-up assessment of the project either within six months or immediately following any material changes to the codebase, whichever comes first. This approach is crucial for maintaining the project’s integrity and addressing potential vulnerabilities introduced by code modifications.
// Download the full report
* Use Google Chrome for best results
** Check "Background Graphics" in the print settings if needed