Skip to content

Arena Contract Review #1

@drmathias

Description

@drmathias

Hi, I took some time to review the Arena contract and left my findings below:


Battle Id is not validated, allowing battle to be overwritten. Consider storing an incremental counter for battle id in the contract and returning battle id from method.

SetBattle(battleId, battle);


User index is not validated, making it possible for anyone to overwrite a battle user. Consider setting user index from an incremental counter.

battle.Users.SetValue(user.Address, userindex);


If scores are tied, the user with a lower index will win and the prize will not be split. Is this intended?

if (user.Score > winningScore)


Condition will always be true, as users array is always initialised with a length of 4. Remove to lower gas cost.

if (battle.Users.Length <= 4)


Condition will always be true, as was previously asserted. Remove to lower gas cost.

if (battle.Winner == Address.Zero)


Prize value considers battle has 4 users. If the battle ends without 4 users, the transfer will fail. Is it intended that every battle must have 4 users?

ulong prize = battle.Fee * (battle.MaxUsers - 1);


Methods returning bool will always return true. Consider making return type void instead.

return true;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions