1

I've made a game that depends on a counter, the first user that get to the target wins. Can someone exploit this and always win?

I know that everyone can know the current count, but since there are multiple people competing, I'm not really sure if someone could always get in the the right position everytime.

I've been looking for 2 days, and haven't found an exact answer (Maybe I'm looking the wrong way).

Here's a dumbed down version of the contract.

pragma solidity ^0.4.19;

contract Ten {

    uint counter = 0;

    function increment() external {

        counter++;

        if(counter == 10) {
            // User won - Give hime the prize
            counter = 0;
        }

    }

}

3 Answers 3

4

The other answers have mentioned front-running by other users, by sending a transaction with a high gas price.

What hasn't been mentioned is front-running by miners. When creating a block, miners can include any transactions they like; they needn't stick to the "highest gas price first" rule.

As such, a miner could include their own transaction ahead of anyone else's. Further, they needn't wait for the counter to read 9 - they could just submit 10 transactions and include them all in the same block, which they themselves are mining.

1

all I see is potential frontrunning. By manipulating the gas price, it is possible to get a desired transaction executed ahead of all others in the current block. The transaction with the highest gas price will be executed first.

0
1

Any variable stored on the base level of a contract is automatically publically readable...even if set to private.

It will be pretty easy for another programmer to game the system and read that publically stored value and wait for the counter to hit 9 before executing the contract with a high gas price.

It won't make for a very fair game, unfortunately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.