English README Jump to Japanese Version
- The Ethernaut is a Web3/Solidity-based coding wargame, played in the Ethereum Virtual Machine.
- Each level is a smart contract that needs to be 'hacked'.
Here are the writeups of my solutions levels I cleared. ** I will not recommend you to look at solutions I wrote. Solve it yourself for your learning 😛 **
- To use ethernaut, you need to use the console from the developper tool of your browser in the first place.
- If your confortable with Foundry and Methods call using
cast
andsend
, you can also solve problem from Foundry framework. - If you are not confortable yet with ABI, then it is a great way to learn about it and how to call any contract by external calls.
- In higher difficulty levels, you will need to wrote smart contracts and interfaces to hack some smart contract externally for clearing levels.
Introductory level.
Link to the repository: Here.
The goal is to become the Owner of the smart contract to be able to steal all the funds in it.
Link to the repository: Here.
The goal is to become the Owner of the smart contract.
- The best hint is in the presentation image of the problem.
Link to the repository: Here.
The goal is to guess 10 times the right side on which the coin is gonna flip when calling the flip()
function.
Link to the repository: Here.
The goal is to become the Owner of the smart contract.
- In the
Telephone
smart contract, there is a logic that if transaction made that is not fromtx.origin
we can become the owner. - It is a problem to show what to use when it comes to the transaction origine.
tx.origin
ormsg.sender
. - The
tx.origin
global variable refers to the original external account that started the transaction whilemsg.sender
is a direct transaction from an user.
Link to the repository: Here.
The goal is to get all ERC20 Tokens of the contract transfered to our balance
- The trick in that contract is that it is done under
Solidity 0.6.0
. under0.8.0
we need to use a library calledSafeMath
for dealing with numbers. - Without
SafeMath
all solidity contracts with a compiler version under0.8.0
have anunderflow
andoverflow
problem. - Example: We have an integer of type
uint
with value of20
. Let say we do20 + 1
, we don't get21
. Instead we get1
by going over21
. Which is theUintMax
in this case. - Meaning we can have all tokens of the total supply.
- SafeMath was used to prevent this problem. Since
0.8.0
it is integrated into solidity by default. Link to the repository: Here.
The goal is to unlock the contract by finding the Bytes32
password.
-
The solution here is to find the value of the
private
variableLink to the repository: Here.
The goal is to take control of the contract.
- The solution here is to send an amount of ether superior to the prize to the contract. Here is an easy explanation:
- To do so we can only use the
call
function. transfer
andsend
can not be used as when calling thereceive
function of the contract, it will revert the transaction due to the gas cap of 2300.call
function does not have this gas cap and can be used to send ether to the contract. Link to the repository: Here.
The goal is to empty the contract of its funds.
- What is going to happen, we need to call
donate
to set avalue
to the balance of contract used for the attack. - Then call
withdraw
to empty the contract. Since the state changes happen later on, thereceive
function will be called and the attack will be repeated until the attacked contract balance is less than0.001eth
. Link to the repository: Here.
- Ethernaut は、Web3/Solidity ベースのコーディングウォーゲームで、Ethereum Virtual Machine (EVM) でプレイされます。
- 各レベルはハッキングする必要があるスマートコントラクトです。
これはクリアしたレベルの解決策です。 **解決策を見ることをお勧めしません。学習のために自分で解決してください 😛 **
- Ethernaut を使用するには、まずブラウザの開発者ツールからコンソールを使用する必要があります。
- Foundry と cast および send を使用した方法の呼び出しに慣れている場合、Foundry フレームワークから問題を解決することもできます。
- まだ ABI に慣れていない場合、それを使用して任意のコントラクトを外部呼び出しで呼び出す方法について学び、理解するのに最適な方法です。
- より高難度のレベルでは、スマートコントラクトとインターフェースを作成して、いくつかのスマートコントラクトを外部からハッキングするために解レベルをクリアする必要があります。
これは導入的なレベルである。
レポジトリーへのリンクは: こちら。
目標は、そのスマートコントラクトのオーナーになり、中にあるすべての資金を奪うことです。
レポジトリーへのリンクは: こちら。
- 目標は、スマートコントラクトの所有者になることです。
最も役立つヒントは、問題のプレゼンテーション画像にあります。
レポジトリーへのリンクは: こちら。
- 目標は、
flip()
関数を呼び出すときに、コインがどの側に反転するかを 10 回正しく予想することです。
レポジトリーへのリンクは: こちら。
目標は、スマートコントラクトの所有者になることです。
Telephone
スマートコントラクトでは、tx.origin
からのトランザクションでない場合、オーナーになる仕組みがあります。- トランザクションの発生元を示すときに、
tx.origin
またはmsg.sender
を使用するかどうかは問題です。 tx.origin
変数は、トランザクションを開始した元の外部アカウントを参照しますが、msg.sender
はユーザーから直接のトランザクションです。
レポジトリーへのリンクは: こちら。
目標は、コントラクトのすべての ERC20 トークンを手に入れることです。
- このコントラクトのミソは、
Solidity 0.6.0
の下で行われたことです。0.8.0
では、数値の処理にSafeMath
と呼ばれるライブラリを使用する必要があります。 SafeMath
がない場合、コンパイラバージョンが0.8.0
未満のすべての Solidity コントラクトにはアンダーフロー
とオーバーフロー
の問題があります。- 例:
uint
型の整数で値が20
の場合、20 + 1
を行ったとしましょう。結果は21
ではなく、21
を超えて1
を得ます。これはこの場合のUintMax
です。 - つまり、合計供給量のすべてのトークンを持っている可能性があります。
- この問題を防ぐために
SafeMath
が使用されました。0.8.0
以降、Solidity にはデフォルトで組み込まれています。
レポジトリーへのリンクは: こちら。
コントラクトを解除する目的は、Bytes32
パスワードを見つけることです。
-
ここでの解決策は、
private
変数password
の値を見つけることです。レポジトリーへのリンクは: こちら.
コントラクトの管理権を握ることが目標です。
-
ここでの解決策は、賞金よりも多いエーテルをコントラクトに送ることです。簡単な説明は以下の通りです:
-
これを行うには、
call
関数のみを使用できます。 -
transfer
やsend
は使用できません。コントラクトのreceive
関数を呼び出すと、2300 のガス上限のためにトランザクションがリバートされるからです。 -
call
関数にはこのガス上限がなく、エーテルをコントラクトに送るために使用できます。レポジトリーへのリンクは: こちら.
目標は、契約の資金を空にすることです。
-
- 何が起こるかというと、攻撃に使用される契約の残高に
value
を設定するためにdonate
を呼び出す必要があります。
- 何が起こるかというと、攻撃に使用される契約の残高に
-
その後、
withdraw
を呼び出して契約の中身を空にします。状態の変更が後で起こるため、receive
関数が呼び出され、攻撃された契約の残高が0.001eth
未満になるまで攻撃が繰り返されます。レポジトリーへのリンクは: こちら.