|
7 | 7 | ;; ;; |
8 | 8 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
9 | 9 |
|
10 | | -(defun (prc-modexp-pricing---standard-precondition) IS_MODEXP_PRICING) |
| 10 | + |
| 11 | +(defconst |
| 12 | + ROFF___MODEXP_PRICING___R@C_ISZERO_CHECK 0 |
| 13 | + ROFF___MODEXP_PRICING___EXPONENT_LOG_ISZERO_CHECK 1 |
| 14 | + ROFF___MODEXP_PRICING___CEILING_OF_MAX_OVER_8 2 |
| 15 | + ROFF___MODEXP_PRICING___MAX_VS_32 3 |
| 16 | + ROFF___MODEXP_PRICING___RAW_COST_VS_MIN_COST 4 |
| 17 | + ROFF___MODEXP_PRICING___CALLEE_GAS_VS_PRECOMPILE_COST 5 |
| 18 | + ) |
| 19 | + |
| 20 | + |
| 21 | +(defun (prc-modexp-pricing---standard-precondition) (* (assumption---fresh-new-stamp) IS_MODEXP_PRICING)) |
11 | 22 | (defun (prc-modexp-pricing---exponent-log) [DATA 6]) |
12 | | -(defun (prc-modexp-pricing---max-xbs-ybs) [DATA 7]) |
13 | | -(defun (prc-modexp-pricing---exponent-log-is-zero) (next OUTGOING_RES_LO)) |
14 | | -(defun (prc-modexp-pricing---f-of-max) (* (shift OUTGOING_RES_LO 2) (shift OUTGOING_RES_LO 2))) |
15 | | -(defun (prc-modexp-pricing---big-quotient) (shift OUTGOING_RES_LO 3)) |
16 | | -(defun (prc-modexp-pricing---big-quotient_LT_GAS_CONST_MODEXP) (shift OUTGOING_RES_LO 4)) |
17 | | -(defun (prc-modexp-pricing---big-numerator) (if-zero (prc-modexp-pricing---exponent-log-is-zero) |
18 | | - (* (prc-modexp-pricing---f-of-max) (prc-modexp-pricing---exponent-log)) |
19 | | - (prc-modexp-pricing---f-of-max))) |
20 | | -(defun (prc-modexp-pricing---precompile-cost) (if-zero (prc-modexp-pricing---big-quotient_LT_GAS_CONST_MODEXP) |
21 | | - (prc-modexp-pricing---big-quotient) |
22 | | - GAS_CONST_MODEXP)) |
23 | | - |
24 | | -(defconstraint prc-modexp-pricing---check--is-zero (:guard (* (assumption---fresh-new-stamp) (prc-modexp-pricing---standard-precondition))) |
25 | | - (call-to-ISZERO 0 0 (prc---r@c))) |
26 | | - |
27 | | -(defconstraint prc-modexp-pricing---check-exponent-log-is-zero (:guard (* (assumption---fresh-new-stamp) (prc-modexp-pricing---standard-precondition))) |
28 | | - (call-to-ISZERO 1 0 (prc-modexp-pricing---exponent-log))) |
29 | | - |
30 | | -(defconstraint prc-modexp-pricing---div-max-xbs-ybs-plus-7-by-8 (:guard (* (assumption---fresh-new-stamp) (prc-modexp-pricing---standard-precondition))) |
31 | | - (call-to-DIV 2 |
32 | | - 0 |
33 | | - (+ (prc-modexp-pricing---max-xbs-ybs) 7) |
34 | | - 0 |
35 | | - 8)) |
36 | | - |
37 | | -(defconstraint prc-modexp-pricing---div-big-numerator-by-quaddivisor (:guard (* (assumption---fresh-new-stamp) (prc-modexp-pricing---standard-precondition))) |
38 | | - (call-to-DIV 3 0 (prc-modexp-pricing---big-numerator) 0 G_QUADDIVISOR)) |
39 | | - |
40 | | -(defconstraint prc-modexp-pricing---compare-big-quotient-against-GAS_CONST_MODEXP (:guard (* (assumption---fresh-new-stamp) (prc-modexp-pricing---standard-precondition))) |
41 | | - (call-to-LT 4 0 (prc-modexp-pricing---big-quotient) 0 GAS_CONST_MODEXP)) |
42 | | - |
43 | | -(defconstraint prc-modexp-pricing---compare-call-gas-against-precompile-cost (:guard (* (assumption---fresh-new-stamp) (prc-modexp-pricing---standard-precondition))) |
44 | | - (call-to-LT 5 0 (prc---callee-gas) 0 (prc-modexp-pricing---precompile-cost))) |
45 | | - |
46 | | -(defconstraint prc-modexp-pricing---justify-hub-predictions (:guard (* (assumption---fresh-new-stamp) (prc-modexp-pricing---standard-precondition))) |
47 | | - (begin (eq! (prc---ram-success) |
48 | | - (- 1 (shift OUTGOING_RES_LO 5))) |
49 | | - (if-zero (prc---ram-success) |
50 | | - (vanishes! (prc---return-gas)) |
51 | | - (eq! (prc---return-gas) (- (prc---callee-gas) (prc-modexp-pricing---precompile-cost)))) |
52 | | - (eq! (prc---r@c-nonzero) (- 1 OUTGOING_RES_LO)))) |
| 23 | +(defun (prc-modexp-pricing---max-mbs-bbs) [DATA 7]) |
| 24 | +;; "" |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 29 | +;; ;; |
| 30 | +;; row i + 0: [email protected]() check ;; |
| 31 | +;; ;; |
| 32 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 33 | + |
| 34 | +(defconstraint prc-modexp-pricing---r@c-iszero-check |
| 35 | + (:guard (prc-modexp-pricing---standard-precondition)) |
| 36 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 37 | + (call-to-ISZERO ROFF___MODEXP_PRICING___R@C_ISZERO_CHECK |
| 38 | + 0 |
| 39 | + (prc---r@c) |
| 40 | + )) |
| 41 | + |
| 42 | +(defun (prc-modex-pricing---r@c-is-zero) (shift OUTGOING_RES_LO ROFF___MODEXP_PRICING___R@C_ISZERO_CHECK)) |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 47 | +;; ;; |
| 48 | +;; row i + 1: exponentLog.isZero() check ;; |
| 49 | +;; ;; |
| 50 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 51 | + |
| 52 | + |
| 53 | +(defconstraint prc-modexp-pricing---check-exponent-log-is-zero |
| 54 | + (:guard (prc-modexp-pricing---standard-precondition)) |
| 55 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 56 | + (call-to-ISZERO ROFF___MODEXP_PRICING___EXPONENT_LOG_ISZERO_CHECK |
| 57 | + 0 |
| 58 | + (prc-modexp-pricing---exponent-log) |
| 59 | + )) |
| 60 | + |
| 61 | +(defun (prc-modexp-pricing---exponent-log-is-zero) (shift OUTGOING_RES_LO ROFF___MODEXP_PRICING___EXPONENT_LOG_ISZERO_CHECK)) |
| 62 | + |
| 63 | + |
| 64 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 65 | +;; ;; |
| 66 | +;; row i + 2: ⌈ max(mbs, bbs) / 8 ⌉ compututation ;; |
| 67 | +;; ;; |
| 68 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +(defconstraint prc-modexp-pricing---computing-ceiling-of-max-mbs-bbs-over-8 |
| 73 | + (:guard (prc-modexp-pricing---standard-precondition)) |
| 74 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 75 | + (call-to-DIV ROFF___MODEXP_PRICING___CEILING_OF_MAX_OVER_8 |
| 76 | + 0 |
| 77 | + (+ (prc-modexp-pricing---max-mbs-bbs) 7) |
| 78 | + 0 |
| 79 | + 8 |
| 80 | + )) |
| 81 | + |
| 82 | +(defun (prc-modexp-pricing---ceiling-of-max-over-8) (shift OUTGOING_RES_LO ROFF___MODEXP_PRICING___CEILING_OF_MAX_OVER_8)) |
| 83 | + |
| 84 | + |
| 85 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 86 | +;; ;; |
| 87 | +;; row i + 3: comparing max(mbs, bbs) and 32 ;; |
| 88 | +;; ;; |
| 89 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 90 | + |
| 91 | + |
| 92 | +(defconstraint prc-modexp-pricing---max-mbs-bbs-vs-32 |
| 93 | + (:guard (prc-modexp-pricing---standard-precondition)) |
| 94 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 95 | + (call-to-LT ROFF___MODEXP_PRICING___MAX_VS_32 |
| 96 | + 0 |
| 97 | + WORD_SIZE |
| 98 | + 0 |
| 99 | + (prc-modexp-pricing---max-mbs-bbs) |
| 100 | + )) |
| 101 | + |
| 102 | +(defun (prc-modexp-pricing---word-cost-dominates) (shift OUTGOING_RES_LO ROFF___MODEXP_PRICING___MAX_VS_32)) |
| 103 | +(defun (prc-modexp-pricing---f-of-max) (* (prc-modexp-pricing---ceiling-of-max-over-8) |
| 104 | + (prc-modexp-pricing---ceiling-of-max-over-8))) |
| 105 | +(defun (prc-modexp-pricing---multiplication-complexity) (if-zero (force-bin (prc-modexp-pricing---word-cost-dominates)) |
| 106 | + 16 |
| 107 | + (* 2 (prc-modexp-pricing---f-of-max)))) |
| 108 | +(defun (prc-modexp-pricing---iteration-count-or-1) (if-zero (force-bin (prc-modexp-pricing---exponent-log-is-zero)) |
| 109 | + (prc-modexp-pricing---exponent-log) |
| 110 | + 1)) |
| 111 | +(defun (prc-modexp-pricing---raw-cost) (* (prc-modexp-pricing---multiplication-complexity) |
| 112 | + (prc-modexp-pricing---iteration-count-or-1))) |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 117 | +;; ;; |
| 118 | +;; row i + 4: comparing raw_price to 500 ;; |
| 119 | +;; ;; |
| 120 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +(defconstraint prc-modexp-pricing---compare-raw-cost-against-GAS_CONST_MODEXP-of-EIP-7823 |
| 125 | + (:guard (prc-modexp-pricing---standard-precondition)) |
| 126 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 127 | + (call-to-LT ROFF___MODEXP_PRICING___RAW_COST_VS_MIN_COST |
| 128 | + 0 |
| 129 | + (prc-modexp-pricing---raw-cost) |
| 130 | + 0 |
| 131 | + GAS_CONST_MODEXP_EIP_7823 |
| 132 | + )) |
| 133 | + |
| 134 | +(defun (prc-modexp-pricing---raw-cost-LT-min-cost) (force-bin (shift OUTGOING_RES_LO ROFF___MODEXP_PRICING___RAW_COST_VS_MIN_COST))) |
| 135 | +(defun (prc-modexp-pricing---precompile-cost) (if-zero (prc-modexp-pricing---raw-cost-LT-min-cost) |
| 136 | + ;; raw_cost_LT_min_cost ≡ faux |
| 137 | + (prc-modexp-pricing---raw-cost) |
| 138 | + ;; raw_cost_LT_min_cost ≡ true |
| 139 | + GAS_CONST_MODEXP_EIP_7823)) |
| 140 | + |
| 141 | + |
| 142 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 143 | +;; ;; |
| 144 | +;; row i + 5: comparing callee_gas to precopile_cost ;; |
| 145 | +;; ;; |
| 146 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | +(defconstraint prc-modexp-pricing---compare-call-gas-against-precompile-cost |
| 151 | + (:guard (prc-modexp-pricing---standard-precondition)) |
| 152 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 153 | + (call-to-LT ROFF___MODEXP_PRICING___CALLEE_GAS_VS_PRECOMPILE_COST |
| 154 | + 0 |
| 155 | + (prc---callee-gas) |
| 156 | + 0 |
| 157 | + (prc-modexp-pricing---precompile-cost) |
| 158 | + )) |
| 159 | + |
| 160 | +(defun (prc-modexp-pricing---callee-gas-LT-precompile-cost) (force-bin (shift OUTGOING_RES_LO ROFF___MODEXP_PRICING___CALLEE_GAS_VS_PRECOMPILE_COST))) |
| 161 | + |
| 162 | + |
| 163 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 164 | +;; ;; |
| 165 | +;; justifying HUB predictions ;; |
| 166 | +;; ;; |
| 167 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 168 | + |
| 169 | +(defconstraint prc-modexp-pricing---justify-hub-predictions---ram-success |
| 170 | + (:guard (prc-modexp-pricing---standard-precondition)) |
| 171 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 172 | + (eq! (prc---ram-success) |
| 173 | + (- 1 (prc-modexp-pricing---callee-gas-LT-precompile-cost)) |
| 174 | + )) |
| 175 | + |
| 176 | +(defconstraint prc-modexp-pricing---justify-hub-predictions---return-gas |
| 177 | + (:guard (prc-modexp-pricing---standard-precondition)) |
| 178 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 179 | + (if-zero (force-bin (prc---ram-success)) |
| 180 | + ;; ram_success ≡ faux |
| 181 | + (vanishes! (prc---return-gas)) |
| 182 | + ;; ram_success ≡ true |
| 183 | + (eq! (prc---return-gas) |
| 184 | + (- (prc---callee-gas) |
| 185 | + (prc-modexp-pricing---precompile-cost))) |
| 186 | + )) |
| 187 | + |
| 188 | +(defconstraint prc-modexp-pricing---justify-hub-predictions---r@c-nonzero |
| 189 | + (:guard (prc-modexp-pricing---standard-precondition)) |
| 190 | + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 191 | + (eq! (prc---r@c-nonzero) |
| 192 | + (- 1 (prc-modex-pricing---r@c-is-zero)) |
| 193 | + )) |
53 | 194 |
|
0 commit comments