Skip to content

Commit

Permalink
Set standard target address storage location
Browse files Browse the repository at this point in the history
  • Loading branch information
IGI-111 committed May 22, 2024
1 parent b7c28c4 commit 37a64e9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions SRCs/src-14.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ The FuelVM provides an `LDC` instruction that is used by Sway's `std::execution:

### Required Behavior

A proxy contract SHOULD maintain the address of its target in its storage and it SHOULD base proxy specific storage fields at `sha256("storage_SRC14")` to avoid collisions with target storage.
The proxy contract MUST maintain the address of its target in its storage at slot `0x7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55` (equivalent to `sha256("storage_SRC15_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.

Expand All @@ -37,7 +39,7 @@ The following functions MUST be implemented by a proxy contract to follow the SR

#### `fn set_proxy_address(new_target: ContractId);`

If a valid call is made to this function it MUST change the target of the proxy to the contract at `new_target`.
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
Expand Down
1 change: 1 addition & 0 deletions examples/src14-simple-proxy/minimal/src/minimal.sw
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use standards::src14::SRC14;
// use sha256("storage_SRC14") as base to avoid collisions
#[namespace(SRC14)]
storage {
// target is as sha256("storage_SRC14_0")
target: ContractId = ContractId::from(ZERO_B256),
}

Expand Down
1 change: 1 addition & 0 deletions examples/src14-simple-proxy/owned/src/owned.sw
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const INITIAL_OWNER: Identity = Identity::Address(Address::from(ZERO_B256));
// use sha256("storage_SRC14") as base to avoid collisions
#[namespace(SRC14)]
storage {
// target is as sha256("storage_SRC14_0")
target: ContractId = ContractId::from(ZERO_B256),
owner: State = State::Initialized(INITIAL_OWNER),
}
Expand Down
5 changes: 5 additions & 0 deletions standards/src/src14.sw
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ abi SRC14 {
#[storage(write)]
fn set_proxy_target(new_target: ContractId);
}

/// The standard storage slot to store proxy target address.
///
/// Value is `sha256("storage_SRC14_0")`.
pub const SRC14_TARGET_STORAGE: b256 = 0x7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55;

0 comments on commit 37a64e9

Please sign in to comment.