Commit f14c715f authored by vicotor's avatar vicotor

fix bug for withdrawal.

parent 3870897b
......@@ -153,8 +153,8 @@ cat << EOL >> tmp_config.json
"daResolveWindow": 100,
"daBondSize": 1000,
"daResolverRefundPercentage": 50,
"useCustomGasToken": false,
"customGasTokenAddress": "0x88395111AB1586a4030dAC62a183542762929bbC"
"useCustomGasToken": true,
"customGasTokenAddress": "0x9c4bd341cf7134a53b1f34cfa9f3dea4fde61c9c"
}
EOL
......
......@@ -214,7 +214,7 @@ contract OptimismPortal is Initializable, ResourceMetering, ISemver {
}
/// @notice Returns the gas paying token and its decimals.
function gasPayingToken() internal view returns (address addr_, uint8 decimals_) {
function gasPayingToken() public view returns (address addr_, uint8 decimals_) {
(addr_, decimals_) = systemConfig.gasPayingToken();
}
......@@ -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.
......
......@@ -2,11 +2,11 @@
source .envrc
./bin/op-proposer \
--data-dir=./data/proposer \
--data-dir=./node/proposer \
--poll-interval=12s \
--rpc.port=8560 \
--rollup-rpc=http://127.0.0.1:9545 \
--l2oo-address=$(cat ./deployer/artifact.json | grep "L2OutputOracleProxy" | grep -Eo "0x[a-fA-F0-9]+") \
--portal-address=$(cat ./deployer/artifact.json | grep -w "OptimismPortal" | grep -Eo "0x[a-fA-F0-9]+") \
--portal-address=$(cat ./deployer/artifact.json | grep -w "OptimismPortalProxy" | grep -Eo "0x[a-fA-F0-9]+") \
--private-key=$GS_PROPOSER_PRIVATE_KEY \
--l1-eth-rpc=$L1_RPC_URL
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