From 8137adccb28656d977978e98b7f981649d14158b Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Wed, 10 Feb 2021 15:18:29 -0500 Subject: [PATCH 1/2] proxy: updated folder names & edited chapter headings --- ProxyContract/{1_Why => 1._Why_use_it}/step1.md | 4 +--- ProxyContract/{2_How => 2._How_it_works}/step2.md | 2 -- ProxyContract/{3_Delegatecall => 3._DelegateCall}/step3.md | 4 +--- .../step4.md | 2 -- .../step4.sol | 0 ProxyContract/{5_Test => 5._Test}/step5.md | 0 ProxyContract/{5_Test => 5._Test}/step5.sol | 0 ProxyContract/{5_Test => 5._Test}/step5_answer.sol | 0 ProxyContract/{5_Test => 5._Test}/step5_test.sol | 0 .../{6_Storage_Problem => 6._A_Storage_Problem}/step6.md | 2 +- .../{6_Storage_Problem => 6._A_Storage_Problem}/step6.sol | 0 ProxyContract/{7_links => 7._Links}/step7.md | 2 +- 12 files changed, 4 insertions(+), 12 deletions(-) rename ProxyContract/{1_Why => 1._Why_use_it}/step1.md (96%) rename ProxyContract/{2_How => 2._How_it_works}/step2.md (97%) rename ProxyContract/{3_Delegatecall => 3._DelegateCall}/step3.md (56%) rename ProxyContract/{4_Generic_proxy_example => 4._Generic_proxy_example}/step4.md (96%) rename ProxyContract/{4_Generic_proxy_example => 4._Generic_proxy_example}/step4.sol (100%) rename ProxyContract/{5_Test => 5._Test}/step5.md (100%) rename ProxyContract/{5_Test => 5._Test}/step5.sol (100%) rename ProxyContract/{5_Test => 5._Test}/step5_answer.sol (100%) rename ProxyContract/{5_Test => 5._Test}/step5_test.sol (100%) rename ProxyContract/{6_Storage_Problem => 6._A_Storage_Problem}/step6.md (96%) rename ProxyContract/{6_Storage_Problem => 6._A_Storage_Problem}/step6.sol (100%) rename ProxyContract/{7_links => 7._Links}/step7.md (94%) 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/step2.md b/ProxyContract/2._How_it_works/step2.md similarity index 97% rename from ProxyContract/2_How/step2.md rename to ProxyContract/2._How_it_works/step2.md index 701a6252e..80d3c2348 100644 --- a/ProxyContract/2_How/step2.md +++ b/ProxyContract/2._How_it_works/step2.md @@ -1,5 +1,3 @@ -# 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**. diff --git a/ProxyContract/3_Delegatecall/step3.md b/ProxyContract/3._DelegateCall/step3.md similarity index 56% rename from ProxyContract/3_Delegatecall/step3.md rename to ProxyContract/3._DelegateCall/step3.md index ec6226c60..0405c1b69 100644 --- a/ProxyContract/3_Delegatecall/step3.md +++ b/ProxyContract/3._DelegateCall/step3.md @@ -1,6 +1,4 @@ -# 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. +**delegatecall** 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. diff --git a/ProxyContract/4_Generic_proxy_example/step4.md b/ProxyContract/4._Generic_proxy_example/step4.md similarity index 96% rename from ProxyContract/4_Generic_proxy_example/step4.md rename to ProxyContract/4._Generic_proxy_example/step4.md index b6780c228..303f485fc 100644 --- a/ProxyContract/4_Generic_proxy_example/step4.md +++ b/ProxyContract/4._Generic_proxy_example/step4.md @@ -1,5 +1,3 @@ -# 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. 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/5_Test/step5.md b/ProxyContract/5._Test/step5.md similarity index 100% rename from ProxyContract/5_Test/step5.md rename to ProxyContract/5._Test/step5.md 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/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 From 35aedbd1d6267ed872960658cb9ec6848e9c8840 Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Wed, 10 Feb 2021 16:22:18 -0500 Subject: [PATCH 2/2] further updates to proxy contract --- ProxyContract/2._How_it_works/step2.md | 8 ++++---- ProxyContract/3._DelegateCall/step3.md | 4 ++-- ProxyContract/4._Generic_proxy_example/step4.md | 10 +++++----- ProxyContract/5._Test/step5.md | 9 +++++++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ProxyContract/2._How_it_works/step2.md b/ProxyContract/2._How_it_works/step2.md index 80d3c2348..21326d5d2 100644 --- a/ProxyContract/2._How_it_works/step2.md +++ b/ProxyContract/2._How_it_works/step2.md @@ -1,11 +1,11 @@ **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**. +With this opcode, all **message calls** from the user will go through a **Proxy contract**. -The **Proxy contract** then will redirect them to the **Logic contract**. +The **Proxy contract** then redirects the calls 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. +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'll only need to update the address of Logic contract in Proxy. +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/3._DelegateCall/step3.md b/ProxyContract/3._DelegateCall/step3.md index 0405c1b69..ad2843804 100644 --- a/ProxyContract/3._DelegateCall/step3.md +++ b/ProxyContract/3._DelegateCall/step3.md @@ -1,7 +1,7 @@ -**delegatecall** 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. +**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 Logic contract. \ No newline at end of file +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/4._Generic_proxy_example/step4.md b/ProxyContract/4._Generic_proxy_example/step4.md index 303f485fc..e89d66db7 100644 --- a/ProxyContract/4._Generic_proxy_example/step4.md +++ b/ProxyContract/4._Generic_proxy_example/step4.md @@ -1,13 +1,13 @@ In the associated solidity file, **step4.sol**, there are 2 contracts - **ProxyContract** and **LogicContract**. -To use this system, we first deploy the LogicContract. +To use this system, we first deploy LogicContract. -And then when we go to deploy the ProxyContract, we pass the LogicContract's address as an arguement of the ProxyContract's constructor. +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 delegate call while keeping the context of LogicContract. +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. +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 +**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 index c61a9e78f..4a43100fb 100644 --- a/ProxyContract/5._Test/step5.md +++ b/ProxyContract/5._Test/step5.md @@ -1,6 +1,11 @@ # 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. + - 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