code-423n4 / 2022-06-putty-findings

5 stars 0 forks source link

Gas Optimizations #392

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

[Gas - 01] - Use Custom Errors

Instead of using error strings, to reduce deployment and runtime cost, you should use Custom Errors: see https://blog.soliditylang.org/2021/04/21/custom-errors/. This would save both deployment and runtime cost.

[Gas - 02] - Directly settle short orders in exercise

In exercise, why not directly settling the deal ?

The gas overhead would be minimal has the transfers are already done, and you’d save a ton of gas in the overall flow. Instead of doing a 2 time transfer msg.sender -> contract during exercise and then contract -> maker or taker during withdraw, you could directly do the accounting, burn the position and do the correct transfers in exercise. There would still be a withdraw function, but only for non-exercised options.

Especially as the order is immutable, we already know during exercise than withdraw will be called, so this optimisation is worth doing to me, although it requires some work.