Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy epoxy #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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**.

Expand Down
11 changes: 11 additions & 0 deletions ProxyContract/2._How_it_works/step2.md
Original file line number Diff line number Diff line change
@@ -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**.
13 changes: 0 additions & 13 deletions ProxyContract/2_How/step2.md

This file was deleted.

7 changes: 7 additions & 0 deletions ProxyContract/3._DelegateCall/step3.md
Original file line number Diff line number Diff line change
@@ -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**.
9 changes: 0 additions & 9 deletions ProxyContract/3_Delegatecall/step3.md

This file was deleted.

13 changes: 13 additions & 0 deletions ProxyContract/4._Generic_proxy_example/step4.md
Original file line number Diff line number Diff line change
@@ -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.**
15 changes: 0 additions & 15 deletions ProxyContract/4_Generic_proxy_example/step4.md

This file was deleted.

11 changes: 11 additions & 0 deletions ProxyContract/5._Test/step5.md
Original file line number Diff line number Diff line change
@@ -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!
File renamed without changes.
6 changes: 0 additions & 6 deletions ProxyContract/5_Test/step5.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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**.

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down