-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs: fix typos in README (#86) * change vault_sub_id back to sub_id * docs: improve SRC-20 (#88) * docs: improve SRC-3 (#85) * Update to latest Sway Transform abusive usage of configurables into constants to support latest version of Sway that uses encoded configurables. * Update README.md * SRC-14 Simple Proxy Standard * Apply suggestions from code review Co-authored-by: Cameron Carstens <bitzoic.eth@gmail.com> * Set standard target address storage location * Apply suggestions from code review Co-authored-by: SwayStar123 <46050679+SwayStar123@users.noreply.github.com> * Update SRCs/src-14.md Co-authored-by: Cameron Carstens <bitzoic.eth@gmail.com> * Correct typo * Apply suggestions from code review Co-authored-by: João Matos <joao@tritao.eu> * Add link to UUPS * Update to forc v0.60.0 (#96) * Update to forc v0.60.0 * Run formatter * address PR comments * Update CI * Delete docs.yml and gh-pages.yml * Update pull request template to include checklist (#93) * Fix README for release --------- Co-authored-by: Paul Razvan Berg <paul.razvan.berg@gmail.com> Co-authored-by: SwayStar123 <swayambhanded@gmail.com> Co-authored-by: Paul Razvan Berg <prberg@proton.me> Co-authored-by: SwayStar123 <46050679+SwayStar123@users.noreply.github.com> Co-authored-by: IGI-111 <igi-111@protonmail.com> Co-authored-by: João Matos <joao@tritao.eu> Co-authored-by: K1-R1 <77465250+K1-R1@users.noreply.github.com>
- Loading branch information
1 parent
a001d3c
commit 348f717
Showing
25 changed files
with
334 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Simple Upgradable Proxies | ||
|
||
## Abstract | ||
|
||
The following proposes a standard for simple upgradable proxies. | ||
|
||
## Motivation | ||
|
||
We seek to standardize proxy implementation to improve developer experience and enable tooling to automatically deploy or update proxies as needed. | ||
|
||
## Prior Art | ||
|
||
[This OpenZeppelin blog post](https://blog.openzeppelin.com/the-state-of-smart-contract-upgrades#proxies-and-implementations) is a good survey of the state of the art at this time. | ||
|
||
Proxy designs fall into three essential categories: | ||
1. Immutable proxies which are lightweight clones of other contracts but can't change targets | ||
2. Upgradable proxies such as [UUPS](https://eips.ethereum.org/EIPS/eip-1822) which store a target in storage and delegate all calls to it | ||
3. [Diamonds](https://eips.ethereum.org/EIPS/eip-2535) which are both upgradable and can point to multiple targets on a per method basis | ||
|
||
This document falls in the second category. We want to standardize the implementation of simple upgradable passthrough contracts. | ||
|
||
The FuelVM provides an `LDC` instruction that is used by Sway's `std::execution::run_external` to provide a similar behavior to EVM's `delegatecall` and execute instructions from another contract while retaining one's own storage context. This is the intended means of implementation of this standard. | ||
|
||
## Specification | ||
|
||
### Required Behavior | ||
|
||
The proxy contract MUST maintain the address of its target in its storage at slot `0x7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55` (equivalent to `sha256("storage_SRC14_0")`). | ||
It SHOULD base other proxy specific storage fields at `sha256("storage_SRC14")` to avoid collisions with target storage. | ||
It MAY have its storage definition overlap with that of its target if necessary. | ||
|
||
The proxy contract MUST delegate any method call not part of its interface to the target contract. | ||
|
||
This delegation MUST retain the storage context of the proxy contract. | ||
|
||
### Required Public Functions | ||
|
||
The following functions MUST be implemented by a proxy contract to follow the SRC-14 standard: | ||
|
||
#### `fn set_proxy_target(new_target: ContractId);` | ||
|
||
If a valid call is made to this function it MUST change the target address of the proxy to `new_target`. | ||
This method SHOULD implement access controls such that the target can only be changed by a user that possesses the right permissions (typically the proxy owner). | ||
|
||
## Rationale | ||
|
||
This standard is meant to provide simple upgradability, it is deliberately minimalistic and does not provide the level of functionality of diamonds. | ||
|
||
Unlike in [UUPS](https://eips.ethereum.org/EIPS/eip-1822), this standard requires that the upgrade function is part of the proxy and not its target. | ||
This prevents irrecoverable updates if a proxy is made to point to another proxy and no longer has access to upgrade logic. | ||
|
||
## Backwards Compatibility | ||
|
||
SRC-14 is intended to be compatible with SRC-5 and other standards of contract functionality. | ||
|
||
As it is the first attempt to standardize proxy implementation, we do not consider interoperability with other proxy standards. | ||
|
||
## Security Considerations | ||
|
||
Permissioning proxy target changes is the primary consideration here. | ||
This standard is not opinionated about means of achieving this, use of [SRC-5](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-5.md) is recommended. | ||
|
||
## Example ABI | ||
|
||
```sway | ||
abi SRC14 { | ||
#[storage(write)] | ||
fn set_proxy_target(new_target: ContractId); | ||
} | ||
``` | ||
|
||
## Example Implementation | ||
|
||
### [Minimal Proxy](../examples/examples/src14-simple-proxy/owned/src/minimal.sw) | ||
|
||
Example of a minimal SRC-14 implementation with no access control. | ||
|
||
### [Owned Proxy](../examples/examples/src14-simple-proxy/owned/src/owned.sw) | ||
|
||
Example of a SRC-14 implementation that also implements [SRC-5](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-5.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.