Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any problems in PveBotSystem.checkCorValidity? #201

Open
VictorECDSA opened this issue Dec 12, 2023 · 1 comment
Open

Is there any problems in PveBotSystem.checkCorValidity? #201

VictorECDSA opened this issue Dec 12, 2023 · 1 comment

Comments

@VictorECDSA
Copy link
Contributor

VictorECDSA commented Dec 12, 2023

I have some questions about this function and don't know if I understand it correctly.

contract PveBotSystem is System {
    function checkCorValidity(address player, uint32 x, uint32 y) internal view returns (bool hasErr) {
        // check x, y validity
        require(x < GameConfig.getLength(0), "x too large");
        require(y < GameConfig.getWidth(0), "y too large");

        // check whether (x,y) is empty
        uint256 cor = Coord.compose(x, y);
        // loop piece to check whether is occupied
        for (uint256 i = 0; i < Player.lengthHeroes(player); i++) {
            bytes32 key = Player.getItemHeroes(player, i);
            HeroData memory hero = Hero.get(key);
            if (cor != Coord.compose(hero.x, hero.y)) {
                hasErr = true;
            }
            // require(cor != Coord.compose(hero.x, hero.y), "this location is not empty");
        }

        hasErr = false;
    }
  1. There is no 'return' branch to distinguish 'right' and 'wrong'. So the result of it will be always 'hasErr = false'.

  2. The require sentence will lead to transaction failure.

  3. The condition 'cor != Coord.compose(hero.x, hero.y' will be achieved at least one time, once if player have more than 2 heroes.

@ClaudeZsb
Copy link
Collaborator

hasErr = false seems like a cheat code for the reason of testing or getting PvE feature live quickly. @aLIEzsss4

And we did lack of careful review. Our bad.

This function has problems as @fenghaoming said. Besides, obviously the inner checking of position should be if (cor == Coord.compose(hero.x, hero.y)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants