Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
status/proof mapping packing [SLT-186] #3173
status/proof mapping packing [SLT-186] #3173
Changes from 1 commit
1348e63
1c5dd7d
5045835
7f5c260
dc2dab5
048a66f
ddc1f1f
582941f
ef3d1f7
2f64c94
488e378
fbd7043
78c84a8
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimize Getter Function Return Type
In the
bridgeStatuses
function, you're returning aBridgeStatus
enum. While enums are convenient, returning them can be less gas-efficient. Consider returning auint8
instead, which represents the underlying value of the enum and reduces gas consumption.Consider this change:
Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid Returning Structs Directly from Public Functions
The
bridgeProofs
function returns aBridgeProof
struct. Returning structs can be expensive in terms of gas and may expose internal implementation details. Instead, consider returning individual fields of the struct.Refactor the function to return individual fields:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
❗ Unexpected Status Transition Detected
The status transition from
REQUESTED
toREFUNDED
is not defined in the expected state machine (REQUESTED
→RELAYER_PROVED
→RELAYER_CLAIMED
). Please review the state transitions to ensure they adhere to the intended workflow.Analysis chain
Confirm Proper Status Transition and Proof Assignment
Before updating the status to
RELAYER_PROVED
and assigning the proof, ensure that the transition fromREQUESTED
toRELAYER_PROVED
is valid according to your state machine. This prevents invalid status transitions.Run the following script to verify status transitions:
Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 109
Script:
Length of output: 1552
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for Uninitialized Proof Before Access
When accessing
bridgeTxDetails[transactionId].proof
, ensure that the proof exists to prevent accessing uninitialized memory, which could lead to incorrect data retrieval.Add a check for proof initialization:
BridgeProof memory proof = bridgeTxDetails[transactionId].proof; +if (proof.relayer == address(0)) revert ProofNotInitialized();
Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure
BridgeProof
type is properly defined or importedThe
BridgeProof
type used in theBridgeTxDetails
struct is not defined within this interface. Please verify thatBridgeProof
is properly defined or imported from another contract or interface to prevent compilation errors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not have a desired effect of saving the gas on reads and writes, as the internal composition of the struct takes more than a single storage slot (256 bits). We don't export a gas report as of now, but in this case it's possible to generate using
forge t --mc FastBridgeV2SrcTest --nmt revert --gas-report
.FastBridgeV2SrcTest
test contract gives us the overview for the source chain-related functions--nmt revert
excludes test functions having a word "revert" in the name, which makes the report more useful (revert cases in general consume less gas, and thus need to be filtered)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This are the results when run on master, prior to this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this are the results after this PR changes:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To gain the performance in gas consumption, the
BridgeTxDetails
needs to fit within 256 bits:BridgeStatus
enum is equivalent touint8
address relayer
takes 160 bitsThis is an opportunity to follow the suit of #3170 and also store the block number, when the prove happened. This could be useful for some of the Relayer implementations. This will require using up to 88 bits for both block number and timestamp, which is more than enough for practical purposes.