@@ -11,6 +11,8 @@ import (
1111
1212 "github.com/ethereum/go-ethereum/arbitrum/multigas"
1313 "github.com/ethereum/go-ethereum/params"
14+
15+ "github.com/offchainlabs/nitro/util/arbmath"
1416)
1517
1618func toGwei (wei * big.Int ) string {
@@ -126,6 +128,62 @@ func TestCompareSingleGasConstraintsPricingModelWithMultiGasConstraints(t *testi
126128 }
127129}
128130
131+ func TestCalcMultiGasConstraintsExponents (t * testing.T ) {
132+ pricing := PricingForTest (t )
133+ pricing .ArbosVersion = ArbosMultiGasConstraintsVersion
134+
135+ Require (t , pricing .AddMultiGasConstraint (
136+ 100000 ,
137+ 10 ,
138+ 20000 ,
139+ map [uint8 ]uint64 {
140+ uint8 (multigas .ResourceKindComputation ): 1 ,
141+ uint8 (multigas .ResourceKindStorageAccess ): 2 ,
142+ },
143+ ))
144+ Require (t , pricing .AddMultiGasConstraint (
145+ 50000 ,
146+ 5 ,
147+ 15000 ,
148+ map [uint8 ]uint64 {
149+ uint8 (multigas .ResourceKindStorageGrowth ): 1 ,
150+ },
151+ ))
152+
153+ exponents , err := pricing .CalcMultiGasConstraintsExponents ()
154+ Require (t , err )
155+
156+ // From constraint 1:
157+ // exp_comp = floor(20000 * 1 * 10000 / (10 * 100000 * 3)) = 66
158+ // exp_store = floor(20000 * 2 * 10000 / (10 * 100000 * 3)) = 133
159+ if got , want := exponents [multigas .ResourceKindComputation ], arbmath .Bips (66 ); got != want {
160+ t .Errorf ("unexpected computation exponent: got %v, want %v" , got , want )
161+ }
162+ if got , want := exponents [multigas .ResourceKindStorageAccess ], arbmath .Bips (133 ); got != want {
163+ t .Errorf ("unexpected storage-access exponent: got %v, want %v" , got , want )
164+ }
165+
166+ // From constraint 2:
167+ // exp_storageGrowth = floor(15000 * 1 * 10000 / (5 * 50000 * 1)) = 600
168+ if got , want := exponents [multigas .ResourceKindStorageGrowth ], arbmath .Bips (600 ); got != want {
169+ t .Errorf ("unexpected storage-growth exponent: got %v, want %v" , got , want )
170+ }
171+
172+ // All other kinds should be zero
173+ if got := exponents [multigas .ResourceKindHistoryGrowth ]; got != 0 {
174+ t .Errorf ("expected zero history-growth exponent, got %v" , got )
175+ }
176+ if got := exponents [multigas .ResourceKindL1Calldata ]; got != 0 {
177+ t .Errorf ("expected zero L1 calldata exponent, got %v" , got )
178+ }
179+ if got := exponents [multigas .ResourceKindL2Calldata ]; got != 0 {
180+ t .Errorf ("expected zero L2 calldata exponent, got %v" , got )
181+ }
182+ if got := exponents [multigas .ResourceKindWasmComputation ]; got != 0 {
183+ t .Errorf ("expected zero wasm computation exponent, got %v" , got )
184+ }
185+ }
186+
129187func TestMultiDimensionalPriceForRefund (t * testing.T ) {
130188 pricing := PricingForTest (t )
131189
0 commit comments