Skip to content

Commit

Permalink
m-01: following eip712 standard in contract (#29)
Browse files Browse the repository at this point in the history
* m-01: following eip712 standard in contract

#13

* ✅ fix tests following eip712

#13

* 🩹 change typehash for eip712

* 🏷️ fix typehash

* 🏷️ fix typehash in test
  • Loading branch information
thurendous authored Sep 20, 2023
1 parent 5577750 commit af8cbb4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/ProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ contract ProxyFactory is Ownable, EIP712 {
/////// State Variables ////////
////////////////////////////////
// contest distribution expiration
bytes32 internal constant _DEPLOY_AND_DISTRIBUTE_TYPEHASH =
keccak256("DeployAndDistribute(bytes32 contestId,address implementation,bytes data)");
uint256 public constant EXPIRATION_TIME = 7 days;
uint256 public constant MAX_CONTEST_PERIOD = 28 days;

Expand Down Expand Up @@ -163,7 +165,8 @@ contract ProxyFactory is Ownable, EIP712 {
bytes calldata signature,
bytes calldata data
) public returns (address) {
bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(contestId, implementation, data)));
bytes32 digest =
_hashTypedDataV4(keccak256(abi.encode(_DEPLOY_AND_DISTRIBUTE_TYPEHASH, contestId, implementation, data)));
if (!organizer.isValidSignatureNow(digest, signature)) revert ProxyFactory__InvalidSignature();
bytes32 salt = _calculateSalt(organizer, contestId, implementation);
if (saltToCloseTime[salt] == 0) revert ProxyFactory__ContestIsNotRegistered();
Expand Down Expand Up @@ -257,7 +260,7 @@ contract ProxyFactory is Ownable, EIP712 {
/// @param proxy The proxy address
/// @param data The prize distribution data
function _distribute(address proxy, bytes calldata data) internal {
if (proxy.code.length == 0) revert ProxyFactory__ProxyIsNotAContract();
if (proxy.code.length == 0) revert ProxyFactory__ProxyIsNotAContract();
(bool success,) = proxy.call(data);
if (!success) revert ProxyFactory__DelegateCallFailed();
emit Distributed(proxy, data);
Expand Down
4 changes: 4 additions & 0 deletions test/integration/HelperContract.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ abstract contract HelperContract is Test {

// test signer's key pair when testing meta tx
// **these are all for test. should never use these in production**
// bytes32 internal constant _DEPLOY_AND_DISTRIBUTE_TYPEHASH =
// keccak256("DeployAndDistribute(bytes32 contestId,bytes data)");
bytes32 internal constant _DEPLOY_AND_DISTRIBUTE_TYPEHASH =
keccak256("DeployAndDistribute(bytes32 contestId,address implementation,bytes data)");
uint256 public constant TEST_SIGNER_KEY = 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d;
address public constant TEST_SIGNER = 0x70997970C51812dc3A010C7d01b50e0d17dc79C8;
uint256 public constant TEST_SIGNER_KEY2 = 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a;
Expand Down
2 changes: 1 addition & 1 deletion test/integration/ProxyFactoryTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ contract ProxyFactoryTest is StdCheats, HelperContract {
);
bytes32 randomId_ = keccak256(abi.encode("Jason", "001"));
bytes memory sendingData = createData();
bytes32 data = keccak256(abi.encode(randomId_, address(distributor), sendingData));
bytes32 data = keccak256(abi.encode(_DEPLOY_AND_DISTRIBUTE_TYPEHASH, randomId_,address(distributor), sendingData));
bytes32 digest = ECDSA.toTypedDataHash(domainSeparatorV4, data);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateK, digest);
bytes memory signature = abi.encodePacked(r, s, v);
Expand Down

0 comments on commit af8cbb4

Please sign in to comment.