Omniscia Xcaliswap Audit
Base64 Code Style Findings
Base64 Code Style Findings
B46-01C: Sub-Optimal Assembly Block
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | Base64.sol:L49, L51, L53, L55 |
Description:
The Base64
implementation by Brecht Devos utilized in the codebase is outdated and sub-optimal as it utilizes an mstore
and shr
instruction to store 1 byte (8 bits) instead of using the mstore8
instruction directly.
Example:
contracts/periphery/libraries/Base64.sol
37// run over the input, 3 bytes at a time38for {39
40} lt(dataPtr, endPtr) {41
42} {43 dataPtr := add(dataPtr, 3)44
45 // read 3 bytes46 let input := mload(dataPtr)47
48 // write 4 characters49 mstore(resultPtr, shl(248, mload(add(tablePtr, and(shr(18, input), 0x3F)))))50 resultPtr := add(resultPtr, 1)51 mstore(resultPtr, shl(248, mload(add(tablePtr, and(shr(12, input), 0x3F)))))52 resultPtr := add(resultPtr, 1)53 mstore(resultPtr, shl(248, mload(add(tablePtr, and(shr(6, input), 0x3F)))))54 resultPtr := add(resultPtr, 1)55 mstore(resultPtr, shl(248, mload(add(tablePtr, and(input, 0x3F)))))56 resultPtr := add(resultPtr, 1)57}
Recommendation:
We advise the statements to be updated according to the latest version of Brecht Devos' Base64
library to ensure the codebase is optimal.
Alleviation:
The Xcaliswap team evaluated this exhibit but opted not to apply any changes for it in the current iteration of the protocol.