-
Notifications
You must be signed in to change notification settings - Fork 156
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
Conversation
There was a problem hiding this 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
e37ea91
to
ccfd317
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Will wait for @ahnaguib to review this |
contracts/UFragments.sol
Outdated
bytes32 permitDataDigest = | ||
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, ownerNonce, deadline)); | ||
bytes32 digest = | ||
keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR, permitDataDigest)); |
There was a problem hiding this comment.
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
_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));
There was a problem hiding this 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.
Holding off on this until we bump up the token solidity compiler version |
OZ released Permit contract today: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.0/contracts/drafts/ERC20Permit.sol |
@brandoniles I've updated to the new implementation which queries the chainId everytime |
contracts/UFragments.sol
Outdated
/** | ||
* @return The underlying blockchain's chainID. | ||
*/ | ||
function getChainId() public view returns (uint256) { |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
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).