-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
send rate in data and time during deposit flow
- Loading branch information
Showing
12 changed files
with
148 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-FileCopyrightText: 2023 Lido <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity 0.8.10; | ||
|
||
contract DepositDataCodec { | ||
|
||
struct DepositData { | ||
uint256 rate; | ||
uint256 time; | ||
bytes data; | ||
} | ||
|
||
function encodeDepositData(DepositData memory depositData) internal pure returns (bytes memory) { | ||
bytes memory data = bytes.concat( | ||
abi.encodePacked(depositData.rate), | ||
abi.encodePacked(depositData.time), | ||
abi.encodePacked(depositData.data) | ||
); | ||
return data; | ||
} | ||
|
||
function decodeDepositData(bytes calldata buffer) internal pure returns (DepositData memory) { | ||
|
||
if (buffer.length < 32 * 2) { | ||
revert ErrorDepositDataLength(); | ||
} | ||
|
||
DepositData memory depositData; | ||
Check warning Code scanning / Slither Uninitialized local variables Medium
DepositDataCodec.decodeDepositData(bytes).depositData is a local variable never initialized
|
||
depositData.rate = uint256(bytes32(buffer[0:31])); | ||
depositData.time = uint256(bytes32(buffer[32:63])); | ||
depositData.data = buffer[64:]; | ||
|
||
return depositData; | ||
} | ||
|
||
error ErrorDepositDataLength(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import {IL2ERC20Bridge} from "./interfaces/IL2ERC20Bridge.sol"; | |
import {BridgingManager} from "../BridgingManager.sol"; | ||
import {BridgeableTokens} from "../BridgeableTokens.sol"; | ||
import {CrossDomainEnabled} from "./CrossDomainEnabled.sol"; | ||
import {DepositDataCodec} from "./DepositDataCodec.sol"; | ||
|
||
import {IERC20Wrapable} from "../token/interfaces/IERC20Wrapable.sol"; | ||
import "hardhat/console.sol"; | ||
|
@@ -25,7 +26,8 @@ contract L1ERC20TokenBridge is | |
IL1ERC20Bridge, | ||
BridgingManager, | ||
BridgeableTokens, | ||
CrossDomainEnabled | ||
CrossDomainEnabled, | ||
DepositDataCodec | ||
{ | ||
using SafeERC20 for IERC20; | ||
|
||
|
@@ -65,16 +67,22 @@ contract L1ERC20TokenBridge is | |
if (Address.isContract(msg.sender)) { | ||
revert ErrorSenderNotEOA(); | ||
} | ||
|
||
DepositData memory depositData; | ||
Check warning Code scanning / Slither Uninitialized local variables Medium
L1ERC20TokenBridge.depositERC20(address,address,uint256,uint32,bytes).depositData is a local variable never initialized
|
||
depositData.rate = IERC20Wrapable(l1TokenNonRebasable).tokensPerStEth(); | ||
depositData.time = block.timestamp; | ||
depositData.data = data_; | ||
|
||
if(l1Token_ == l1TokenRebasable) { | ||
bytes memory data = bytes.concat(hex'01', data_); | ||
bytes memory encodedDepositData = encodeDepositData(depositData); | ||
|
||
if (isRebasableTokenFlow(l1Token_, l2Token_)) { | ||
IERC20(l1TokenRebasable).safeTransferFrom(msg.sender, address(this), amount_); | ||
IERC20(l1TokenRebasable).approve(l1TokenNonRebasable, amount_); | ||
uint256 wstETHAmount = IERC20Wrapable(l1TokenNonRebasable).wrap(amount_); | ||
_initiateERC20Deposit(l1Token_, l2Token_, msg.sender, msg.sender, wstETHAmount, l2Gas_, data); | ||
} else { | ||
_initiateERC20Deposit(l1TokenRebasable, l2TokenRebasable, msg.sender, msg.sender, wstETHAmount, l2Gas_, encodedDepositData); | ||
} else if (isNonRebasableTokenFlow(l1Token_, l2Token_)) { | ||
IERC20(l1TokenNonRebasable).safeTransferFrom(msg.sender, address(this), amount_); | ||
_initiateERC20Deposit(l1Token_, l2Token_, msg.sender, msg.sender, amount_, l2Gas_, data_); | ||
_initiateERC20Deposit(l1TokenNonRebasable, l2TokenNonRebasable, msg.sender, msg.sender, amount_, l2Gas_, encodedDepositData); | ||
} | ||
} | ||
|
||
|
@@ -111,10 +119,10 @@ contract L1ERC20TokenBridge is | |
onlySupportedL2Token(l2Token_) | ||
onlyFromCrossDomainAccount(l2TokenBridge) | ||
{ | ||
if (data_.length > 0 && data_[0] == hex'01') { | ||
if (isRebasableTokenFlow(l1Token_, l2Token_)) { | ||
uint256 stETHAmount = IERC20Wrapable(l1TokenNonRebasable).unwrap(amount_); | ||
IERC20(l1TokenRebasable).safeTransfer(to_, stETHAmount); | ||
} else { | ||
} else if (isNonRebasableTokenFlow(l1Token_, l2Token_)) { | ||
IERC20(l1Token_).safeTransfer(to_, amount_); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,10 @@ contract ERC20Rebasable is IERC20Wrapable, IERC20, ERC20Metadata { | |
return sharesAmount; | ||
} | ||
Check failure Code scanning / Slither Unchecked transfer High
ERC20Rebasable.unwrap(uint256) ignores return value by wrappedToken.transfer(msg.sender,sharesAmount)
|
||
|
||
function tokensPerStEth() external view returns (uint256) { | ||
return 0; | ||
} | ||
|
||
function mintShares(address account_, uint256 amount_) external returns (uint256) { | ||
return _mintShares(account_, amount_); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.