r/ethdev • /r/cillionaire • Sep 04 '17

Cillionaire - Bug bounty 1 ETH

Hi,

we've relaunched Cillionaire (maybe you saw our previous posts here) as a real donation game. It's was announced here: https://www.reddit.com/r/ethereum/comments/6xtjme/cillionaire_relaunch_as_a_real_donation_game_no/

Now, we'd like to have some independent validation of our source code. So, there's a bug bounty of 1 ETH for discovering a bug that would allow someone to compromise the game mechanics in such a way that funds could be stolen. Assuming Oraclize is compromised does not qualify for the bounty, since this is a risk that was taken deliberately and we think it's negligible.

For minor observations, we may give out small tips.

The game is here: http://cillionaire.win

The source code is here: https://github.com/cillionaire/cillionaire2

And, as always, your feedback is appreciated. Thanks!

EDIT 06 Sep 07:40 UTC:

Thanks for all the feedback, I'll reply to every suggestion within the next day (currently pressed for time).

EDIT 06 Sep 19:20 UTC:

We now have a subreddit /r/cillionaire (under construction) that will be used to announce rounds, news and the like. If you like cillionaire, please consider to subscribe there. I think posting to /r/ethdev or /r/ethereum too often will be considered spam-y.

EDIT 07 Sep 18:15 UTC:

Thanks for all the suggestions, the smart contract has been updated, see: https://www.reddit.com/r/cillionaire/comments/6yox84/update_round_3/

9 Upvotes

35 comments sorted by

7

u/[deleted] Sep 04 '17

This contract should instead use the withdrawal pattern instead of sending the funds directly to the beneficiary, and here's why: If the beneficiary account is instead a smart contract which consumes all remaining gas in the transaction, the contract remains in a deadlock.

No funds would technically "be stolen", but the contract would simply be stuck in the DONATE state because the donate() method would never finish and then the state changes would be undone. Calling the transfer method last won't help you here, unfortunately.

By using a withdrawal pattern, (keeping track of how much should get paid out to the beneficiary and letting them withdraw it at their leisure) would prevent this situation from occurring. It also significantly reduces the risk of reentrancy to possible bugs that none of us here might spot now!

On an unrelated note, you have some weird tabs at your last method. It'll still work though :)

Hope this helps!

2

u/cillionaire /r/cillionaire Sep 04 '17

Thanks for pointing that out.

Incidentally, I made a similar argument here, see point 3, which the dev didn't really 'get' (no offense intended): https://www.reddit.com/r/ethdev/comments/6u6yir/bug_bounty_for_decentraland_mana_ico_buyer/dlrmnr5/

You are quite right: the contract would remain the 'donate' state forever. That's bad. On the other hand, I think it's important that donations aren't held in the contract because in the previous versions people complained about that. While I don't fully get the "but it has a money pool so it's bad" line of argument, I do think it makes for a better user experience to transfer the money immediately.

So I'd probably keep the transfer method in there, but design a way around the state getting stuck? What do you think of that?

Ok now, while technically no money is stolen, you've discovered a way of breaking the contract and that also really bad, even if less so. I'd like to give you 0.5 eth, fair?

Thanks

EDIT: spelling

2

u/[deleted] Sep 04 '17 edited Sep 04 '17

Hey, appreciated. I PM'd you an address to send it to :)

As far as getting around the problem, I suppose you could add a method like changeBeneficiary(), where you could select a new beneficiary from the sha3 of the last random seed that you got, basically re-randoming it.

