Skip to content

Commit

Permalink
Merge pull request #170 from 1inch/audit/astrasec-n2
Browse files Browse the repository at this point in the history
[SC-1387] Use a consistent code style
  • Loading branch information
zZoMROT authored Jan 20, 2025
2 parents 26969f6 + 7c3d100 commit 5085b30
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
24 changes: 11 additions & 13 deletions contracts/libraries/SafeERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ library SafeERC20 {
mstore(add(data, 0x04), from)
mstore(add(data, 0x24), to)
mstore(add(data, 0x44), amount)
success := call(gas(), token, 0, data, 100, 0x0, 0x20)
success := call(gas(), token, 0, data, 0x64, 0x0, 0x20)
if success {
switch returndatasize()
case 0 {
Expand Down Expand Up @@ -167,14 +167,14 @@ library SafeERC20 {
* the caller to make sure that the higher 96 bits of the `to` parameter are clean.
* @param token The IERC20 token contract from which the tokens will be transferred.
* @param to The address to which the tokens will be transferred.
* @param value The amount of tokens to transfer.
* @param amount The amount of tokens to transfer.
*/
function safeTransfer(
IERC20 token,
address to,
uint256 value
uint256 amount
) internal {
if (!_makeCall(token, token.transfer.selector, to, value)) {
if (!_makeCall(token, token.transfer.selector, to, amount)) {
revert SafeTransferFailed();
}
}
Expand Down Expand Up @@ -442,15 +442,13 @@ library SafeERC20 {
* @param amount The amount of Ether to deposit into the IWETH contract.
*/
function safeDeposit(IWETH weth, uint256 amount) internal {
if (amount > 0) {
bytes4 selector = IWETH.deposit.selector;
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
mstore(0, selector)
if iszero(call(gas(), weth, amount, 0, 4, 0, 0)) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
bytes4 selector = IWETH.deposit.selector;
assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
mstore(0, selector)
if iszero(call(gas(), weth, amount, 0, 4, 0, 0)) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1inch/solidity-utils",
"version": "6.3.0",
"version": "6.3.1",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"exports": {
Expand Down
12 changes: 0 additions & 12 deletions test/contracts/SafestERC20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,6 @@ describe('SafeERC20', function () {
}
});

it('should be cheap on deposit 0 tokens', async function () {
const { weth, wrapper } = await loadFixture(deployWrapperWETH);
const tx = (await trackReceivedTokenAndTx(ethers.provider, weth, await wrapper.getAddress(), () =>
wrapper.deposit(),
))[1] as ContractTransactionReceipt;
if (hre.__SOLIDITY_COVERAGE_RUNNING === undefined) {
expect(await countInstructions(ethers.provider, tx.hash, ['STATICCALL', 'CALL', 'MSTORE', 'MLOAD', 'SSTORE', 'SLOAD'])).to.be.deep.equal([
0, 0, 1, 0, 0, 1,
]);
}
});

it('should withdrawal tokens on withdraw', async function () {
const { weth, wrapper } = await loadFixture(deployWrapperWETHAndDeposit);
const [received] = await trackReceivedTokenAndTx(ethers.provider, weth, await wrapper.getAddress(), () =>
Expand Down

0 comments on commit 5085b30

Please sign in to comment.