Skip to content

Commit

Permalink
fix(l1xdm): run out of gas when executing transferFrom before storing…
Browse files Browse the repository at this point in the history
… the failedMessages map
  • Loading branch information
0x6e616d committed Oct 1, 2024
1 parent 5994507 commit 134d6c7
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,6 @@ contract L1CrossDomainMessenger is CrossDomainMessenger, OnApprove, ISemver {
// These properties should always hold when the message is first submitted (as
// opposed to being replayed).
assert(!failedMessages[versionedHash]);
if (_value > 0) {
IERC20(_nativeTokenAddress).safeTransferFrom(address(portal), address(this), _value);
}
} else {
require(failedMessages[versionedHash], "CrossDomainMessenger: message cannot be replayed");
}
Expand Down
10 changes: 1 addition & 9 deletions packages/tokamak/contracts-bedrock/src/L1/OptimismPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,7 @@ contract OptimismPortal is Initializable, ResourceMetering, OnApprove, ISemver {
// Set the l2Sender so contracts know who triggered this withdrawal on L2.
l2Sender = _tx.sender;
if (_tx.value != 0) {
if (_tx.data.length != 0) {
IERC20(_nativeTokenAddress).approve(_tx.target, _tx.value);
} else {
IERC20(_nativeTokenAddress).safeTransfer(_tx.target, _tx.value);
}
IERC20(_nativeTokenAddress).safeTransfer(_tx.target, _tx.value);
}

// Trigger the call to the target contract. We use a custom low level method
Expand All @@ -460,10 +456,6 @@ contract OptimismPortal is Initializable, ResourceMetering, OnApprove, ISemver {
success = true;
}

// Reset approval after a call
if (_tx.data.length != 0 && _tx.value != 0) {
IERC20(_nativeTokenAddress).approve(_tx.target, 0);
}

// Reset the l2Sender back to the default value.
l2Sender = Constants.DEFAULT_L2_SENDER;
Expand Down
11 changes: 1 addition & 10 deletions packages/tokamak/contracts-bedrock/src/L1/OptimismPortal2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,7 @@ contract OptimismPortal2 is Initializable, ResourceMetering, OnApprove, ISemver
l2Sender = _tx.sender;

if (_tx.value != 0) {
if (_tx.data.length != 0) {
IERC20(_nativeTokenAddress).approve(_tx.target, _tx.value);
} else {
IERC20(_nativeTokenAddress).safeTransfer(_tx.target, _tx.value);
}
IERC20(_nativeTokenAddress).safeTransfer(_tx.target, _tx.value);
}

// Trigger the call to the target contract. We use a custom low level method
Expand All @@ -408,11 +404,6 @@ contract OptimismPortal2 is Initializable, ResourceMetering, OnApprove, ISemver
success = true;
}

// Reset approval after a call
if (_tx.data.length != 0 && _tx.value != 0) {
IERC20(_nativeTokenAddress).approve(_tx.target, 0);
}

// Reset the l2Sender back to the default value.
l2Sender = Constants.DEFAULT_L2_SENDER;

Expand Down

0 comments on commit 134d6c7

Please sign in to comment.