diff --git a/ProxyContract/1_Why/step1.md b/ProxyContract/1._Why_use_it/step1.md similarity index 96% rename from ProxyContract/1_Why/step1.md rename to ProxyContract/1._Why_use_it/step1.md index 92ff9f1cc..63b981c79 100644 --- a/ProxyContract/1_Why/step1.md +++ b/ProxyContract/1._Why_use_it/step1.md @@ -1,6 +1,4 @@ -# Proxy Contract AKS the Dispatcher - -## Why? +## Proxy Contract AKA "the Dispatcher" This is a great pattern which is used mainly in **library development**. diff --git a/ProxyContract/2._How_it_works/step2.md b/ProxyContract/2._How_it_works/step2.md new file mode 100644 index 000000000..21326d5d2 --- /dev/null +++ b/ProxyContract/2._How_it_works/step2.md @@ -0,0 +1,11 @@ +**EIP-7 DelegateCall** opcode allows a separate execution in another contract while maintaining the original execution context. + +With this opcode, all **message calls** from the user will go through a **Proxy contract**. + +The **Proxy contract** then redirects the calls to the **Logic contract**. + +And when the logic contract needs fixing or upgrading, you **just** deploy that - **HOWEVER** - the implementation (the original deployed contract) of Proxy will remain the same. + +You only need to update the address of Logic contract stored in Proxy contract. + +The Proxy Contract uses **Delegate calls** and **Solidity assembly** because without it, it's impossible to return any value from **delegatecall**. \ No newline at end of file diff --git a/ProxyContract/2_How/step2.md b/ProxyContract/2_How/step2.md deleted file mode 100644 index 701a6252e..000000000 --- a/ProxyContract/2_How/step2.md +++ /dev/null @@ -1,13 +0,0 @@ -# How it works? - -**EIP-7 DelegateCall** opcode allows a separate execution in another contract while maintaining the original execution context. - -All **message calls** from the user go through a **Proxy contract**. - -The **Proxy contract** then will redirect them to the **Logic contract**. - -And when you need to **upgrade** the logic, you'll **just** deploy that - **HOWEVER** - the implementation of Proxy will rename the same. - -You'll only need to update the address of Logic contract in Proxy. - -The Proxy Contract uses **Delegate calls** and **Solidity assembly** because without it, it's impossible to return any value from **delegatecall**. \ No newline at end of file diff --git a/ProxyContract/3._DelegateCall/step3.md b/ProxyContract/3._DelegateCall/step3.md new file mode 100644 index 000000000..ad2843804 --- /dev/null +++ b/ProxyContract/3._DelegateCall/step3.md @@ -0,0 +1,7 @@ +**delegatecall** a special variant of a **message call**. It is identical to a message call apart from the fact that the code at the target address is executed in the context of the calling contract so **msg.sender** and **msg.value** do not change their values. + +This means that a contract can dynamically load code from a different address at runtime. + +The storage, the current address and balance still refer to the calling contract, only the code is taken from the called address. + +So when a **Proxy** delegates calls to the Logic contract, every storage modification will impact the storage of the **Logic contract**. \ No newline at end of file diff --git a/ProxyContract/3_Delegatecall/step3.md b/ProxyContract/3_Delegatecall/step3.md deleted file mode 100644 index ec6226c60..000000000 --- a/ProxyContract/3_Delegatecall/step3.md +++ /dev/null @@ -1,9 +0,0 @@ -# Delegate call - -It's a special variant of a **message call**, which is identical to a message call apart from the fact that the code at the target address is executed in the context of the calling contract so **msg.sender** and **msg.value** do not change their values. - -This means that a contract can dynamically load code from a different address at runtime. - -The storage, the current address and balance still refer to the calling contract, only the code is taken from the called address. - -So when a **Proxy** delegates calls to the Logic contract, every storage modification will impact the storage of Logic contract. \ No newline at end of file diff --git a/ProxyContract/4._Generic_proxy_example/step4.md b/ProxyContract/4._Generic_proxy_example/step4.md new file mode 100644 index 000000000..e89d66db7 --- /dev/null +++ b/ProxyContract/4._Generic_proxy_example/step4.md @@ -0,0 +1,13 @@ +In the associated solidity file, **step4.sol**, there are 2 contracts - **ProxyContract** and **LogicContract**. + +To use this system, we first deploy LogicContract. + +And then when we go to deploy ProxyContract, we pass the LogicContract's address as an argument in ProxyContract's constructor. + +The ProxyContract is deployed only once. + +The code of LogicContract will be called at the line 20. It will be forwarded with **delegatecall** while keeping the context of LogicContract. + +In case we need to change the logic, we would deploy a new LogicContract and set the address of it with setLogicContractAddress setter function. + +**Note: The LogicContract we have here does not use the storage. Once you need to use the storage, the implementation becomes a bit more complicated because those contracts share the context.** \ No newline at end of file diff --git a/ProxyContract/4_Generic_proxy_example/step4.sol b/ProxyContract/4._Generic_proxy_example/step4.sol similarity index 100% rename from ProxyContract/4_Generic_proxy_example/step4.sol rename to ProxyContract/4._Generic_proxy_example/step4.sol diff --git a/ProxyContract/4_Generic_proxy_example/step4.md b/ProxyContract/4_Generic_proxy_example/step4.md deleted file mode 100644 index b6780c228..000000000 --- a/ProxyContract/4_Generic_proxy_example/step4.md +++ /dev/null @@ -1,15 +0,0 @@ -# A Basic Generic Proxy Example - -In the associated solidity file, **step4.sol**, there are 2 contracts - **ProxyContract** and **LogicContract**. - -To use this system, we first deploy the LogicContract. - -And then when we go to deploy the ProxyContract, we pass the LogicContract's address as an arguement of the ProxyContract's constructor. - -The ProxyContract is deployed only once. - -The code of LogicContract will be called at the line 20. It will be forwarded with delegate call while keeping the context of LogicContract. - -In case we need to change the logic we would deploy a new LogicContract and set the address of it with setLogicContractAddress setter function. - -*Note: The LogicContract we have here does not use the storage. Once you need to use the storage the implementation becomes a bit more complicated because those contracts share the context.* \ No newline at end of file diff --git a/ProxyContract/5._Test/step5.md b/ProxyContract/5._Test/step5.md new file mode 100644 index 000000000..4a43100fb --- /dev/null +++ b/ProxyContract/5._Test/step5.md @@ -0,0 +1,11 @@ +# Let's test what we've learned + + - Add to the contract **LogicContract** a public function named **getNumber** which returns 10 + + - Add to the proxy contract **ProxyContract**: + - an internal state variable that holds the logic contract's address. + - a constructor that takes the logic contract's address as a parameter and stores it in the state variable. + + ProxyContract should take an address of LogicContract as a first parameter. + + Good Luck! \ No newline at end of file diff --git a/ProxyContract/5_Test/step5.sol b/ProxyContract/5._Test/step5.sol similarity index 100% rename from ProxyContract/5_Test/step5.sol rename to ProxyContract/5._Test/step5.sol diff --git a/ProxyContract/5_Test/step5_answer.sol b/ProxyContract/5._Test/step5_answer.sol similarity index 100% rename from ProxyContract/5_Test/step5_answer.sol rename to ProxyContract/5._Test/step5_answer.sol diff --git a/ProxyContract/5_Test/step5_test.sol b/ProxyContract/5._Test/step5_test.sol similarity index 100% rename from ProxyContract/5_Test/step5_test.sol rename to ProxyContract/5._Test/step5_test.sol diff --git a/ProxyContract/5_Test/step5.md b/ProxyContract/5_Test/step5.md deleted file mode 100644 index c61a9e78f..000000000 --- a/ProxyContract/5_Test/step5.md +++ /dev/null @@ -1,6 +0,0 @@ -# Let's test what we've learned - - - Write a contract named "LogicContract" which implements a public function named "getNumber" which returns 10 - - Write a proxy contract named "ProxyContract". This ProxyContract should take an address of LogicContract as a first parameter. - - Good Luck! \ No newline at end of file diff --git a/ProxyContract/6_Storage_Problem/step6.md b/ProxyContract/6._A_Storage_Problem/step6.md similarity index 96% rename from ProxyContract/6_Storage_Problem/step6.md rename to ProxyContract/6._A_Storage_Problem/step6.md index 0d94e4c73..eedbec28b 100644 --- a/ProxyContract/6_Storage_Problem/step6.md +++ b/ProxyContract/6._A_Storage_Problem/step6.md @@ -1,4 +1,4 @@ -# What if we have state variables? +## What if we have state variables? Things are more complicated once we need to deal with state variables. State variable are saved to **storage**. diff --git a/ProxyContract/6_Storage_Problem/step6.sol b/ProxyContract/6._A_Storage_Problem/step6.sol similarity index 100% rename from ProxyContract/6_Storage_Problem/step6.sol rename to ProxyContract/6._A_Storage_Problem/step6.sol diff --git a/ProxyContract/7_links/step7.md b/ProxyContract/7._Links/step7.md similarity index 94% rename from ProxyContract/7_links/step7.md rename to ProxyContract/7._Links/step7.md index 239d2292c..69247f796 100644 --- a/ProxyContract/7_links/step7.md +++ b/ProxyContract/7._Links/step7.md @@ -1,4 +1,4 @@ -# Check out some links for more info +## For more info- check out these links - ERC DelegateProxy https://github.com/ethereum/EIPs/pull/897