We here show how infeasible it is for convex optimization to be implemented on even the most performant centralized blockchains.

Great—let’s lock in the robust fixed-point model (full-precision mulDiv), then show the math and totals for several “standard finance” sizes.

Assume a typical on-chain convex QP solved by gradient descent in fixed-point, with:

$$ \min_{x\in\mathbb{R}^n} f(x) = \tfrac12 x^\top Q x + c^\top x $$

I’ll show one full worked example, then a table of other instances.


1) Cost model

From the per-iteration operation count (matrix-vector multiply ($Qx)$, add (c), step ($x\leftarrow x-\alpha(Qx+c))$), the pre-fudge per-iteration gas with mulDiv is:

$\boxed{g_{\text{iter, pre}}(n) \approx 153,n^2 + 174,n}$

Where that comes from:

Implementation overhead (stack moves, bound checks, Solidity codegen): Plain Solidity 0.8: multiply by 2.5

$g_{\text{iter}}^{\text{eff}}(n) ;=; \text{fudge}\cdot(153n^2+174n)$

Total compute gas for $(T)$ iterations:

$G_{\text{compute}} ;=; T\cdot g_{\text{iter}}^{\text{eff}}(n)$