k26dr / ethereum-games

The official code repo for the book Building Games with Ethereum Smart Contracts
64 stars 35 forks source link

Minor security flaw in SimplePonzi contract #1

Open k26dr opened 6 years ago

k26dr commented 6 years ago

Can you find it? The first user who can point to a transaction that exploits the flaw will receive a 0.1 ether reward. Attack away :)

yunzhishang commented 6 years ago

I am not sure if I guess it is correct. We should set new investor after the success of send. :)

k26dr commented 6 years ago

Nope sorry. That's not it. Keep looking 😉

WingT commented 6 years ago

there is a potential flaw of integer overflow, but that require a large amount of wei

gramgrok commented 6 years ago

How about this: https://etherscan.io/tx/0x238866bcbf1abc18f4220a18c20586aa21226bdcd8c34397f6dba013a86749bf

The investor contract at 0x55aa079e2fb0c8b68a0a08efbff3f1aa5472f1a2 (source code is provided) gets nothing on the next step, because of: 1) gas limit for "send" at SimplePonzi, 2) gas-consuming fallback function of "smart" investor.

Some ether will be stuck at SimplePonzi address. Anyway, the SimplePonzi is not blocked here as it would be with "transfer" instead of "send".

k26dr commented 6 years ago

@deepcode You're right, this contract would not be able to receive the ether and it would be stuck in the contract, but that's not a flaw in the game as much as a feature in how Ethereum is designed. Contracts with flaws are free to screw themselves over, but you wouldn't be able to affect the game play this way. You would simply lose your own ether.

gramgrok commented 6 years ago

Then maybe this: https://rinkeby.etherscan.io/tx/0x5fa700b23a81ba8a21522f68e23244f71bdb42cdd28f32c680391f6d17264f4a

This demo attack is performed on Rinkeby testnet with an exact copy of the SimplePonzi contract and with similar initial conditions (0.005 ETH and 0.007 ETH investments before the attack).

Spent by the attacker: 0.008 ETH (on previous transaction) + gas fee. Resulting currentInvestment value: 750 ETH.

Rinkeby SimplePonzi contract copy is at https://rinkeby.etherscan.io/address/0x022159d0c168ce87c35a7643bc41e560febfde02 .

k26dr commented 6 years ago

My man! Congrats, you got it. You can render the contract unusable by sending a 2nd transaction with a large value. The ether goes back to you so there is no large loss.

Paste your ETH address here @deepcode and I'll send you your 0.1 ETH reward. I'll admit that reward looked a lot juicier when I wrote this chapter in November :sweat_smile:

gramgrok commented 6 years ago

Wow! I was almost ready to start reading the opcodes of SimplePonzi to get a different perspective :relaxed:

Let's reward the address of "successful attacker"... but not on Rinkeby :wink:

0x51FA329cab258588dB7236b67363Ab6cfEA54eB4

@k26dr Thanks for the prize and more thanks for all the fun with the contract!

chrisdannen commented 6 years ago

This is great. Nice work keeping them guessing.

On Wed, Aug 29, 2018 at 9:01 PM k26dr notifications@github.com wrote:

My man! Congrats, you got it. You can render the contract unusable by sending a 2nd transaction with a large value. The ether goes back to you so there is no large loss.

Paste your ETH address here @deepcode https://github.com/deepcode and I'll send you your 0.1 ETH reward. I'll admit that reward looked a lot juicier when I wrote this chapter in November 😅

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/k26dr/ethereum-games/issues/1#issuecomment-417155704, or mute the thread https://github.com/notifications/unsubscribe-auth/AAhANRbZLx-Tb3PeNiuj6BnBJtY18AsLks5uVzmCgaJpZM4Qv765 .

--

Chris Dannen | @chrisdannen http://twitter.com/chrisdannen Managing Partner Iterative Capital Management http://iterative.capital Mobile +1.917.617.0951 Fax +1.917.677.5002 Keybase 8223371585CC5FDC

gramgrok commented 6 years ago

Got the reward, twice the promised! Thanks again @k26dr and @chrisdannen !

ashaller2017 commented 3 years ago

really happy I followed up while reading this book lol good job!

paraskumarop commented 1 year ago

Then maybe this: https://rinkeby.etherscan.io/tx/0x5fa700b23a81ba8a21522f68e23244f71bdb42cdd28f32c680391f6d17264f4a

This demo attack is performed on Rinkeby testnet with an exact copy of the SimplePonzi contract and with similar initial conditions (0.005 ETH and 0.007 ETH investments before the attack).

Spent by the attacker: 0.008 ETH (on previous transaction) + gas fee. Resulting currentInvestment value: 750 ETH.

Rinkeby SimplePonzi contract copy is at https://rinkeby.etherscan.io/address/0x022159d0c168ce87c35a7643bc41e560febfde02 .

can you please elaborate, how did attacker did it , the link is broken..., how did the currentInvestment has 750 eth value ?