code-423n4 / 2021-12-amun-findings

0 stars 0 forks source link

`PolygonERC20Wrapper.sol` Avoid unnecessary storage operations can save gas #219

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-12-amun/blob/98f6e2ff91f5fcebc0489f5871183566feaec307/contracts/bridge/contracts/amunBasketBridge/PolygonERC20Wrapper.sol#L67-L68

_mint(_msgSender(), amount);
_burn(_msgSender(), amount);

PolygonERC20Wrapper.sol#withdraw() and PolygonERC20Wrapper.sol#withdrawTo() will call _mint and _burn with the same amount, which will SLOAD and SSTORE _balances[account] and _totalSupply multiple times, but resting to the original state at the end.

We believe it's not gas efficient.

Recommendation

Consider emitting Transfer events directly.

loki-sama commented 2 years ago

This is do to how polygon bridge works

0xleastwood commented 2 years ago

This is intended behaviour, marking invalid.