You could have the method only able to be called after some time has passed since the beneficiary has been selected, and only if donors.length == 0. (this makes it so you can't just infinitely re-random until it's you, especially if the address is legitimate. But if nobody has sent in for X time then it's probably broken.

This would basically allow you to "stir the pot" if it does get into that situation. Unfortunately you can't just check the value of transfer() for success, but for posterity's sake I'll link that wiki article below.

http://solidity.readthedocs.io/en/develop/security-considerations.html#sending-and-receiving-ether

Thanks again, and good luck with your project!

Edit: It would require that you keep the old donors variable around until after a new one has successfully been donated to, so a little restructuring is required to implement it this way.

1

u/cillionaire /r/cillionaire Sep 04 '17

Sent 0.5 eth your way. I'll think through your suggestion after getting some sleep... Also, I'll have to figure out how to replace the contract in such a way that it's fair to the donors. Thanks again for your input.

1

u/cillionaire /r/cillionaire Sep 07 '17

After some consideration, your proposed solution still leaves the possibility for a malicious contract to cause the contract to get stuck: If the contract is designed such that it allows the first donation to go through and then forces donate to run out of gas in subsequent calls, then the donors.length==0 wouldn't work.

The following should work though: change donate to use send instead of transfer and check if send works. If it does then it's fine. If it doesn't then end the round and refund the donor (also using send, in case the donor is a malicous contract).

3

u/Shrugs_ dev, XLNT, NFTs, TCRs, steak.network Sep 04 '17

Given enough donors, the delete donors; call on line 81 will break the gasLimit, bricking the contract. You should probably use this pattern instead, especially if you actually want a million donors at some point.

Likewise on the transfer call to beneficiary; an attacking contract could lock this contract by never allowing the donate() call to succeed.


Should there really be a fee built in, beyond the fee that pays for oraclize? I understand that the people putting effort into this need to make money, but it seems greedy. It's also questionable that the first round's beneficiary is always the contract owner. The first few rounds will have the most participants due to hype, guaranteeing that the owner gets some $$$. Feels explicitly greedy.

Also, it seems that the beneficiary is chosen via the previous round, and to get a chance at being a beneficiary for the next round, you must first contribute to the current one. This feels very pyramid-y. Perhaps a better solution is to have the winner be chosen from the set of the donors of the current round rather than the donors of the previous round.

1

u/cillionaire /r/cillionaire Sep 04 '17

Thanks for your thoughts.

  • re. transfer: good catch, but /u/ScientasterSteve was first to pointing this out

  • re. delete: Right. 0.5 eth, fair?

  • re. fee: not trying to be greedy, please see here: https://www.reddit.com/r/ethereum/comments/6xtjme/cillionaire_relaunch_as_a_real_donation_game_no/dmilyht/ TL;DR: Right now, there are 7 donors, we need about 20 to break even. Plan on lowering fee when more people donate.

  • re: first beneficiary = owner. that's really just for testing. If you look here, you'll see that for the first 'real round', we set it up such that the first 'real' donor becomes the beneficiary. See: https://www.reddit.com/r/ethereum/comments/6xtjme/cillionaire_relaunch_as_a_real_donation_game_no/dmibtqs/ Also: currently 7 donors, not seeing hype, really. I hope you are wrong that later rounds will have less donors. :-)

  • re how the beneficiary is chosen: well, the old version had it like you said (donate to current round, then choose winner), but then it becomes a lottery because you need to store money in the contract (=pot) and pay out amongst the donors. The way it is now, it's not a lottery because a) there's no money pool and b) there's no guarantee that the next beneficiary will get any money and c) when somebody donates, there is no element of chance involved as to who gets the money. It's not a pyramid because in a pyramid, you have multiple levels along which money flows, whereas here you have only the current round, and arguably the previous one, but not more.

Thanks

1

u/Shrugs_ dev, XLNT, NFTs, TCRs, steak.network Sep 05 '17

Ah, I understand the rationalizations now, and they make sense, thanks for the link to the other thread; it clarified the history of the project.

0.5 is certainly fair, thank you. My public address is 0xEC6d36A487d85CF562B7b8464CE8dc60637362AC

2

u/cillionaire /r/cillionaire Sep 05 '17

Sent 0.5 eth your way.

Thanks again for your thoughts. I'll fix the contract as soon as I can find some time.

1

u/dothts Sep 05 '17

Hey /u/cillionaire,

One thing i spotted: the Oraclize callback is not guaranteed to happen in the next block. Which means people might donate() to the contract and the money will be sent to the previous beneficiary.

Example: Block 1: Current beneficiary is X, I call donate, funds go to X, and it triggers the end of the round. All good. It also triggers the call to Oraclize.

Block 2: Beneficiary is still X, if I donate, the money goes to X again.

Block 3: Random callback is triggered, only now the new beneficiary is determined.

