Skip to content

Commit

Permalink
Merge branch 'main' into gas-optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
reednaa authored Feb 29, 2024
2 parents 6b76e10 + fab0ba6 commit 3564831
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 0 additions & 1 deletion evm/script/config/config_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"factory": "0x0f169fa42b47651E1F95f7cE9F2Ae1E44DA2671d",
"volatile_mathlib": "0xBFEDF53f4FEfB0f520E5570355e732bc4c4C428e",
"volatile_template": "0x463788aC702F3e000EB917417d8b49a972533854"
},
"registry": {
"describer": "0x02a52682aa3634734535bf761800492C9b05A6B0",
"describer_registry": "0x85f7279F9434Ad9c0111042769d661D150b15452",
Expand Down
7 changes: 6 additions & 1 deletion evm/src/CatalystVaultCommon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,20 @@ abstract contract CatalystVaultCommon is
// This call provides re-entry protection against re-entering this call. Otherwise, this call can always be called.
address fallbackAddress = _releaseAssetEscrow(sendAssetHash, escrowAmount, escrowToken); // Only reverts for missing escrow,

// We are going to make a low-level call. It may revert (see comment below) but it should not revert if it runs out of gas (that should be raised). As such, get the current gas in the contract.
uint256 gasLeftBeforeCall = gasleft();

// Make a low level call such that the transfer never fails. This is important for tokens
// that use block lists.
// This also implies that if you get blacklisted between when you initiated the swap and the swap failed, you
// would lose the tokens.
bytes memory payload = abi.encodeWithSignature("transfer(address,uint256)", fallbackAddress, escrowAmount);
assembly ("memory-safe") {
let success := call(gas(), escrowToken, 0, add(payload, 0x20), mload(payload), 0, 0)
let success := call(0x8000000000000000000000000000000000000000000000000000000000000000, escrowToken, 0, add(payload, 0x20), mload(payload), 0, 0)
// SafeTransferLib.safeTransferFrom(escrowToken, fallbackAddress, escrowAmount);
}
// Check that the call didn't use all of its gas.
if(gasleft() < gasLeftBeforeCall * 1 / 63) revert NotEnoughGas();

emit SendAssetFailure( // Never reverts.
channelId,
Expand Down
3 changes: 2 additions & 1 deletion evm/src/interfaces/ICatalystV1VaultErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ error ReturnInsufficient(uint256 result, uint256 minimum); // 24557f0
error VaultNotConnected(); // 2c64c1b
error WithdrawRatioNotZero(); // b8003bf
error UnusedUnitsAfterWithdrawal(uint256 Units); // 0289311
error EscrowAlreadyExists(); // ed77877
error EscrowAlreadyExists(); // ed77877
error NotEnoughGas(); // dd629f86

0 comments on commit 3564831

Please sign in to comment.