Skip to content

Commit 7a22e88

Browse files
TepNiksakulstra
authored andcommitted
refactor: replaced the ecrecover with the OZ's ECDSA.recover
1 parent 468e5dc commit 7a22e88

6 files changed

Lines changed: 17 additions & 7 deletions

File tree

docs/3.4/Aave-v3.4-features.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ The implementation for aAAVE was upgraded in line with the other tokens: [AToken
137137
- VersionedInitializable now bricks the initializer on the implementation, so implementations no longer have to be initialized in order to prevent malicious initialization.
138138
- Now all fees from flash-loans are sent to the `RESERVE_TREASURY_ADDRESS` in the form of the underlying token. Also, the function `FLASHLOAN_PREMIUM_TO_PROTOCOL` in the `Pool` contract now always returns `100_00` value.
139139
- Improved the accuracy and gas consumption of the `calculateCompoundedInterest` function without changing the formula. Inside calculations of the `second_term` and `third_term` variables now at first the function performs multiplications by `exp` and then divides by `SECONDS_PER_YEAR`. Previously it was the other way around, first there was division, then multiplication.
140+
- Replaced the use of the `ecrecover` function call with the OpenZeppelin's `ECDSA.recover` function call.
140141

141142
## Changelog
142143

src/contracts/mocks/testnet-helpers/TestnetERC20.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.0;
33

4+
import {ECDSA} from 'openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol';
5+
46
import {Ownable} from '../../dependencies/openzeppelin/contracts/Ownable.sol';
57
import {ERC20} from '../../dependencies/openzeppelin/contracts/ERC20.sol';
68
import {IERC20WithPermit} from '../../interfaces/IERC20WithPermit.sol';
@@ -64,7 +66,7 @@ contract TestnetERC20 is IERC20WithPermit, ERC20, Ownable {
6466
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, currentValidNonce, deadline))
6567
)
6668
);
67-
require(owner == ecrecover(digest, v, r, s), 'INVALID_SIGNATURE');
69+
require(owner == ECDSA.recover(digest, v, r, s), 'INVALID_SIGNATURE');
6870
_nonces[owner] = currentValidNonce + 1;
6971
_approve(owner, spender, value);
7072
}

src/contracts/mocks/tokens/MintableERC20.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.10;
33

4+
import {ECDSA} from 'openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol';
5+
46
import {ERC20} from '../../dependencies/openzeppelin/contracts/ERC20.sol';
57
import {IERC20WithPermit} from '../../interfaces/IERC20WithPermit.sol';
68

@@ -56,7 +58,7 @@ contract MintableERC20 is IERC20WithPermit, ERC20 {
5658
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, currentValidNonce, deadline))
5759
)
5860
);
59-
require(owner == ecrecover(digest, v, r, s), 'INVALID_SIGNATURE');
61+
require(owner == ECDSA.recover(digest, v, r, s), 'INVALID_SIGNATURE');
6062
_nonces[owner] = currentValidNonce + 1;
6163
_approve(owner, spender, value);
6264
}

src/contracts/protocol/tokenization/AToken.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity ^0.8.10;
33

4+
import {SafeCast} from 'openzeppelin-contracts/contracts/utils/math/SafeCast.sol';
5+
import {ECDSA} from 'openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol';
6+
47
import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
58
import {GPv2SafeERC20} from '../../dependencies/gnosis/contracts/GPv2SafeERC20.sol';
6-
import {SafeCast} from 'openzeppelin-contracts/contracts/utils/math/SafeCast.sol';
79
import {VersionedInitializable} from '../../misc/aave-upgradeability/VersionedInitializable.sol';
810
import {Errors} from '../libraries/helpers/Errors.sol';
911
import {WadRayMath} from '../libraries/math/WadRayMath.sol';
@@ -152,7 +154,7 @@ abstract contract AToken is VersionedInitializable, ScaledBalanceTokenBase, EIP7
152154
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, currentValidNonce, deadline))
153155
)
154156
);
155-
require(owner == ecrecover(digest, v, r, s), Errors.InvalidSignature());
157+
require(owner == ECDSA.recover(digest, v, r, s), Errors.InvalidSignature());
156158
_nonces[owner] = currentValidNonce + 1;
157159
_approve(owner, spender, value);
158160
}

src/contracts/protocol/tokenization/base/DebtTokenBase.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.10;
33

4+
import {ECDSA} from 'openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol';
5+
46
import {Context} from '../../../dependencies/openzeppelin/contracts/Context.sol';
57
import {Errors} from '../../libraries/helpers/Errors.sol';
68
import {VersionedInitializable} from '../../../misc/aave-upgradeability/VersionedInitializable.sol';
@@ -62,7 +64,7 @@ abstract contract DebtTokenBase is
6264
)
6365
)
6466
);
65-
require(delegator == ecrecover(digest, v, r, s), Errors.InvalidSignature());
67+
require(delegator == ECDSA.recover(digest, v, r, s), Errors.InvalidSignature());
6668
_nonces[delegator] = currentValidNonce + 1;
6769
_approveDelegation(delegator, delegatee, value);
6870
}

src/contracts/protocol/tokenization/delegation/BaseDelegation.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pragma solidity ^0.8.0;
33

44
import {MessageHashUtils} from 'openzeppelin-contracts/contracts/utils/cryptography/MessageHashUtils.sol';
5+
import {ECDSA} from 'openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol';
56
import {SafeCast} from 'openzeppelin-contracts/contracts/utils/math/SafeCast.sol';
67

78
import {WadRayMath} from '../../libraries/math/WadRayMath.sol';
@@ -166,7 +167,7 @@ abstract contract BaseDelegation is IBaseDelegation {
166167
)
167168
);
168169

169-
require(delegator == ecrecover(digest, v, r, s), Errors.InvalidSignature());
170+
require(delegator == ECDSA.recover(digest, v, r, s), Errors.InvalidSignature());
170171

171172
_delegateByType(delegator, delegatee, delegationType);
172173
}
@@ -191,7 +192,7 @@ abstract contract BaseDelegation is IBaseDelegation {
191192
)
192193
);
193194

194-
require(delegator == ecrecover(digest, v, r, s), Errors.InvalidSignature());
195+
require(delegator == ECDSA.recover(digest, v, r, s), Errors.InvalidSignature());
195196

196197
_delegateByType(delegator, delegatee, GovernancePowerType.VOTING);
197198
_delegateByType(delegator, delegatee, GovernancePowerType.PROPOSITION);

0 commit comments

Comments
 (0)