use ECDSA utils from OpenZeppelin
This commit is contained in:
parent
a1e7b666fa
commit
245a4626ee
|
@ -12,28 +12,6 @@ library EVMUtils {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
function recoverSigner(bytes32 _digest, bytes memory _sig) internal pure returns (address) {
|
|
||||||
require(_sig.length == 65, "bad signature length");
|
|
||||||
|
|
||||||
bytes32 r;
|
|
||||||
bytes32 s;
|
|
||||||
uint8 v;
|
|
||||||
|
|
||||||
// solium-disable-next-line security/no-inline-assembly
|
|
||||||
assembly {
|
|
||||||
r := mload(add(_sig, 32))
|
|
||||||
s := mload(add(_sig, 64))
|
|
||||||
v := byte(0, mload(add(_sig, 96)))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (v < 27) {
|
|
||||||
v += 27;
|
|
||||||
}
|
|
||||||
|
|
||||||
require(v == 27 || v == 28, "signature version doesn't match");
|
|
||||||
return ecrecover(_digest, v, r, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getChainID() internal pure returns (uint256) {
|
function getChainID() internal pure returns (uint256) {
|
||||||
uint256 id;
|
uint256 id;
|
||||||
assembly {
|
assembly {
|
||||||
|
|
|
@ -3,6 +3,8 @@ pragma solidity >=0.5.0 <0.7.0;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol";
|
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol";
|
||||||
|
import "@openzeppelin/contracts-ethereum-package/contracts/cryptography/ECDSA.sol";
|
||||||
|
|
||||||
import "./IBlockRelay.sol";
|
import "./IBlockRelay.sol";
|
||||||
import "./BlockConsumer.sol";
|
import "./BlockConsumer.sol";
|
||||||
import "./EVMUtils.sol";
|
import "./EVMUtils.sol";
|
||||||
|
@ -154,7 +156,7 @@ contract StatusPay is BlockConsumer {
|
||||||
|
|
||||||
function unlockAccount(Unlock memory _unlock, bytes memory _signature) public {
|
function unlockAccount(Unlock memory _unlock, bytes memory _signature) public {
|
||||||
require(owners[msg.sender] == address(0), "this owner already has an account");
|
require(owners[msg.sender] == address(0), "this owner already has an account");
|
||||||
address signer = EVMUtils.recoverSigner(EVMUtils.eip712Hash(DOMAIN_SEPARATOR, hashUnlock(_unlock)), _signature);
|
address signer = ECDSA.recover(EVMUtils.eip712Hash(DOMAIN_SEPARATOR, hashUnlock(_unlock)), _signature);
|
||||||
address accountAddress = keycards[signer];
|
address accountAddress = keycards[signer];
|
||||||
|
|
||||||
validateAnchorBlock(_unlock.blockNumber, _unlock.blockHash, maxTxDelayInBlocks);
|
validateAnchorBlock(_unlock.blockNumber, _unlock.blockHash, maxTxDelayInBlocks);
|
||||||
|
@ -171,7 +173,7 @@ contract StatusPay is BlockConsumer {
|
||||||
}
|
}
|
||||||
|
|
||||||
function requestPayment(Payment memory _payment, bytes memory _signature) public {
|
function requestPayment(Payment memory _payment, bytes memory _signature) public {
|
||||||
address signer = EVMUtils.recoverSigner(EVMUtils.eip712Hash(DOMAIN_SEPARATOR, hashPayment(_payment)), _signature);
|
address signer = ECDSA.recover(EVMUtils.eip712Hash(DOMAIN_SEPARATOR, hashPayment(_payment)), _signature);
|
||||||
Account storage payer = accounts[keycards[signer]];
|
Account storage payer = accounts[keycards[signer]];
|
||||||
|
|
||||||
// allow direct payment without Keycard from owner
|
// allow direct payment without Keycard from owner
|
||||||
|
|
|
@ -3,6 +3,8 @@ pragma solidity >=0.5.0 <0.7.0;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol";
|
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol";
|
||||||
|
import "@openzeppelin/contracts-ethereum-package/contracts/cryptography/ECDSA.sol";
|
||||||
|
|
||||||
import "./StatusPay.sol";
|
import "./StatusPay.sol";
|
||||||
import "./IBlockRelay.sol";
|
import "./IBlockRelay.sol";
|
||||||
import "./BlockConsumer.sol";
|
import "./BlockConsumer.sol";
|
||||||
|
@ -76,7 +78,7 @@ contract StatusPayBucket is BlockConsumer {
|
||||||
require(blockTimestamp() < expirationTime, "expired redeemable");
|
require(blockTimestamp() < expirationTime, "expired redeemable");
|
||||||
require(blockTimestamp() > startTime, "reedeming not yet started");
|
require(blockTimestamp() > startTime, "reedeming not yet started");
|
||||||
|
|
||||||
address recipient = EVMUtils.recoverSigner(EVMUtils.eip712Hash(DOMAIN_SEPARATOR, hashRedeem(_redeem)), _sig);
|
address recipient = ECDSA.recover(EVMUtils.eip712Hash(DOMAIN_SEPARATOR, hashRedeem(_redeem)), _sig);
|
||||||
|
|
||||||
Redeemable storage redeemable = redeemables[recipient];
|
Redeemable storage redeemable = redeemables[recipient];
|
||||||
require(redeemable.recipient == recipient, "not found");
|
require(redeemable.recipient == recipient, "not found");
|
||||||
|
|
Loading…
Reference in New Issue