Skip to content

Permit [eip-2612] support for AMPL #181

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

Merged
merged 1 commit into from
Feb 5, 2021
Merged

Permit [eip-2612] support for AMPL #181

merged 1 commit into from
Feb 5, 2021

Conversation

aalavandhan
Copy link
Member

Gasless approvals with permit.
https://eips.ethereum.org/EIPS/eip-2612

Reference implementations

There's one major discussion point.

As per the standard openzeppelin implementation, the domain separator is computed in the contract's constructor. However since we have a live contract instance, we cant do that.

In the current approach, I've hardcoded the values that go into the domain separator creation based on the production config. (Address, chainId and token name).

If we dont want to hardcode this, we could create a function which we invoke after upgrade which sets the domain separator after reading the contract's store (more general solution).

Copy link
Contributor

@thegostep thegostep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - though was only able to take a cursory look

@aalavandhan aalavandhan force-pushed the permit branch 3 times, most recently from e37ea91 to ccfd317 Compare January 10, 2021 19:24
Copy link
Member

@brandoniles brandoniles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@aalavandhan
Copy link
Member Author

Will wait for @ahnaguib to review this

@ahnaguib ahnaguib changed the title eip-2612 support for AMPL Permit [eip-2612] support for AMPL Jan 12, 2021
@aalavandhan aalavandhan linked an issue Jan 15, 2021 that may be closed by this pull request
bytes32 permitDataDigest =
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, ownerNonce, deadline));
bytes32 digest =
keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR, permitDataDigest));
Copy link
Member Author

@aalavandhan aalavandhan Jan 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahnaguib How OpenZeppelin implements this. It is identical

https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/master/contracts/drafts/EIP712Upgradeable.sol#L88

https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/master/contracts/drafts/ERC20PermitUpgradeable.sol#L50

_TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

_PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");

domainSeperator = keccak256(
    abi.encode(
        _TYPE_HASH,
        name,
        version,
        _getChainId(),
        address(this)
    )
);

structHash = keccak256(
      abi.encode(
          _PERMIT_TYPEHASH,
          owner,
          spender,
          amount,
          _nonces[owner].current(),
          deadline
      )
  );

digest = keccak256(abi.encodePacked("\x19\x01", domainSeperator, structHash));

Copy link
Member

@brandoniles brandoniles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until we address the hardcoded separator issue.

@aalavandhan
Copy link
Member Author

Holding off on this until we bump up the token solidity compiler version

@thegostep
Copy link
Contributor

@aalavandhan aalavandhan changed the base branch from master to compiler-upgrade February 4, 2021 21:19
@aalavandhan
Copy link
Member Author

@brandoniles I've updated to the new implementation which queries the chainId everytime

/**
* @return The underlying blockchain's chainID.
*/
function getChainId() public view returns (uint256) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be public?

Also, basic question but--does this being its own function use more gas than it would if it were just in the body of DOMAIN_SEPARATOR()?

Copy link
Member Author

@aalavandhan aalavandhan Feb 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Since it's not being used anywhere else doesn't have to be a public function

Copy link
Member

@brandoniles brandoniles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but wait for at least @thegostep 's approval also.

Copy link
Contributor

@thegostep thegostep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Base automatically changed from compiler-upgrade to master February 5, 2021 21:29
@aalavandhan aalavandhan merged commit 404bd9e into master Feb 5, 2021
@aalavandhan aalavandhan deleted the permit branch February 5, 2021 21:43
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.

support for EIP-2612
3 participants