fuguefoundation / smart-contracts

https://etherscan.io/address/0xfbf9ae92ecb05bc436d9b1e6c1d928824aedb2f1
1 stars 1 forks source link

`payout` function very broken #5

Open adamdossa opened 6 years ago

adamdossa commented 6 years ago

Couple of issues:

  1. the function is marked as payable which it shouldn't be and could lose ETH.
  2. the function has an unbounded loop which means if too many people "play" the contract will never pay out - this has happened to other similar contracts and needs to be resolved!

One approach here is to keep guesses in an ordered linked list. You can check the winner by having a function that takes a 'seed' to start searching in the linked list which means it can be executed in constant time (calculating the seed off-chain).

fuguefoundation commented 6 years ago

Thanks! Took care of point one. Do you know of a code or contract example of your linked list approach that I could refer to?

Someone also suggested that because the contract now uses a nomination period for potential winners, to just keep state of who the current best nominated guess is instead of keeping state of all nominated guesses.

adamdossa commented 6 years ago

For an ordered linked list implementation, you can take a look at:
https://github.com/melonproject/smart-contracts/blob/develop/src/system/OperatorStaking.sol

If you google it you'll probably find other simpler implementations.

Having users need to nominate their prior guesses, and only keeping the winning nominated guess would be another workable approach as you say.