Skip to content

Commit

Permalink
Re-arrange section (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
YamenMerhi authored Aug 6, 2024
1 parent 59540e2 commit 84b5519
Showing 1 changed file with 122 additions and 122 deletions.
244 changes: 122 additions & 122 deletions docs/ERC-725.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ requires: 165, 173

## Abstract

The following describes two standards that allow for a generic data storage in a smart contract and a generic execution through a smart contract. These can be used seperate or in conjunction and can serve as building blocks for smart contract accounts, upgradable meta data and other means.
The following describes two standards that allow for generic data storage in a smart contract and a generic execution through a smart contract. These can be used separately or in conjunction and can serve as building blocks for smart contract accounts, upgradable metadata, and other means.

## Motivation

The initial motivation came out of the need to create a smart contract account system thats flexible enough to be viable long term, but also defined enough to be standardised. They are a generic set of two standardised building blocks to be used in all forms of smart contracts.
The initial motivation came out of the need to create a smart contract account system that's flexible enough to be viable long-term but also defined enough to be standardized. They are a generic set of two standardized building blocks to be used in all forms of smart contracts.

This standard consists of two sub standards, a generic data key/value store (ERC725Y) and a generic execute function (ERC725X). Both of which in combination allow for a very flexible and long lasting account system. The account version of ERC725 is standardised under [LSP0 ERC725Account](https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-0-ERC725Account.md).
This standard consists of two sub-standards, a generic data key/value store (ERC725Y) and a generic execute function (ERC725X). Both of these in combination allow for a very flexible and long-lasting account system. The account version of ERC725 is standardised under [LSP0 ERC725Account](https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-0-ERC725Account.md).

These standards (ERC725 X and Y) can also be used separately to enhance NFTs and Token meta data or other types of smart contracts. ERC725X allows for a generic execution through a smart contract, functioning as an account or actor.
These standards (ERC725 X and Y) can also be used separately to enhance NFTs and Token metadata or other types of smart contracts. ERC725X allows for a generic execution through a smart contract, functioning as an account or actor.

## Specification

Expand All @@ -39,6 +39,110 @@ And the event:

---

### ERC725Y

**ERC725Y** interface id according to [ERC165]: `0x629aa694`.

Smart contracts implementing the ERC725Y standard MUST implement the [ERC165] `supportsInterface(..)` function and MUST support the ERC165 and ERC725Y interface ids.

### Methods

Smart contracts implementing the ERC725Y standard MUST implement all of the functions listed below:

#### getData

```solidity
function getData(bytes32 dataKey) external view returns(bytes memory)
```

Function Selector: `0x54f6127f`

Gets the data set for the given data key.

_Parameters:_

- `dataKey`: the data key which value to retrieve.

_Returns:_ `bytes` , The data for the requested data key.

#### getDataBatch

```solidity
function getDataBatch(bytes32[] memory dataKeys) external view returns(bytes[] memory)
```

Function Selector: `0xdedff9c6`

Gets array of data at multiple given data keys.

_Parameters:_

- `dataKeys`: the data keys which values to retrieve.

_Returns:_ `bytes[]` , array of data values for the requested data keys.

#### setData

```solidity
function setData(bytes32 dataKey, bytes memory dataValue) external payable
```

Function Selector: `0x7f23690c`

Sets data as bytes in the storage for a single data key.

_Parameters:_

- `dataKey`: the data key which value to set.
- `dataValue`: the data to store.

_Requirements:_

- MUST only be called by the current owner of the contract.

**Triggers Event:** [DataChanged](#datachanged)

#### setDataBatch

```solidity
function setDataBatch(bytes32[] memory dataKeys, bytes[] memory dataValues) external payable
```

Function Selector: `0x97902421`

Sets array of data at multiple data keys. MUST only be called by the current owner of the contract.

_Parameters:_

- `dataKeys`: the data keys which values to set.
- `dataValues`: the array of bytes to set.

_Requirements:_

- Array parameters MUST have the same length.
- MUST only be called by the current owner of the contract.

**Triggers Event:** [DataChanged](#datachanged)

### Events

#### DataChanged

```solidity
event DataChanged(bytes32 indexed dataKey, bytes dataValue)
```

MUST be triggered when a data key is successfully set.

### ERC725Y Data keys

Data keys, are the way to retrieve values via `getData()`. These `bytes32` values can be freely chosen, or defined by a standard.
A common way to define data keys is the hash of a word, e.g. `keccak256('ERCXXXMyNewKeyType')` which results in: `0x6935a24ea384927f250ee0b954ed498cd9203fc5d2bf95c735e52e6ca675e047`

The [LSP2 ERC725JSONSchema standard](https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-2-ERC725YJSONSchema.md) is a more explicit ERC725Y data key standard, that defines key types and value types, and their encoding and decoding.

---

### ERC725X

**ERC725X** interface id according to [ERC165]: `0x7545acac`.
Expand Down Expand Up @@ -152,145 +256,32 @@ event ContractCreated(uint256 indexed operationType, address indexed contractAdd

MUST be triggered when `execute` creates a new contract using the `operationType` `1`, `2`.

---

### ERC725Y

**ERC725Y** interface id according to [ERC165]: `0x629aa694`.

Smart contracts implementing the ERC725Y standard MUST implement the [ERC165] `supportsInterface(..)` function and MUST support the ERC165 and ERC725Y interface ids.

### Methods

Smart contracts implementing the ERC725Y standard MUST implement all of the functions listed below:

#### getData

```solidity
function getData(bytes32 dataKey) external view returns(bytes memory)
```

Function Selector: `0x54f6127f`

Gets the data set for the given data key.

_Parameters:_

- `dataKey`: the data key which value to retrieve.

_Returns:_ `bytes` , The data for the requested data key.

#### getDataBatch

```solidity
function getData(bytes32[] memory dataKeys) external view returns(bytes[] memory)
```

Function Selector: `0xdedff9c6`

Gets array of data at multiple given data keys.

_Parameters:_

- `dataKeys`: the data keys which values to retrieve.

_Returns:_ `bytes[]` , array of data values for the requested data keys.

#### setData

```solidity
function setData(bytes32 dataKey, bytes memory dataValue) external payable
```

Function Selector: `0x7f23690c`

Sets data as bytes in the storage for a single data key.

_Parameters:_

- `dataKey`: the data key which value to set.
- `dataValue`: the data to store.

_Requirements:_

- MUST only be called by the current owner of the contract.

**Triggers Event:** [DataChanged](#datachanged)

#### setDataBatch

```solidity
function setData(bytes32[] memory dataKeys, bytes[] memory dataValues) external payable
```

Function Selector: `0x97902421`

Sets array of data at multiple data keys. MUST only be called by the current owner of the contract.

_Parameters:_

- `dataKeys`: the data keys which values to set.
- `dataValues`: the array of bytes to set.

_Requirements:_

- Array parameters MUST have the same length.
- MUST only be called by the current owner of the contract.

**Triggers Event:** [DataChanged](#datachanged)

### Events

#### DataChanged

```solidity
event DataChanged(bytes32 indexed dataKey, bytes dataValue)
```

MUST be triggered when a data key was successfully set.

### ERC725Y Data keys

Data keys, are the way to retrieve values via `getData()`. These `bytes32` values can be freely chosen, or defined by a standard.
A common way to define data keys is the hash of a word, e.g. `keccak256('ERCXXXMyNewKeyType')` which results in: `0x6935a24ea384927f250ee0b954ed498cd9203fc5d2bf95c735e52e6ca675e047`

The [LSP2 ERC725JSONSchema standard](https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-2-ERC725YJSONSchema.md) is a more explicit ERC725Y data key standard, that defines key types and value types, and their encoding and decoding.

## Rationale

The generic way of storing data key with values was chosen to allow upgradablity over time. Stored data values can be changed over time. Other smart contract protocols can then interpret this data in new ways and react to interactions from a ERC725 smart contract differently.
The generic way of storing data keys with values was chosen to allow upgradability over time. Stored data values can be changed over time. Other smart contract protocols can then interpret this data in new ways and react to interactions from an ERC725 smart contract differently.

The data stored in an ERC725Y smart contract is not only readable/writable by off chain applications, but also by other smart contracts. Function overloading was used to allow for the retrievable for single and multiple keys, to keep gas costs minimal for both uses cases.
The data stored in an ERC725Y smart contract is not only readable/writable by off-chain applications, but also by other smart contracts. Function overloading was used to allow for the retrievable for single and multiple keys, to keep gas costs minimal for both use cases.

## Backwards Compatibility

All contracts since ERC725v2 from 2018/19 should be compatible to the current version of the standard. Mainly interface ID and Event parameters have changed, while `getDataBatch(bytes32[])` and `setDataBatch(bytes32[], bytes[])` was added as an efficient way to set/get multiple keys at once. The same applies for execution, as `executeBatch(..[])` was added as an efficient way to batch calls.
All contracts since ERC725v2 from 2018/19 should be compatible with the current version of the standard. Mainly interface ID and Event parameters have changed, while `getDataBatch(bytes32[])` and `setDataBatch(bytes32[], bytes[])` were added as an efficient way to set/get multiple keys at once. The same applies to execution, as `executeBatch(..[])` was added as an efficient way to batch calls.

## Reference Implementation

Reference implementations can be found [here](../assets/eip-725)

## Security Considerations

This contract allows generic executions, therefore special care need to be take care to prevent re-entrancy attacks and other forms of call chain attacks.
This contract allows generic executions, therefore special care should be taken to prevent re-entrancy attacks and other forms of call chain attacks.

When using the operation type `4` for `delegatecall`, it is important to consider that the called contracts can alter the state of the calling contract and also change owner variables and ERC725Y data storge entries at will. Additionally calls to `selfdestruct` are possible and other harmful state changing operations.
When using the operation type `4` for `delegatecall`, it is important to consider that the called contracts can alter the state of the calling contract and also change owner variables and ERC725Y data storage entries at will. Additionally calls to `selfdestruct` are possible and other harmful state-changing operations.

### Solidity Interfaces

```solidity
// SPDX-License-Identifier: CC0-1.0
pragma solidity >=0.5.0 <0.7.0;
interface IERC725X /* is ERC165, ERC173 */ {
event ContractCreated(uint256 indexed operationType, address indexed contractAddress, uint256 value, bytes32 indexed salt);
event Executed(uint256 indexed operationType, address indexed target, uint256 value, bytes4 indexed selector);
function execute(uint256 operationType, address target, uint256 value, bytes memory data) external payable returns(bytes memory);
function executeBatch(uint256[] memory operationsType, address[] memory targets, uint256[] memory values, bytes memory datas) external payable returns(bytes[] memory);
}
interface IERC725Y /* is ERC165, ERC173 */ {
event DataChanged(bytes32 indexed dataKey, bytes dataValue);
Expand All @@ -302,6 +293,15 @@ interface IERC725Y /* is ERC165, ERC173 */ {
function setDataBatch(bytes32[] memory dataKeys, bytes[] memory dataValues) external;
}
interface IERC725X /* is ERC165, ERC173 */ {
event ContractCreated(uint256 indexed operationType, address indexed contractAddress, uint256 value, bytes32 indexed salt);
event Executed(uint256 indexed operationType, address indexed target, uint256 value, bytes4 indexed selector);
function execute(uint256 operationType, address target, uint256 value, bytes memory data) external payable returns(bytes memory);
function executeBatch(uint256[] memory operationsType, address[] memory targets, uint256[] memory values, bytes memory datas) external payable returns(bytes[] memory);
}
interface IERC725 /* is IERC725X, IERC725Y */ {
}
Expand Down

0 comments on commit 84b5519

Please sign in to comment.