tokamak-network / L2-Assets-Migration

3 stars 4 forks source link

Gas optimization in getForcePosition Function #21

Closed NegruGeorge closed 1 month ago

NegruGeorge commented 1 month ago

Describe the bug In the getForcePosition function of the UpgradeL1Bridge contract, the _key parameter is defined as memory but it can be more efficiently defined as calldata.

Affected Function:

function getForcePosition(string memory _key) external view returns (address)

Configuration

Impact Inefficient Memory Usage: Using memory for the _key parameter consumes more gas than necessary. calldata is more efficient for external function parameters, especially when dealing with strings.

Recommendation Change the _key parameter from memory to calldata to optimize gas usage.

Change the function signature to:

function getForcePosition(string calldata _key) external view returns (address)

Exploit Scenario

Demo

DevUreak commented 1 month ago

I will test and apply it in the next update. Thank you.

DevUreak commented 1 month ago

fixed ce5fb7327707d67313a9f236b813abac6d5053e5 thanks!