code-423n4 / 2021-10-ambire-findings

0 stars 0 forks source link

`Zapper.sol#wrapETH()` Use `WETH.deposit` can save some gas #27

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-10-ambire/blob/bc01af4df3f70d1629c4e22a72c19e6a814db70d/contracts/wallet/Zapper.sol#L137-L140

function wrapETH() payable external {
    // TODO: it may be slightly cheaper to call deposit() directly
    payable(WETH).transfer(msg.value);
}

Recommendation

Change to:

interface IWETH {
    function deposit() external payable;
}
function wrapETH() payable external {
    IWETH(WETH).deposit{ value: msg.value }();
}
Ivshti commented 3 years ago

resolved in https://github.com/AmbireTech/adex-protocol-eth/commit/263192503524f9177fe0d52eb68b81feb0fc5e97

GalloDaSballo commented 3 years ago

Since the fallback takes extra logic, using .deposit saves gas. The sponsor has applied the improvement