-
Notifications
You must be signed in to change notification settings - Fork 65
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
Gas Consumption Analysis on Bridge Solidity Contracts #842
Comments
i propose to write such a function. the test should fail, based on some fixed inputs that the gas is not cray high. this should be feasible, because the test is deterministic. it would be a control mechanism that checks that no high-fee consuming functionality is introduced by error |
The cost of So overall, if I am correct the cost of hashing 1K bytes, is 30 + (6 * 1000/32) = 217.5gas (a word in the EVM is 32bytes, 256bits). In contrast writing to permanent storage is very expensive. It is 20000 gas per word. So the following lines bridgeTransfers[bridgeTransferId] = BridgeTransfer({
amount: moveAmount,
originator: originator,
recipient: recipient,
hashLock: hashLock,
timeLock: block.timestamp + initiatorTimeLockDuration,
state: MessageState.INITIALIZED
}); probably incur ~100K gas for the write to storage. |
You can see that the struct storage calls are the most expensive ones. |
@0xPrimata Thanks a lot for this breakdown. The minimum gas cost of any transaction is ~21700 gas units. For reference, gasNow, at 4pm Sydney time Nov 13, 130K gas units cost ~$10 for a fast Tx, and $6 for a standard. |
initiateBridgeTransfer
is consuming around 400k units of gas, this is far too high for what the function is doing.There could be several culprits, the struct and its size (fields). The way we operate on the mapping
bridgeTransferIds
or, something else.Do an analysis of gas consumption on the solidity contracts for the bridge in main. You can do this using
forge test --gas-report
.My suspicion is this line causing the high gas cosumption
Too much salt, if we take param number down to three, it should be several degrees less consuming. We need nonce tho as this garantees uniqueness of
bridgeTransferId
.On this issue, paste your findings and suggest what gas optimisations can be made.
The text was updated successfully, but these errors were encountered: