Skip to content

Conversation

Zodomo
Copy link
Contributor

@Zodomo Zodomo commented Jan 31, 2025

I significantly reduced gas costs for SolverNetInbox's open() function. This was done by storing the OnchainCrossChainOrder struct rather than the complex ResolvedCrossChainOrder struct. Then, in any function that relies on the ResolvedCrossChainOrder, it is resolved again for these functions. The majority of the gas savings were found in open, but all of the other order functions saw gas reductions too. We can likely go way further than this ~20% reduction in costs, but this was what I could squeeze out without any impact to the solver. The interface remains entirely unchanged.

Here are gas reports for the impacted functions:

Preoptimizations:

| src/SolverNetInbox.sol:SolverNetInbox contract |                 |        |        |         |         |
|------------------------------------------------|-----------------|--------|--------|---------|---------|
| Deployment Cost                                | Deployment Size |        |        |         |         |
| 3361901                                        | 15509           |        |        |         |         |
| Function Name                                  | min             | avg    | median | max     | # calls |
| accept                                         | 2471            | 58476  | 67327  | 67327   | 20      |
| cancel                                         | 84258           | 136912 | 172001 | 172001  | 5       |
| claim                                          | 84365           | 84365  | 84365  | 84365   | 1       |
| getOrder                                       | 11624           | 12955  | 12268  | 21810   | 12      |
| markFilled                                     | 92090           | 92103  | 92090  | 92179   | 13      |
| open                                           | 26235           | 807746 | 943293 | 1372890 | 36      |
| reject                                         | 2602            | 109826 | 151691 | 175160  | 7       |
| resolve                                        | 15690           | 15870  | 15690  | 19658   | 40      |
| validate                                       | 1019            | 3791   | 4516   | 5418    | 16      

Postoptimizations:

| src/SolverNetInbox.sol:SolverNetInbox contract |                 |        |        |        |         |
|------------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost                                | Deployment Size |        |        |        |         |
| 3219429                                        | 14850           |        |        |        |         |
| Function Name                                  | min             | avg    | median | max    | # calls |
| accept                                         | 2471            | 106376 | 115264 | 141101 | 20      |
| cancel                                         | 68791           | 121447 | 156538 | 156538 | 5       |
| claim                                          | 68898           | 68898  | 68898  | 68898  | 1       |
| getOrder                                       | 13450           | 16328  | 16708  | 17354  | 12      |
| markFilled                                     | 91696           | 91880  | 91914  | 91914  | 13      |
| open                                           | 25502           | 579554 | 675862 | 990757 | 36      |
| reject                                         | 2602            | 98780  | 136228 | 159697 | 7       |
| resolve                                        | 15942           | 16113  | 15942  | 19711  | 40      |
| validate                                       | 1089            | 3892   | 4604   | 5509   | 16      

issue: #2917

@Zodomo Zodomo self-assigned this Jan 31, 2025
@Zodomo Zodomo requested a review from kevinhalliday as a code owner January 31, 2025 00:08
@Zodomo
Copy link
Contributor Author

Zodomo commented Feb 4, 2025

Closed as this implementation was deprecated by the one in #2954, which achieved far better optimization.

@Zodomo Zodomo closed this Feb 4, 2025
@Zodomo Zodomo deleted the zodomo/sn-gasoptimizations branch February 4, 2025 01:15
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.

1 participant