-
Notifications
You must be signed in to change notification settings - Fork 689
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #726 from OpenZeppelin/Stake-New-Level-31
Stake - New Level (Level 31)
- Loading branch information
Showing
25 changed files
with
269 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ client/src/gamedata/deploy.local.json | |
.env | ||
|
||
# Local Netlify folder | ||
.netlify | ||
.netlify |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,17 @@ | |
"https://github.com/fefeupz" | ||
], | ||
"donate": "0x00000000000d86e4837ba41dacde4b8713d5ccac" | ||
}, | ||
"GustavoDeps":{ | ||
"name": [ | ||
"Gustavo Deps" | ||
], | ||
"websites": [ | ||
"https://www.linkedin.com/in/gustavo-deps/" | ||
], | ||
"emails": [ | ||
"[email protected]" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Stake is safe for staking native ETH and ERC20 WETH, considering the same 1:1 value of the tokens. Can you drain the contract? | ||
|
||
To complete this level, the contract state must meet the following conditions: | ||
|
||
* The `Stake` contract's ETH balance has to be greater than 0. | ||
* `totalStaked` must be greater than the `Stake` contract's ETH balance. | ||
* You must be a staker. | ||
* You staked balance must be 0. | ||
|
||
Things that might be useful: | ||
* [ERC-20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md) specification. | ||
* [OpenZeppelin contracts](https://github.com/OpenZeppelin/openzeppelin-contracts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Congratulations, you have cracked the `Stake` machine! | ||
|
||
When performing low-level calls to external contracts, it is important to properly validate external call returns to determine whether the call reverted. | ||
|
||
For more info, check out [EEA EthTrust [S] Check External Calls Return](https://entethalliance.github.io/eta-registry/security-levels-spec.html#req-1-check-return) requirement, and always use [SafeERC20](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/utils/SafeERC20.sol) when interacting with external ERC-20 tokens. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Stake é cofre para fazer stake de ETH nativo e ERC20 WETH, considerando o mesmo valor 1:1 dos tokens. Você pode drenar o contrato? | ||
|
||
Para completar este nível, o estado do contrato deve atender às seguintes condições: | ||
|
||
* O saldo em ETH do contrato `Stake` deve ser maior que 0. | ||
* `totalStaked` deve ser maior que o saldo em ETH do contrato `Stake`. | ||
* Você deve ser um staker. | ||
* Seu saldo estacado deve ser 0. | ||
|
||
Coisas que podem ser úteis: | ||
* A especificação [ERC20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md) | ||
* Os contratos da [OpenZeppelin](https://github.com/OpenZeppelin/zeppelin-solidity/tree/master/contracts) |
5 changes: 5 additions & 0 deletions
5
client/src/gamedata/pt_br/descriptions/levels/stake_complete.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Parabéns, você conseguiu desvendar a máquina `Stake`! | ||
|
||
Ao realizar chamadas de baixo nível para contratos externos, é importante validar corretamente os retornos das chamadas externas para determinar se a chamada foi revertida. | ||
|
||
Para mais informações, confira o requisito [EEA EthTrust [S] Check External Calls Return](https://entethalliance.github.io/eta-registry/security-levels-spec.html#req-1-check-return), e sempre use [SafeERC20](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/utils/SafeERC20.sol) ao interagir com tokens externos ERC-20." |
25 changes: 15 additions & 10 deletions
25
client/src/gamedata/pt_br/descriptions/levels/telephone_complete.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
Embora este exemplo possa ser simples, confundir `tx.origin` com `msg.sender` pode levar a ataques do tipo phishing, como [este](https://blog.ethereum.org/2016/06/24/security-alert-smart-contract-wallets-created-in-frontier-are-vulnerable-to-phishing-attacks/). | ||
Embora este exemplo sejá bem simples, podemos esquecer de checar o retorno `success bool` quando realizamos chamadas externas, neste caso de `transfer` para saber se a mesma ocorreu da forma que deveria, como [este](https://github.com/crytic/slither/wiki/Detector-Documentation#unchecked-transfer) | ||
|
||
Um exemplo de um possível ataque é descrito abaixo. | ||
|
||
1) Use `tx.origin` para determinar de quem os tokens serão transferidos, por exemplo: | ||
1) Use `ERC(Stake.WETH()).approve(address(Stake), 1 ether)` para determinar de o contrato pode transferir os tokens que você "possui" | ||
|
||
2) Agora use a função `Stake.StakeWETH(uint256 amount)` com qualquer valor para amount que seja maior que o `Stake.balance` e veja seus `UserStake` points subirem sem haver transferido quaiquer fundos e extraia através de `Unstake(uint256 amount)` com amount igual a `Stake.balance` e veja o ETH indo para sua carteira, por exemplo: | ||
|
||
``` | ||
function transfer(address _to, uint _value) { | ||
tokens[tx.origin] -= _value; | ||
tokens[_to] += _value; | ||
function () payable { | ||
ERC20(Stake.WETH).approve(stakeAddress, 1000000000000000000); | ||
Stake.StakeWETH(1000000000000000000); | ||
Stake.Unstake(Stake.balance); | ||
} | ||
``` | ||
|
||
2) O hacker faz com que a vítima envie fundos para um contrato malicioso que chama a função de transferência do contrato de token, por exemplo: | ||
3) Nesse cenário, `UserStake[attackerContractAddress]` será maior que o valor transferido ao contrato, permitindo que a função `Unstake(uint256 amount)` seja chamada, adicione também uma transferência dos fundos para a sua wallet, assim os fundos irão para a sua wallet e o contrato será drenado, por exemplo: | ||
|
||
``` | ||
function () payable { | ||
token.transfer(attackerAddress, 10000); | ||
ERC20(Stake.WETH).approve(stakeAddress, 1000000000000000000); | ||
Stake.StakeWETH(1000000000000000000); | ||
Stake.Unstake(Stake.balance); | ||
(bool success, bytes memory return) = payable(msg.sender).call{value: address(this).balance}("") | ||
require (success) | ||
} | ||
``` | ||
|
||
3) Nesse cenário, `tx.origin` será o endereço da vítima (enquanto `msg.sender` será o endereço do contrato malicioso), resultando na transferência de fundos da vítima para o hacker. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.