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

Update EIP-5732 Clean up #5910

Merged
merged 6 commits into from
Nov 10, 2022
Merged
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
103 changes: 1 addition & 102 deletions EIPS/eip-5732.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ But there MUST be a way to supply an extra field of `secret_salt`, so that commi

## Rationale

1. One design options is that we can attach a Commit Interface to any individual ERCs such as voting standards or token standards. We choose to have a simple and eneralize commit interface so all ERCs can be extended to support commit-reveal without changing their basic method signatures.
1. One design options is that we can attach a Commit Interface to any individual ERCs such as voting standards or token standards. We choose to have a simple and generalize commit interface so all ERCs can be extended to support commit-reveal without changing their basic method signatures.

2. The key derived design decision we made is we will have a standardized `commit` method without a standardized `reveal` method, making room for customized reveal method or using `commit` with existing standard.

Expand All @@ -88,107 +88,6 @@ The `IERC_COMMIT_CORE` is backward compatible with ENS implementations and other

## Reference Implementation

### Commit with Token-Transfer as Reveal

Example of a Simple Transfer Standard being integrated with this EIP:

```solidity
interface ISimpleToken {
function transfer(address to, uint256 amount);
}

contract SomeToken is ISimpleToken {
mapping(address => uint256, bytes calldata extraData) balance;
function transfer(address to, uint256 amount, bytes calldata extraData) {
required(balance[msg.sender] > amount);
balance[msg.sender] -= amount;
balance[to] += amount;
}
}
```

When integrating with this EIP, it becomes this

```solidity
interface ISimpleToken {
function transfer(address to, uint256 amount, bytes calldata extraData);
}

contract SomeBetterToken is ISimpleToken, IERC_COMMIT_CORE {
mapping(address => uint256) balance;
mapping(address => bytes32) lastCommits;
function commit(bytes32 _commitment) {
lastCommits[msg.sender] = _commitment;
emit Commit(...);
}
function transfer(address _to, uint256 _amount, bytes calldata _extraData/*first 32bytes are used as secret_sault*/) {
required(balance[msg.sender] > amount);
// pseudo code.
require(lastCommits[msg.sender] == _recomputeCommit(msg.sender, _to, _amount, _extraData[:32])); // the commitment from last sender was
delete lastCommits[msg.sender]; // immediately delete commits to avoid reentry attack.
balance[msg.sender] -= amount;
balance[to] += amount;
}

function _recomputeCommit(address _sender, address _to, uint256 _amount, bytes32 _secretSalt) returns (bytes32){
return keccak256(abi.encodePack(_sender, _to, _amount, _secretSalt));
}

}
```

### Commit with Voting as Reveal

Example of a Simple Transfer Standard being integrated with this EIP:

```solidity
interface ISimpleToken {
function vote(address _proposalId, uint8 _optionId, bytes calldata _extraData);
}

contract FooVote is ISimpleToken {
mapping(address => uint256/*proposalId*/ => uint8/*optionId*/) ballots;
function vote(address _proposalId, uint8 _optionId, bytes calldata _extraData) {
ballots[msg.sender][_proposalId] = _optionId;
}

// Ballot tally method omitted.
}
```

When integrating with this EIP, it becomes this

```solidity
interface ISimpleVote {
function vote(uint256 _proposalId);
}

contract BarVote is ISimpleVote, IERC_COMMIT_CORE {
mapping(address => address => bool) proposalVotes;
mapping(address => bytes32) lastCommits;
mapping(uint256 => uint256) proposalDeadlines; // block number of deadline for each proposal

function commit(bytes32 _commitment) {
lastCommits[msg.sender] = _commitment;
emit Commit(...);
}

function vote(address _proposalId, uint8 _optionId, bytes calldata _extraData) {
// pseudo code.
require(lastCommits[msg.sender] == _recomputeCommit(msg.sender, _proposalId, _optionId, _extraData[:32])); // the commitment from last sender was
delete lastCommits[msg.sender]; // immediately delete commits to avoid reentry attack.
ballots[msg.sender][_proposalId] = _optionId;
}

function _recomputeCommit(address _sender, address _proposalId, uint8 _optionId, bytes32 _secretSalt) returns (bytes32){
return keccak256(abi.encodePack(_sender, _proposalId, _optionId, _secretSalt));
}

// Ballot tally method omitted.
// Proposal deadline method omitted.
}
```

### Commit with ENS Register as Reveal

In ENS registering process, currently inside of `ETHRegistrarController` contract a commit function is being used to allow registerer fairly register a desire domain to avoid being front-run.
Expand Down