Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static analysis fixes #1147

Merged
merged 21 commits into from
Jul 16, 2024
Merged

Static analysis fixes #1147

merged 21 commits into from
Jul 16, 2024

Conversation

RensR
Copy link
Collaborator

@RensR RensR commented Jul 5, 2024

This PR addresses various static analysis findings, mostly to reduce gas and contract bytecode size. Both before and after use 3600 optimizations. Due to the saves space in the onRamp we can bump the number of optimizations.

Each commit addresses a different change, and each commit contains the gas snapshot to illustrate the impact of that particular change.

Before

| EVM2EVMMultiOffRamp             | 24.665    | -0.089      |
| EVM2EVMMultiOnRamp              | 20.885    | 3.691       |
| EVM2EVMOffRamp                  | 23.092    | 1.484       |
| EVM2EVMOnRamp                   | 24.432    | 0.144       |

2E:test_E2E_3MessagesSuccess_gas() (gas: 1.104.821)
MultiRampsE2E:test_E2E_3MessagesSuccess_gas() (gas: 1.424.394)

After

| EVM2EVMMultiOffRamp             | 24.538    | 0.038       |
| EVM2EVMMultiOnRamp              | 20.841    | 3.735       |
| EVM2EVMOffRamp                  | 22.968    | 1.608       |
| EVM2EVMOnRamp                   | 24.351    | 0.225       |

E2E:test_E2E_3MessagesSuccess_gas() (gas: 1.102.679)
MultiRampsE2E:test_E2E_3MessagesSuccess_gas() (gas: 1.422.669)

note: comment slightly outdated since the last merge. Overall diff should still be the same

@@ -818,8 +832,8 @@ contract EVM2EVMMultiOffRamp is ITypeAndVersion, MultiOCR3Base {
// We call the pool with exact gas to increase resistance against malicious tokens or token pools.
// We protects against return data bombs by capping the return data size at MAX_RET_BYTES.
(bool success, bytes memory returnData,) = CallWithExactGas._callWithExactGasSafeReturnData(
abi.encodeWithSelector(
IPoolV1.releaseOrMint.selector,
abi.encodeCall(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saves gas AND adds type safety, no brainer

@@ -38,7 +38,7 @@ contract EVM2EVMOffRamp is IAny2EVMOffRamp, AggregateRateLimiter, ITypeAndVersio
error AlreadyExecuted(uint64 sequenceNumber);
error ZeroAddressNotAllowed();
error CommitStoreAlreadyInUse();
error ExecutionError(bytes error);
error ExecutionError(bytes err);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove shadowing the error type

@@ -5,7 +5,7 @@ import {Internal} from "../../libraries/Internal.sol";

// MessageHasher is a contract that provides a function to hash an EVM2EVMMessage.
contract MessageHasher {
function hash(Internal.EVM2EVMMessage memory msg, bytes32 metadataHash) public pure returns (bytes32) {
return Internal._hash(msg, metadataHash);
function hash(Internal.EVM2EVMMessage memory message, bytes32 metadataHash) public pure returns (bytes32) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove shadowing msg

Copy link
Contributor

github-actions bot commented Jul 5, 2024

LCOV of commit 17fdce9 during Solidity Foundry #6582

Summary coverage rate:
  lines......: 98.7% (1851 of 1876 lines)
  functions..: 96.3% (341 of 354 functions)
  branches...: 90.3% (791 of 876 branches)

Files changed coverage rate: n/a

# Conflicts:
#	contracts/gas-snapshots/ccip.gas-snapshot
#	contracts/scripts/native_solc_compile_all_ccip
#	contracts/src/v0.8/ccip/libraries/Internal.sol
#	contracts/src/v0.8/ccip/offRamp/EVM2EVMMultiOffRamp.sol
#	contracts/src/v0.8/ccip/onRamp/EVM2EVMMultiOnRamp.sol
#	contracts/src/v0.8/ccip/test/helpers/MessageHasher.sol
#	core/gethwrappers/ccip/generated/evm_2_evm_multi_offramp/evm_2_evm_multi_offramp.go
#	core/gethwrappers/ccip/generated/evm_2_evm_multi_onramp/evm_2_evm_multi_onramp.go
#	core/gethwrappers/ccip/generated/message_hasher/message_hasher.go
#	core/gethwrappers/ccip/generation/generated-wrapper-dependency-versions-do-not-edit.txt
# Conflicts:
#	contracts/gas-snapshots/ccip.gas-snapshot
#	contracts/scripts/native_solc_compile_all_ccip
#	contracts/src/v0.8/ccip/libraries/Internal.sol
#	contracts/src/v0.8/ccip/offRamp/EVM2EVMMultiOffRamp.sol
#	contracts/src/v0.8/ccip/onRamp/EVM2EVMMultiOnRamp.sol
#	contracts/src/v0.8/ccip/test/helpers/MessageHasher.sol
#	core/gethwrappers/ccip/generated/evm_2_evm_multi_offramp/evm_2_evm_multi_offramp.go
#	core/gethwrappers/ccip/generated/evm_2_evm_multi_onramp/evm_2_evm_multi_onramp.go
#	core/gethwrappers/ccip/generated/message_hasher/message_hasher.go
#	core/gethwrappers/ccip/generation/generated-wrapper-dependency-versions-do-not-edit.txt
@RensR RensR marked this pull request as ready for review July 15, 2024 11:13
@RensR RensR requested review from makramkd, RayXpub and a team as code owners July 15, 2024 11:13
@@ -284,8 +284,10 @@ contract EVM2EVMMultiOffRamp is ITypeAndVersion, MultiOCR3Base {
for (uint256 msgIndex = 0; msgIndex < numMsgs; ++msgIndex) {
uint256 newLimit = msgGasLimitOverrides[msgIndex];
// Checks to ensure message cannot be executed with less gas than specified.
if (newLimit != 0 && newLimit < report.messages[msgIndex].gasLimit) {
revert InvalidManualExecutionGasLimit(report.sourceChainSelector, msgIndex, newLimit);
if (newLimit != 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: are the gas / contract size changes significant for splitting if statements? I find a && b && c much more readable in most cases

@RensR RensR merged commit f77e6f0 into ccip-develop Jul 16, 2024
107 checks passed
@RensR RensR deleted the static-analysis branch July 16, 2024 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants