Skip to content

Instantly share code, notes, and snippets.

@yuriy77k
Forked from RideSolo/ETH_lottereum_audit_report.md
Created September 11, 2018 09:42
Show Gist options
  • Save yuriy77k/8dc77c7a2ed7433f234b5cf1b95d59b8 to your computer and use it in GitHub Desktop.
Save yuriy77k/8dc77c7a2ed7433f234b5cf1b95d59b8 to your computer and use it in GitHub Desktop.

Lottereum Project Audit Report.

1. Summary

This document is a security audit report performed by RideSolo, where Lottereum Project has been reviewed.

2. In scope

  • smart contract github commit hash 8485c34a0364f8aad53ff6e719604d7d7aa32e12.

3. Findings

7 issues were reported including:

  • 2 high severity issues.

  • 2 medium severity issues.

  • 2 low severity issues.

  • 2 minor remark.

3.1. Result Prediction and Manipulation

Severity: High

Description

Two possible scenarios can guarantee or increase the chance of an attacker to win the lottery:

  • Malicious miner manipulation of the transactions orderings can allow the attacker to increase his chances of winning.
  • using a simple attack contract an attacker can check the value of amountOfTicketsForEthereumLotteryPurchased if using the ethereum lottery or amountOfTicketsForTokenLotteryPurchased when using the token lottery. Setting simple condition to guarantee that he wins by checking if the value of the state variables satisfy the condition present in playLotteryByToken or playLotteryByEthereum functions.

Code snippet

https://github.com/RideSolo/Lottereum/blob/master/smart%20contract#L103#L104

https://github.com/RideSolo/Lottereum/blob/master/smart%20contract#L220#L230

https://github.com/RideSolo/Lottereum/blob/master/smart%20contract#L232#L241

https://github.com/RideSolo/Lottereum/blob/master/smart%20contract#L263#L291

https://github.com/RideSolo/Lottereum/blob/master/smart%20contract#L293#L348

3.2. Buy Ticket For Ethereum

Severity: High

Description

buyTicketForEthereumLottery does not implement any logic to check the msg.value, consequences:

  • A user can play without even sending ether to the contract.
  • A user can send more ether than the ticket price when calling buyTicketForEthereumLottery the extra ether will be lost in the contract.

Code snippet

https://github.com/RideSolo/Lottereum/blob/master/smart%20contract#L232#L241

3.3. Internal Call to Restricted Function

Severity: medium

Description

Internal call to playLotteryByEthereum and playLotteryByToken is made inside buyTicketForEthereumLottery and buyTicketForTokenLottery, however this two functions are restricted by the onlyAdministrator modifier. when amountOfTicketsForTokenLotteryPurchased or amountOfTicketsForEthereumLotteryPurchased will reach 1000 the transactions wil fail.

Code snippet

https://github.com/RideSolo/Lottereum/blob/8485c34a0364f8aad53ff6e719604d7d7aa32e12/smart%20contract#L227

https://github.com/RideSolo/Lottereum/blob/8485c34a0364f8aad53ff6e719604d7d7aa32e12/smart%20contract#L239

3.4. Lottery Winners distrubution

Severity: medium

Description

The following description assumes that the devs didn't take into account the high severity issue mentioned in 3.1.

80% of totalFundInTokenLottery is distributed to the lottery winners, however after starting distrubution only 96% of the original 80% is distributed (check the computation bellow).

(1000÷100)×(2÷100+4÷1000+2÷1000)+(1000÷20)×(4÷1000+2÷1000)+(1000÷10)×(2÷1000)+2÷10 = 0.96

Same issue with the 70% of totalFundInEthereumLottery, 96% of the original 70% will be distributed and the other 4% will be lost in the contract.

Code snippet

https://github.com/RideSolo/Lottereum/blob/master/smart%20contract#L264

https://github.com/RideSolo/Lottereum/blob/master/smart%20contract#L269#L280

3.5. Play & Withdraw Pattern

Severity: low

Description

This description assumes that the high severity security issues are solved. A play and withdrawal pattern should be used instead of playLotteryByEthereum and playLotteryByToken that will consume a highly excessive amount of gas.

Recommendation

The dev should set an opening and closing time where in between players can buy tickets and after closing time players will withdraw their reward by themselves.

3.6. Identical Functions

Severity: low

Description

participateInEthereumLottery and participateInTokenLotterycontain the exact same code. one function should handle ether to buy tickets and the other one should handle tokens.

Code snippet

https://github.com/RideSolo/Lottereum/blob/master/smart%20contract#L197

https://github.com/RideSolo/Lottereum/blob/master/smart%20contract#L209

3.7. Useless State Variables

Severity: minor

Description

ticketsForTokenLottery and ticketsForEthereumLottery map players addresses to their ticket number and own address, adding useless extra data.

Code snippet

https://github.com/RideSolo/Lottereum/blob/8485c34a0364f8aad53ff6e719604d7d7aa32e12/smart%20contract#L107

https://github.com/RideSolo/Lottereum/blob/8485c34a0364f8aad53ff6e719604d7d7aa32e12/smart%20contract#L108

3.8. Opening and Closing Time

Severity: minor

Description

An opening time is set and checked, but no closing time is set which means that users can play the lottery even after that it closes.

4. Conclusion

This contract is not safe and cannot be deployed, it contains high severity security issues and high severity operability issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment