Skip to content

Commit 2bce10d

Browse files
authored
Merge pull request #659 from lidofinance/fix/shapella-upgrade-fixes
Fix: shapella upgrade fixes [WIP]
2 parents b609306 + 4ec32dc commit 2bce10d

File tree

140 files changed

+10951
-3756
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+10951
-3756
lines changed

.husky/pre-commit

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4+
RED_COLOR='\033[0;31m'
5+
NO_COLOR='\033[0m'
6+
47
yarn compile
5-
git diff --quiet lib/abi
8+
git diff --quiet lib/abi || (echo -e "${RED_COLOR}Unstaged ABIs detected${NO_COLOR}"; exit 1)
69

710
yarn lint

contracts/0.4.24/Lido.sol

+114-139
Large diffs are not rendered by default.

contracts/0.4.24/StETH.sol

+20-14
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ contract StETH is IERC20, Pausable {
7979
* For reference types, conventional storage variables are used since it's non-trivial
8080
* and error-prone to implement reference-type unstructured storage using Solidity v0.4;
8181
* see https://github.com/lidofinance/lido-dao/issues/181#issuecomment-736098834
82+
*
83+
* keccak256("lido.StETH.totalShares")
8284
*/
83-
bytes32 internal constant TOTAL_SHARES_POSITION = keccak256("lido.StETH.totalShares");
85+
bytes32 internal constant TOTAL_SHARES_POSITION =
86+
0xe3b4b636e601189b5f4c6742edf2538ac12bb61ed03e6da26949d69838fa447e;
8487

8588
/**
8689
* @notice An executed shares transfer from `sender` to `recipient`.
@@ -232,7 +235,7 @@ contract StETH is IERC20, Pausable {
232235
*/
233236
function transferFrom(address _sender, address _recipient, uint256 _amount) external returns (bool) {
234237
uint256 currentAllowance = allowances[_sender][msg.sender];
235-
require(currentAllowance >= _amount, "TRANSFER_AMOUNT_EXCEEDS_ALLOWANCE");
238+
require(currentAllowance >= _amount, "ALLOWANCE_EXCEEDED");
236239

237240
_transfer(_sender, _recipient, _amount);
238241
_approve(_sender, msg.sender, currentAllowance.sub(_amount));
@@ -271,7 +274,7 @@ contract StETH is IERC20, Pausable {
271274
*/
272275
function decreaseAllowance(address _spender, uint256 _subtractedValue) external returns (bool) {
273276
uint256 currentAllowance = allowances[msg.sender][_spender];
274-
require(currentAllowance >= _subtractedValue, "DECREASED_ALLOWANCE_BELOW_ZERO");
277+
require(currentAllowance >= _subtractedValue, "ALLOWANCE_BELOW_ZERO");
275278
_approve(msg.sender, _spender, currentAllowance.sub(_subtractedValue));
276279
return true;
277280
}
@@ -355,7 +358,7 @@ contract StETH is IERC20, Pausable {
355358
) external returns (uint256) {
356359
uint256 currentAllowance = allowances[_sender][msg.sender];
357360
uint256 tokensAmount = getPooledEthByShares(_sharesAmount);
358-
require(currentAllowance >= tokensAmount, "TRANSFER_AMOUNT_EXCEEDS_ALLOWANCE");
361+
require(currentAllowance >= tokensAmount, "ALLOWANCE_EXCEEDED");
359362

360363
_transferShares(_sender, _recipient, _sharesAmount);
361364
_approve(_sender, msg.sender, currentAllowance.sub(tokensAmount));
@@ -396,8 +399,8 @@ contract StETH is IERC20, Pausable {
396399
* - `_spender` cannot be the zero address.
397400
*/
398401
function _approve(address _owner, address _spender, uint256 _amount) internal {
399-
require(_owner != address(0), "APPROVE_FROM_ZERO_ADDRESS");
400-
require(_spender != address(0), "APPROVE_TO_ZERO_ADDRESS");
402+
require(_owner != address(0), "APPROVE_FROM_ZERO_ADDR");
403+
require(_spender != address(0), "APPROVE_TO_ZERO_ADDR");
401404

402405
allowances[_owner][_spender] = _amount;
403406
emit Approval(_owner, _spender, _amount);
@@ -423,17 +426,18 @@ contract StETH is IERC20, Pausable {
423426
* Requirements:
424427
*
425428
* - `_sender` cannot be the zero address.
426-
* - `_recipient` cannot be the zero address.
429+
* - `_recipient` cannot be the zero address or the `stETH` token contract itself
427430
* - `_sender` must hold at least `_sharesAmount` shares.
428431
* - the contract must not be paused.
429432
*/
430433
function _transferShares(address _sender, address _recipient, uint256 _sharesAmount) internal {
431-
require(_sender != address(0), "TRANSFER_FROM_THE_ZERO_ADDRESS");
432-
require(_recipient != address(0), "TRANSFER_TO_THE_ZERO_ADDRESS");
434+
require(_sender != address(0), "TRANSFER_FROM_ZERO_ADDR");
435+
require(_recipient != address(0), "TRANSFER_TO_ZERO_ADDR");
436+
require(_recipient != address(this), "TRANSFER_TO_STETH_CONTRACT");
433437
_whenNotStopped();
434438

435439
uint256 currentSenderShares = shares[_sender];
436-
require(_sharesAmount <= currentSenderShares, "TRANSFER_AMOUNT_EXCEEDS_BALANCE");
440+
require(_sharesAmount <= currentSenderShares, "BALANCE_EXCEEDED");
437441

438442
shares[_sender] = currentSenderShares.sub(_sharesAmount);
439443
shares[_recipient] = shares[_recipient].add(_sharesAmount);
@@ -451,7 +455,7 @@ contract StETH is IERC20, Pausable {
451455
* - the contract must not be paused.
452456
*/
453457
function _mintShares(address _recipient, uint256 _sharesAmount) internal returns (uint256 newTotalShares) {
454-
require(_recipient != address(0), "MINT_TO_THE_ZERO_ADDRESS");
458+
require(_recipient != address(0), "MINT_TO_ZERO_ADDR");
455459

456460
newTotalShares = _getTotalShares().add(_sharesAmount);
457461
TOTAL_SHARES_POSITION.setStorageUint256(newTotalShares);
@@ -477,10 +481,10 @@ contract StETH is IERC20, Pausable {
477481
* - the contract must not be paused.
478482
*/
479483
function _burnShares(address _account, uint256 _sharesAmount) internal returns (uint256 newTotalShares) {
480-
require(_account != address(0), "BURN_FROM_THE_ZERO_ADDRESS");
484+
require(_account != address(0), "BURN_FROM_ZERO_ADDR");
481485

482486
uint256 accountShares = shares[_account];
483-
require(_sharesAmount <= accountShares, "BURN_AMOUNT_EXCEEDS_BALANCE");
487+
require(_sharesAmount <= accountShares, "BALANCE_EXCEEDED");
484488

485489
uint256 preRebaseTokenAmount = getPooledEthByShares(_sharesAmount);
486490

@@ -509,11 +513,13 @@ contract StETH is IERC20, Pausable {
509513
* Allows to get rid of zero checks for `totalShares` and `totalPooledEther`
510514
* and overcome corner cases.
511515
*
516+
* NB: reverts if the current contract's balance is zero.
517+
*
512518
* @dev must be invoked before using the token
513519
*/
514520
function _bootstrapInitialHolder() internal returns (uint256) {
515521
uint256 balance = address(this).balance;
516-
require(balance != 0, "EMPTY_INIT_BALANCE");
522+
assert(balance != 0);
517523

518524
if (_getTotalShares() == 0) {
519525
// if protocol is empty bootstrap it with the contract's balance

contracts/0.4.24/StETHPermit.sol

+12-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pragma solidity 0.4.24;
66

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

9-
import {ECDSA} from "../common/lib/ECDSA.sol";
9+
import {SignatureUtils} from "../common/lib/SignatureUtils.sol";
1010
import {IEIP712StETH} from "../common/interfaces/IEIP712StETH.sol";
1111

1212
import {StETH} from "./StETH.sol";
@@ -69,14 +69,19 @@ contract StETHPermit is IERC2612, StETH {
6969

7070
/**
7171
* @dev Storage position used for the EIP712 message utils contract
72+
*
73+
* keccak256("lido.StETHPermit.eip712StETH")
7274
*/
73-
bytes32 internal constant EIP712_STETH_POSITION = keccak256("lido.StETHPermit.eip712StETH");
75+
bytes32 internal constant EIP712_STETH_POSITION =
76+
0x42b2d95e1ce15ce63bf9a8d9f6312cf44b23415c977ffa3b884333422af8941c;
7477

7578
/**
7679
* @dev Typehash constant for ERC-2612 (Permit)
80+
*
81+
* keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")
7782
*/
7883
bytes32 internal constant PERMIT_TYPEHASH =
79-
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
84+
0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
8085

8186
/**
8287
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
@@ -94,17 +99,15 @@ contract StETHPermit is IERC2612, StETH {
9499
function permit(
95100
address _owner, address _spender, uint256 _value, uint256 _deadline, uint8 _v, bytes32 _r, bytes32 _s
96101
) external {
97-
require(block.timestamp <= _deadline, "ERC20Permit: expired deadline");
102+
require(block.timestamp <= _deadline, "DEADLINE_EXPIRED");
98103

99104
bytes32 structHash = keccak256(
100105
abi.encode(PERMIT_TYPEHASH, _owner, _spender, _value, _useNonce(_owner), _deadline)
101106
);
102107

103108
bytes32 hash = IEIP712StETH(getEIP712StETH()).hashTypedDataV4(address(this), structHash);
104109

105-
address signer = ECDSA.recover(hash, _v, _r, _s);
106-
require(signer == _owner, "ERC20Permit: invalid signature");
107-
110+
require(SignatureUtils.isValidSignature(_owner, hash, _v, _r, _s), "INVALID_SIGNATURE");
108111
_approve(_owner, _spender, _value);
109112
}
110113

@@ -158,8 +161,8 @@ contract StETHPermit is IERC2612, StETH {
158161
* @dev Initialize EIP712 message utils contract for stETH
159162
*/
160163
function _initializeEIP712StETH(address _eip712StETH) internal {
161-
require(_eip712StETH != address(0), "StETHPermit: zero eip712StETH");
162-
require(getEIP712StETH() == address(0), "StETHPermit: eip712StETH already set");
164+
require(_eip712StETH != address(0), "ZERO_EIP712STETH");
165+
require(getEIP712StETH() == address(0), "EIP712STETH_ALREADY_SET");
163166

164167
EIP712_STETH_POSITION.setStorageAddress(_eip712StETH);
165168

0 commit comments

Comments
 (0)