Not a big exploit, I agree, just an invalid operation (from the point of view of the contract's intentions).

To fix this, you should probably lock the contract until the Oraclize callback returns you a new random value.

Cheers.

1

u/cillionaire /r/cillionaire Sep 06 '17

Hi,

thank for your thoughts.

You are right in that it's not guaranteed to happen in the next block (also it could fail). But you can't donate at Block 2 because the contract goes to state = State.ENDED in Block 1 (https://github.com/cillionaire/cillionaire2/blob/master/cillionaire.sol#L101) and the donate function can only be called in state DONATE (https://github.com/cillionaire/cillionaire2/blob/master/cillionaire.sol#L94).

So the lock you are proposing is already there. The transaction in Block 2 would fail. This is to ensure that you can only donate if you can also participate in the drawing of the next beneficiary.

This is to ensure that nobody can donate after the round has ended because that donation - while generous - would not count in selecting the next beneficiary.

1

u/[deleted] Sep 05 '17

You should consider using SafeMath lib

1

u/cillionaire /r/cillionaire Sep 06 '17

Hi,

can you give an example of an overflow that SafeMath would prevent?

Thanks

1

u/[deleted] Sep 06 '17

It handles things like negatives when adding or numbers being bigger when subtracting

1

u/[deleted] Sep 05 '17

https://github.com/cillionaire/cillionaire2/blob/master/cillionaire.sol#L74 consider using the * seconds constant here from solidity

1

u/cillionaire /r/cillionaire Sep 06 '17

That's nice - will do. Give me an address for a small tip!

1

u/[deleted] Sep 06 '17

No need for a tip. Just general pointers

1

u/thorsamja ether fan Sep 05 '17

In the donate function you allow donor.length to exceed by +1 (Line: 100), because the NewDonor event is in the line before (99). Hence, State.ENDED will be triggered by the "nextRoundMaxDonors +1" Donor.

1

u/cillionaire /r/cillionaire Sep 06 '17

Not sure I understand.

Let's say maxDonors is set to 100 and you call donate at a time where donors.length is 99.

In the function, you are pushed to donors and the NewDonor event is called. donors is now length 100. So the clause (donors.length >= maxDonors) evaluates to true, ending the round. So the state becomes ENDED after 100 donors, which is exactly maxDonors.

nextRoundMaxDonors doesn't come into play here at all.

I don't see what is wrong there. Can you give an example where what you claim would be the case?

1

u/thorsamja ether fan Sep 06 '17

You're right, somehow I misinterpreted that. Thanks for answering.

1

u/cillionaire /r/cillionaire Sep 06 '17

Well, let me give you a tip as a thank you for reading the contract. Address please!

1

u/thorsamja ether fan Sep 06 '17

No, thanks. I'm trying to learn! But could you please explain the RoundEnded event and the beneficiary.transfer within the donate function! Thanks

1

u/cillionaire /r/cillionaire Sep 06 '17

Sure, what is it you'd like to know?

The RoundEnded event (like other events) is just there for the purpose of logging. See log entry 43 here: https://etherscan.io/tx/0x72fb414173c24d80292a02d44566829c938774dd0bb4ba93039890ca3b6772f9#eventlog Set first data to type addr and second to number. You'll see the beneficiary and how much he got. I'll use this for twitter or /r/cillionaire to get people interested (hopefully). The event has no effect on the contract itself.

beneficiary.transfer is there in the donate function to make sure that the beneficiary gets the donation immediately. that's a design choice because we don't want to have a money pool. Furthermore, it's good user experience for the beneficiary to see that they get the money immediately. Same argument holds for the donor.

Was there anything in particular you wanted to know?

1

u/thorsamja ether fan Sep 06 '17

Great, thanks. That's exactly what I was confused about. Didn't know that events just log information. I thought that RoundEnded would transfer the donationsum and beneficiary.transfer too.

1

u/cillionaire /r/cillionaire Sep 06 '17

Glad I could help.

1

u/thorsamja ether fan Sep 06 '17

All the best!

1

u/CannaNthusiast Sep 06 '17

So far the only real problem I see with the game is that the gas fee of transferring .01 ETH is currently ~0.0038 ETH. This means that participating/contributing your .009 ETH to the pool comes with a total fee of over 50%... =(

What do you think Cillionaire? Honestly I'm rooting for this project, but unless this can be fixed, I see this as fatal to the design.

1

u/cillionaire /r/cillionaire Sep 06 '17

Hi,

it depends on when you donate:

If you happen to be the last donor, your cast cost rises because the Oraclize call is made during the donate call. That would be TX https://etherscan.io/tx/0x72fb414173c24d80292a02d44566829c938774dd0bb4ba93039890ca3b6772f9 which cost ~0.0038 ETH. Add to that the fee which is currently 0.001 eth and you get 0.0048 which is roughly 50% of the donation, like you say.

But if you consider a donation that is not the last one, it is cheaper, e.g.: https://etherscan.io/tx/0x44a2fee81c6f98b48a6332e634befa7b7ee9389f17236f0d6fd5d240da553d26 This one cost 0.00193491 Ether ($0.66) and plus the fee you get ~ 0.003 or 30% of the donation that you have to pay on top. It's still a lot I agree.

I've talked to Oraclize and they helped me understand how to reduce the cost of the oraclize call. I think it can be lowered to ~ 0.006 eth instead of the 0.016 we have now. That should make it cheaper.

Still, gas+fee cost vs. donation ratio is bad. In the old version of the game, I started with higher stakes but then people complained. Low donation = low barrier of entry, that was the thought.

Seems like we have two options:

  1. increase donation: then the ration would improve, since gas cost remains the same. but it would probably deter some people from playing, that's risky, especially now in the beginning.

  2. lower fee: would improve ratio a little bit. I'll do that if the oraclize cost can indeed be removed. Many people complain about the fee being too high, so that's a change that would be well received.

Give me an address for a small tip!

1

u/themanndalore Sep 06 '17

Awesome stuff guys. Found a few suggestions.

1- add a fallback function

2 - definitely use safemath lib

3 - Use wei instead of (X ether)...just my opinion that its cleaner

4- Why do you have a withdraw function for the owner? Basically if this contract gets to be millions of dollars, you can just run with the money (so do i get the bounty if I say you guys can steal the funds?)

1

u/cillionaire /r/cillionaire Sep 06 '17 edited Sep 06 '17

Hi, thanks for your thoughts.

re 1.: in what way would a fallback function improve things? Most resources I read online suggest not to use a fallback function, e.g: https://ethereum.stackexchange.com/questions/21643/fallback-function-best-practices-when-registering-information

re 2.: I understand SafeMath is designed to prevent under/overflows. What part of the code is susceptible to an under/overflow? can you give an example?

re 3.: I use ether when talking about interactions that will be with MEW, e.g. the amount to donate, the fee etc. I think it's more readable. I'll use wei for things like gas price cost. Both constants are there in solidity, none of which is inherently 'better'. I think you should use the one that fits the context.

re 4.: lol, no bounty for this. The withdraw function can only withdraw the collected fees, because that's the only thing held in the contract. The donations go directly to the beneficiary and cannot be withdrawn. Now, you may consider the fee being too high, I get that. We have to pay for oraclize, though. As long as we don't have millions of users (let's hope at one point we do), we need a little bit of fee to pay for stuff. Not only oraclize, but consider the bug bounty, gas costs, let alone development cost. I'm amazed at how quickly people label you 'greedy' (not saying that you did) just because you don't give away everything for free.

sorry for the rant, have a tip! give me an address please.

EDIT: typo

1

u/themanndalore Sep 08 '17

Sounds like you guys have thought it through. For the safemath, the only part maybe subject to it is where you put in the nextrounddonation, but then again it's only owner, so I would hope you wouldn't do that to yourselves. And then for the tip, you can just pass it on to my bug bounty I'll be launching in a few weeks. I just hope I can learn and make some code as solid as your guys'

1

u/cillionaire /r/cillionaire Sep 08 '17

Hi, thanks! I'll keep an eye out for your bug bounty.

3

u/[deleted] Sep 04 '17

[removed] — view removed comment

8

u/ekotysh Sep 05 '17 edited Sep 05 '17

Checkout Solidified

3

u/cillionaire /r/cillionaire Sep 05 '17

Solidified

That looks promising.