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

0 stars 0 forks source link

Unchecked math operations #64

Closed code423n4 closed 3 years ago

code423n4 commented 3 years ago

Handle

pauliax

Vulnerability details

Impact

You can use the 'unchecked' keyword to avoid redundant arithmetic checks to save gas when an underflow/overflow cannot happen. E.g. unchecked can be applied here: require(sig.length >= 1, "SignatureValidator: basic sig len"); uint8 modeRaw = uint8(sig[sig.length - 1]);

or here: require(sig.length > 33, "SignatureValidator: wallet sig len");

IERC1271Wallet wallet = IERC1271Wallet(address(uint160(uint256(sig.readBytes32(sig.length - 33))))); sig.trimToSize(sig.length - 33);

Recommended Mitigation Steps

Consider applying unchecked keyword where it can't overflow/underflow.

Ivshti commented 3 years ago

good optimization, thanks!

Ivshti commented 3 years ago

may be a partial duplicate of https://github.com/code-423n4/2021-10-ambire-findings/issues/46 and https://github.com/code-423n4/2021-10-ambire-findings/issues/22

Ivshti commented 3 years ago

resolved in https://github.com/AmbireTech/adex-protocol-eth/commit/d86f7199b39bc52cb88a3d76e2f8f06de10a07e5 and https://github.com/AmbireTech/adex-protocol-eth/commit/67a9bf713e1e21f9d6e5d19dbee1964a2db0fca4

GalloDaSballo commented 3 years ago

Duplicate of #46