Skip to content

Optimizing Variable Initialization to Save Gas#1742

Open
mingbaile wants to merge 2 commits intosphinx-labs:mainfrom
mingbaile:patch-1
Open

Optimizing Variable Initialization to Save Gas#1742
mingbaile wants to merge 2 commits intosphinx-labs:mainfrom
mingbaile:patch-1

Conversation

@mingbaile
Copy link

Hi, We are a research group specializing in programming languages and software engineering. We recently studied inconsistent state update vulnerabilities in Solidity and are developing a tool to detect such issues.

After testing our prototype on your repository, we found some state variables that have never been updated, suggesting they might be missing updates or could be optimized for gas efficiency. Would you find our results useful?

These modifiers save gas by embedding values directly into the bytecode instead of using storage. The key difference:
constant: Set at compile time, no runtime cost.
immutable: Assigned in the constructor, slightly more gas usage.
(More details)

Potential Optimizations: In your repository, the following state variables might need attention. If they are meant to remain unchanged, using constant or immutable can optimize gas:

BridgeFunds.s.sol
State variable: dstGasAmount, bnbTestnetAmount, gnosisChiadoAmount , avaxAmount , ftmAmount

uint256 dstGasAmount = 200_000;
uint256 bnbTestnetAmount = 0; // 1 BNBT
uint256 gnosisChiadoAmount = 0; // 2 XDAI
uint256 avaxAmount = 150 * (10 ** 18);
uint256 ftmAmount = 1000 * (10 ** 18);

Thanks for your time! Does this modification seem appropriate to you?

@CLAassistant
Copy link

CLAassistant commented Mar 10, 2025

CLA assistant check
All committers have signed the CLA.

@mergify
Copy link
Contributor

mergify bot commented Mar 10, 2025

This PR changes implementation code, but doesn't include a changeset. Did you forget to add one?

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.

2 participants