crates/lint/docs/asm-keccak256.md
Severity: Gas
ID: asm-keccak256
Flags calls to the high-level keccak256(...) builtin that can be cheaply rewritten with inline
assembly.
Reports keccak256(arg) calls and (when possible) emits a fix suggestion that uses inline
assembly to compute the hash directly, avoiding the overhead of the high-level call.
The high-level keccak256 call performs additional memory management and ABI encoding compared
to a direct keccak256(ptr, len) opcode invocation. In hot paths the difference is visible in
gas reports.
bytes32 h = keccak256(abi.encodePacked(a, b));
bytes32 h;
assembly ("memory-safe") {
let m := mload(0x40)
mstore(m, a)
mstore(add(m, 0x20), b)
h := keccak256(m, 0x40)
}
This is a Gas-severity lint and is not applied to test or script files.