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

Dynamic Proxy #18

Merged
merged 3 commits into from
Jul 10, 2019
Merged

Dynamic Proxy #18

merged 3 commits into from
Jul 10, 2019

Conversation

AugustoL
Copy link
Contributor

Instead of using a single proxy contract this PR propose changes for creating and destroying a proxy contract for each extra call executed by the ERC827 token. This has another advantage, allowing the receiver contract to verify that the proxy was created by the original msg.sender of the tokens.

The computation of the proxy address receives as input the original msg.sender, the address of the contract to be called by the proxy and a nonce.

bytes32 salt = keccak256(abi.encodePacked(msg.sender, _to, nonces[msg.sender]));
address proxy = Create2.deploy(salt, proxyBytecode);

ERC827 contract keep tracks of nonces mapped by senders that increment each time a call is executed successfully.

Since the Create2 opcode also takes in count the address of the contract that deploys the contract it allow the token receiver to verify that the call is coming from a proxy that was created by the msg.sender.
For this the receiver contract would need the token and sender address

  function receiveVerifiedTokens(address sender, ERC827 token) public {
    address proxy = Create2.computeAddress(
      address(token),
      keccak256(abi.encodePacked(sender, address(this), token.nonces(sender))),
      token.proxyBytecode()
    );
    require(msg.sender == proxy, "ERC827Receiver: Sender invalid");
  }

Note in the ERC827Receiver test fiel I execute tests proving how the sender verification works.

AugustoL added 3 commits June 11, 2019 12:57
- Creates a ERC827 proxy for every call and destroy it after being used.
- Proxies addresses are protected against replay attacks.
- Reorganization of contracts folder.
BREAKING CHANGE: Using dinamyc procies instead of a single proxy contract
@AugustoL AugustoL merged commit 8b424ac into windingtree:master Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant