Commit b8715ecc authored by vicotor's avatar vicotor

update contract for withdrawal

parent a837d358
......@@ -430,7 +430,6 @@ contract OptimismPortal is Initializable, ResourceMetering, ISemver {
// revert GasEstimation();
// }
}
event Println(uint256 line);
/// @notice withdrawal for a user.
......@@ -447,20 +446,10 @@ contract OptimismPortal is Initializable, ResourceMetering, ISemver {
external
whenNotPaused
{
emit Println(1);
if (_param.user == address(this)) revert BadTarget();
emit Println(2);
bytes32 outputRoot = l2Oracle.getL2Output(_l2OutputIndex).outputRoot;
emit Println(3);
require(_param.user!=address(this), "BadTarget()");
Types.OutputProposal memory proposal = l2Oracle.getL2Output(_l2OutputIndex);
bytes32 outputRoot = proposal.outputRoot;
bytes32 withdrawalHash = Hashing.hashExChainWithdrawal(_param);
emit Println(4);
ProvenWithdrawal memory provenWithdrawal = provenWithdrawals[withdrawalHash];
require(
provenWithdrawal.timestamp == 0
|| l2Oracle.getL2Output(provenWithdrawal.l2OutputIndex).outputRoot != provenWithdrawal.outputRoot,
"OptimismPortal: withdrawal hash has already been proven"
);
emit Println(5);
// Verify that the hash of this withdrawal was stored in the L2toL1MessagePasser contract
// on L2. If this is true, under the assumption that the SecureMerkleTrie does not have
......@@ -475,7 +464,6 @@ contract OptimismPortal is Initializable, ResourceMetering, ISemver {
}),
"OptimismPortal: invalid withdrawal inclusion proof"
);
emit Println(6);
// Designate the withdrawalHash as proven by storing the `outputRoot`, `timestamp`, and
// `l2BlockNumber` in the `provenWithdrawals` mapping. A `withdrawalHash` can only be
......@@ -485,30 +473,24 @@ contract OptimismPortal is Initializable, ResourceMetering, ISemver {
timestamp: uint128(block.timestamp),
l2OutputIndex: uint128(_l2OutputIndex)
});
emit Println(7);
// Check that this withdrawal has not already been finalized, this is replay protection.
require(finalizedWithdrawals[withdrawalHash] == false, "OptimismPortal: withdrawal has already been finalized");
emit Println(8);
// Mark the withdrawal as finalized so it can't be replayed.
finalizedWithdrawals[withdrawalHash] = true;
emit Println(9);
// Set the l2Sender so contracts know who triggered this withdrawal on L2.
// This acts as a reentrancy guard.
l2Sender = msg.sender;
bool success;
emit Println(10);
(address token,) = gasPayingToken();
if (token == Constants.ETHER) {
emit Println(11);
success = SafeCall.send(_param.user, _param.value);
} else {
// Cannot call the token contract directly from the portal. This would allow an attacker
// to call approve from a withdrawal and drain the balance of the portal.
emit Println(12);
if (_param.user == token) revert BadTarget();
require(_param.user != token, "BadTarget() user queal token address");
// Only transfer value when a non zero value is specified. This saves gas in the case of
// using the standard bridge or arbitrary message passing.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment