Platform: Code4rena
Start Date: 09/02/2024
Pot Size: $60,500 USDC
Total HM: 17
Participants: 283
Period: 12 days
Judge:
Id: 328
League: ETH
Rank: 139/283
Findings: 2
Award: $20.07
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xSmartContract
Also found by: 0xAsen, 0xDetermination, 0xStriker, 0xblack_bird, 0xbrett8571, 0xepley, 0xweb3boy, 14si2o_Flint, Bauchibred, DarkTower, JayShreeRAM, JcFichtner, K42, McToady, Myd, PoeAudits, Rolezn, SAQ, ZanyBonzy, aariiif, albahaca, ansa-zanjbeel, cheatc0d3, clara, cudo, dimulski, fouzantanveer, foxb868, hassanshakeel13, hunter_w3b, kaveyjoe, klau5, peanuts, pipidu83, popeye, rspadi, scokaf, shaflow2, tala7985, wahedtalash77, yongskiws
20.0744 USDC - $20.07
AI Arena establishes an intricate gaming economy around tradable NFT fighters powered by machine learning models. Users battle their AIs in a decentralized PvP platform to earn token rewards.
Architecture
The core gameplay logic resides off-chain in the game servers, which act as oracles submitting match results on-chain. Smart contracts enforce ownership, ratings, and incentive models.
FighterFarm
- Minting and metadata for NFT fightersGameItems
- Purchase in-game assetsRankedBattles
- Staking, match adjudication, rewards distributionNeuron
- ERC20 utility token for incentives+----------------------------+\ | UI | +----------------------------+/ | Front-End App | +----------------------------+ | Oracle | | (Game Server) | +----------------------------+ | | | Smart Contracts | | | +----------------------------+ | EVM | +----------------------------+ \ / | Blockchain | / \ +----------------+
The game servers act as the oracle managing fight outcomes and rankings.
Design Patterns
Security Analysis
But risks remain around unchecked oracle inputs, overpowered admin roles, and economic stability.
Risk Vectors
Testing & Audits
Centralization Risks
The RankedBattles
contract shows total trust in the opaque gameServer
oracle:
No verification checks against the inputs opens manipulation vectors.
Incentives Review
The Staking
contract enforces a square root curve when rewarding stakes:
points = sqrt(stakeAmount + riskAmount) * eloMultiplier
Curbing returns to scale helps sustainability.
Admins could selectively pick acquaintances or "favored" addresses as winners rather than true randomness
The randomness process occurring off-chain has potential for bias influence if improper tools or weak protocols used
If the selection admin account was compromised, attacker could exploit
Mitigation Strategies:
Have an on-chain DAO of trusted community members confirm admin picks before recording
Utilize proper tools like Chainlink VRF for performing robust verifiable randomness off-chain
Separate admin roles - one to run selection, one to confirm and record winners
Audit selection software and admin processes regularly for fairness
Provide transparency to community by publishing details of off-chain selection protocols
Allow third-party Solidity contract to view winners then encrypt for delayed reveal to mitigate temporary compromise recovery time
By decentralizing control, leveraging trusted blockchain-native randomness, enacting process controls, and pursuing regular auditing - risks around manipulation and bias can be greatly reduced in order to uphold selection integrity. Community involvement also brings additional guardrails.
For admins to manipulate the raffle selection process in the MergingPool contract.
The key vulnerability stems from the pickWinner
function, which relies on admins to provide the array of tokenIds for each period's winners:
function pickWinner(uint256[] calldata winners) external { require(isAdmin[msg.sender]); // Save winner addresses and reset points }
By placing full trust in admins to supply the winner data, this creates the opportunity for malicious or biased selection:
Attack Scenario
A compromised admin could call pickWinner
and cherry-pick acquaintances to "win" the raffle rather than true random addresses
Over time, this allows them to disproportionately distribute special NFT rewards to friends rather than the intended random distribution
If the attack goes undetected, they could slowly syphon rare NFTs by social engineering
Root Cause
The root cause is that the contract code does not actually enforce or validate randomness. It fully trusts the admin's supplied data.
Impact
Mitigations
Use a DAO of multiple admins to provide checks and balances
Leverage ChainLink VRF to provably inject verified randomness
Publish details of off-chain selection for transparency
By addressing the root over-reliance on a single admin, adding transparency, and integrating blockchain-enabled randomness, the risks can be reduced considerably while retaining admin functionality.
While the on-chain MergingPool
contract records winners, it currently depends on some off-chain process to actually generate that random data:
// OFF-CHAIN randomness generation function pickWinner(uint256[] calldata winners) external { // On-chain recording }
If improper randomness tools or weak protocols are used off-chain, there is risk of predictable or biased results:
Attack Scenario
Root Cause
The root cause is reliance on unproven or centralized off-chain protocols lacking cryptography. Without rigour here, the on-chain contract is powerless to enforce proper randomness.
Impact
Mitigations
This analysis underscores the severe vulnerabilities introduced through opaque off-chain components interacting with on-chain logic. By transitioning to trustless blockchain-based randomness and enabling transparency, we gain significant assurances.
Governance rights in the AI Arena smart contracts are handled in a centralized fashion through the use of admin roles and owner addresses. Here are some key details:
Most contracts have an _ownerAddress
set at deployment via the constructor.
Owner addresses can unilaterally call restricted functions like transferring ownership or adjusting parameters.
There is also an isAdmin
mapping that grants privileges to additional admin addresses.
Only owners can add/remove admin role assignments using functions like addAdmin
or adjustAdminAccess
.
Typical admin privileges include pausing/unpausing functionality, changing key parameters, or distributing tokens.
Some execution like winner selection in MergingPool does rely on admins being "honest" actors.
So in summary:
Governance follows a centralized admin model rather than decentralized community vote-based model.
Contract ownership and parameterization control rests firmly with the ArenaX team and appointed admins.
There are some trusts placed in proper admin execution for key processes.
The contracts do not impose checks and balances or separation of duties on admins. So governance aligns more with an authoritative hierarchy rather than emergent consensus - retaining control for the originating business entity.
Opportunities
AI Arena establishes an exciting foundation spanning machine learning, incentives design, and NFT collateralization. But for long-term sustainability, reducing points of centralization and mathematically proving hyper-incentive alignment will be key. The project shows promise in exploring futuristic intersections of technology, economics, and governance.
30 hours
#0 - c4-pre-sort
2024-02-25T20:28:53Z
raymondfam marked the issue as sufficient quality report
#1 - c4-judge
2024-03-19T08:18:33Z
HickupHH3 marked the issue as grade-b