Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Adds a new section to the documentation on "proxy patterns" #288

Merged
merged 8 commits into from
Oct 22, 2018

Conversation

eternauta1337
Copy link
Contributor

(WIP)

Fixes #151

Copy link
Contributor

@come-maiz come-maiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,68 @@
---
id: proxies
title: Proxy Pattern
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to brand this:
The ZeppelinOS Upgrade Pattern

The problem here is that the ideas for this come from many different places, so maybe at the end we can add some generic thanks to everybody researching about upgradeability in ethereum.

@martriay what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that the title has to fit in the sidebar =D

packages/docs/docs/docs/proxies.md Outdated Show resolved Hide resolved
packages/docs/docs/docs/proxies.md Outdated Show resolved Hide resolved
packages/docs/docs/docs/proxies.md Outdated Show resolved Hide resolved
packages/docs/docs/docs/proxies.md Outdated Show resolved Hide resolved
packages/docs/docs/docs/proxies.md Outdated Show resolved Hide resolved
packages/docs/docs/docs/proxies.md Outdated Show resolved Hide resolved

This code can be put in the fallback function of a proxy, and will forward any call to any function with any set of parameters to the logic contract without it needing to know anything in particular of the logic contract's interface. In essence, (1) the `calldata` is copied to memory, (2) the call is forwarded to the logic contract, (3) the return data from the call to the logic contract is retrieved, and (4) the returned data is forwarded back to the caller.

A very important thing to note is that the code makes use of `delegatecall` which executes the callee's code in the context of the caller's state. That is, the logic contract controls the proxy's state and the logic contract's state is meaningless. Thus, the proxy doesn't forward transactions to and from the logic contract, but also represents the pair's state. The state is in the proxy and the logic is in the particular implementation that the proxy points to. To put it in yet another way, the "what" is in the proxy contract and the "how" is in the logic contract.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link to delegatecall's docs.
doesn't forward -> doesn't only forward

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I like the last sentence about "what" and "how". What would you think of mentioning instead that the state variables are in the proxy, and the functions are in the logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that because it may confuse the user. One may think that variables need to be declared in the proxy in and functions in the implementation.

Removing my sentence and replacing it with nothing for now.

packages/docs/docs/docs/proxies.md Outdated Show resolved Hide resolved
@facuspagnuolo facuspagnuolo added the kind:documentation Write or review documentation content label Oct 18, 2018
@eternauta1337
Copy link
Contributor Author

@ElOpio In this last commit I removed a few sections from advanced.md and merged them into proxies.md. My criteria was "incorporate what the items in advanced.md describe that is not described in the items in proxies.md and then delete them."

Copy link
Contributor

@come-maiz come-maiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ship it!

Copy link
Contributor

@facuspagnuolo facuspagnuolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one comment

|... | |
|... | |

An example of how the randomized storage is achieved:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't use the word random, it sounds not-robust, I'd rather use something like fixed, explaining that we choose a specific position making sure that Solidity won't ever use it

Copy link
Contributor

@facuspagnuolo facuspagnuolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@facuspagnuolo facuspagnuolo merged commit dabfb5f into master Oct 22, 2018
@facuspagnuolo facuspagnuolo deleted the docs-proxy-patterns branch October 22, 2018 18:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind:documentation Write or review documentation content
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add upgradeability pattern documentation
3 participants