From 245a4626eebe24db70debe57caa1ebdc9b6c8a58 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Tue, 29 Sep 2020 08:47:58 +0200 Subject: [PATCH] use ECDSA utils from OpenZeppelin --- status-pay/contracts/EVMUtils.sol | 22 ---------------------- status-pay/contracts/StatusPay.sol | 6 ++++-- status-pay/contracts/StatusPayBucket.sol | 4 +++- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/status-pay/contracts/EVMUtils.sol b/status-pay/contracts/EVMUtils.sol index 854638b..596d844 100644 --- a/status-pay/contracts/EVMUtils.sol +++ b/status-pay/contracts/EVMUtils.sol @@ -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) { uint256 id; assembly { diff --git a/status-pay/contracts/StatusPay.sol b/status-pay/contracts/StatusPay.sol index 339a1a1..45ec155 100644 --- a/status-pay/contracts/StatusPay.sol +++ b/status-pay/contracts/StatusPay.sol @@ -3,6 +3,8 @@ pragma solidity >=0.5.0 <0.7.0; pragma experimental ABIEncoderV2; import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts-ethereum-package/contracts/cryptography/ECDSA.sol"; + import "./IBlockRelay.sol"; import "./BlockConsumer.sol"; import "./EVMUtils.sol"; @@ -154,7 +156,7 @@ contract StatusPay is BlockConsumer { function unlockAccount(Unlock memory _unlock, bytes memory _signature) public { 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]; validateAnchorBlock(_unlock.blockNumber, _unlock.blockHash, maxTxDelayInBlocks); @@ -171,7 +173,7 @@ contract StatusPay is BlockConsumer { } 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]]; // allow direct payment without Keycard from owner diff --git a/status-pay/contracts/StatusPayBucket.sol b/status-pay/contracts/StatusPayBucket.sol index 5036392..a5816b2 100644 --- a/status-pay/contracts/StatusPayBucket.sol +++ b/status-pay/contracts/StatusPayBucket.sol @@ -3,6 +3,8 @@ pragma solidity >=0.5.0 <0.7.0; pragma experimental ABIEncoderV2; import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts-ethereum-package/contracts/cryptography/ECDSA.sol"; + import "./StatusPay.sol"; import "./IBlockRelay.sol"; import "./BlockConsumer.sol"; @@ -76,7 +78,7 @@ contract StatusPayBucket is BlockConsumer { require(blockTimestamp() < expirationTime, "expired redeemable"); 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]; require(redeemable.recipient == recipient, "not found");