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

Fix: move eip712 for stETH to unstructured storage #536

Merged
Merged
Show file tree
Hide file tree
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
23 changes: 17 additions & 6 deletions contracts/0.4.24/StETHPermit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
/* See contracts/COMPILERS.md */
pragma solidity 0.4.24;

import {UnstructuredStorage} from "@aragon/os/contracts/common/UnstructuredStorage.sol";

import {ECDSA} from "../common/lib/ECDSA.sol";
import {IERC2612} from "./interfaces/IERC2612.sol";
import {IEIP712} from "../common/interfaces/IEIP712.sol";

import {StETH} from "./StETH.sol";

contract StETHPermit is IERC2612, StETH {
using UnstructuredStorage for bytes32;

/**
* @dev Service event for initialization
*/
Expand All @@ -23,9 +27,9 @@ contract StETHPermit is IERC2612, StETH {
mapping(address => uint256) internal noncesByAddress;

/**
* @dev EIP712 message utils contract for StETH
* @dev Storage position used for the EIP712 message utils contract
*/
address internal eip712StETH;
bytes32 internal constant EIP712_STETH_POSITION = keccak256("lido.StETHPermit.eip712StETH");

/**
* @dev Typehash constant for ERC-2612 (Permit)
Expand Down Expand Up @@ -55,7 +59,7 @@ contract StETHPermit is IERC2612, StETH {
abi.encode(PERMIT_TYPEHASH, _owner, _spender, _value, _useNonce(_owner), _deadline)
);

bytes32 hash = IEIP712(eip712StETH).hashTypedDataV4(structHash);
bytes32 hash = IEIP712(_getEIP712StETH()).hashTypedDataV4(structHash);

address signer = ECDSA.recover(hash, _v, _r, _s);
require(signer == _owner, "ERC20Permit: invalid signature");
Expand All @@ -79,7 +83,7 @@ contract StETHPermit is IERC2612, StETH {
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32) {
return IEIP712(eip712StETH).domainSeparatorV4();
return IEIP712(_getEIP712StETH()).domainSeparatorV4();
}

/**
Expand All @@ -95,10 +99,17 @@ contract StETHPermit is IERC2612, StETH {
*/
function _initializeEIP712StETH(address _eip712StETH) internal {
require(_eip712StETH != address(0), "StETHPermit: zero eip712StETH");
require(eip712StETH == address(0), "StETHPermit: eip712StETH already set");
require(_getEIP712StETH() == address(0), "StETHPermit: eip712StETH already set");

eip712StETH = _eip712StETH;
EIP712_STETH_POSITION.setStorageAddress(_eip712StETH);

emit EIP712StETHInitialized(_eip712StETH);
}

/**
* @dev Get EIP712 message utils contract
*/
function _getEIP712StETH() internal view returns (address) {
return EIP712_STETH_POSITION.getStorageAddress();
}
}
2 changes: 1 addition & 1 deletion contracts/0.4.24/test_helpers/LidoMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ contract LidoMock is Lido {
}

function resetEip712StETH() external {
eip712StETH = address(0);
EIP712_STETH_POSITION.setStorageAddress(0);
}
}