@@ -66,7 +66,7 @@ var PrecompiledContractsByzantium = PrecompiledContracts{
66
66
common .BytesToAddress ([]byte {0x2 }): & sha256hash {},
67
67
common .BytesToAddress ([]byte {0x3 }): & ripemd160hash {},
68
68
common .BytesToAddress ([]byte {0x4 }): & dataCopy {},
69
- common .BytesToAddress ([]byte {0x5 }): & bigModExp {eip2565 : false , eip7823 : false },
69
+ common .BytesToAddress ([]byte {0x5 }): & bigModExp {eip2565 : false , eip7823 : false , eip7883 : false },
70
70
common .BytesToAddress ([]byte {0x6 }): & bn256AddByzantium {},
71
71
common .BytesToAddress ([]byte {0x7 }): & bn256ScalarMulByzantium {},
72
72
common .BytesToAddress ([]byte {0x8 }): & bn256PairingByzantium {},
@@ -79,7 +79,7 @@ var PrecompiledContractsIstanbul = PrecompiledContracts{
79
79
common .BytesToAddress ([]byte {0x2 }): & sha256hash {},
80
80
common .BytesToAddress ([]byte {0x3 }): & ripemd160hash {},
81
81
common .BytesToAddress ([]byte {0x4 }): & dataCopy {},
82
- common .BytesToAddress ([]byte {0x5 }): & bigModExp {eip2565 : false , eip7823 : false },
82
+ common .BytesToAddress ([]byte {0x5 }): & bigModExp {eip2565 : false , eip7823 : false , eip7883 : false },
83
83
common .BytesToAddress ([]byte {0x6 }): & bn256AddIstanbul {},
84
84
common .BytesToAddress ([]byte {0x7 }): & bn256ScalarMulIstanbul {},
85
85
common .BytesToAddress ([]byte {0x8 }): & bn256PairingIstanbul {},
@@ -93,7 +93,7 @@ var PrecompiledContractsBerlin = PrecompiledContracts{
93
93
common .BytesToAddress ([]byte {0x2 }): & sha256hash {},
94
94
common .BytesToAddress ([]byte {0x3 }): & ripemd160hash {},
95
95
common .BytesToAddress ([]byte {0x4 }): & dataCopy {},
96
- common .BytesToAddress ([]byte {0x5 }): & bigModExp {eip2565 : true , eip7823 : false },
96
+ common .BytesToAddress ([]byte {0x5 }): & bigModExp {eip2565 : true , eip7823 : false , eip7883 : false },
97
97
common .BytesToAddress ([]byte {0x6 }): & bn256AddIstanbul {},
98
98
common .BytesToAddress ([]byte {0x7 }): & bn256ScalarMulIstanbul {},
99
99
common .BytesToAddress ([]byte {0x8 }): & bn256PairingIstanbul {},
@@ -107,7 +107,7 @@ var PrecompiledContractsCancun = PrecompiledContracts{
107
107
common .BytesToAddress ([]byte {0x2 }): & sha256hash {},
108
108
common .BytesToAddress ([]byte {0x3 }): & ripemd160hash {},
109
109
common .BytesToAddress ([]byte {0x4 }): & dataCopy {},
110
- common .BytesToAddress ([]byte {0x5 }): & bigModExp {eip2565 : true , eip7823 : false },
110
+ common .BytesToAddress ([]byte {0x5 }): & bigModExp {eip2565 : true , eip7823 : false , eip7883 : false },
111
111
common .BytesToAddress ([]byte {0x6 }): & bn256AddIstanbul {},
112
112
common .BytesToAddress ([]byte {0x7 }): & bn256ScalarMulIstanbul {},
113
113
common .BytesToAddress ([]byte {0x8 }): & bn256PairingIstanbul {},
@@ -122,7 +122,7 @@ var PrecompiledContractsPrague = PrecompiledContracts{
122
122
common .BytesToAddress ([]byte {0x02 }): & sha256hash {},
123
123
common .BytesToAddress ([]byte {0x03 }): & ripemd160hash {},
124
124
common .BytesToAddress ([]byte {0x04 }): & dataCopy {},
125
- common .BytesToAddress ([]byte {0x05 }): & bigModExp {eip2565 : true , eip7823 : false },
125
+ common .BytesToAddress ([]byte {0x05 }): & bigModExp {eip2565 : true , eip7823 : false , eip7883 : false },
126
126
common .BytesToAddress ([]byte {0x06 }): & bn256AddIstanbul {},
127
127
common .BytesToAddress ([]byte {0x07 }): & bn256ScalarMulIstanbul {},
128
128
common .BytesToAddress ([]byte {0x08 }): & bn256PairingIstanbul {},
@@ -148,7 +148,7 @@ var PrecompiledContractsOsaka = PrecompiledContracts{
148
148
common .BytesToAddress ([]byte {0x02 }): & sha256hash {},
149
149
common .BytesToAddress ([]byte {0x03 }): & ripemd160hash {},
150
150
common .BytesToAddress ([]byte {0x04 }): & dataCopy {},
151
- common .BytesToAddress ([]byte {0x05 }): & bigModExp {eip2565 : true , eip7823 : true },
151
+ common .BytesToAddress ([]byte {0x05 }): & bigModExp {eip2565 : true , eip7823 : true , eip7883 : true },
152
152
common .BytesToAddress ([]byte {0x06 }): & bn256AddIstanbul {},
153
153
common .BytesToAddress ([]byte {0x07 }): & bn256ScalarMulIstanbul {},
154
154
common .BytesToAddress ([]byte {0x08 }): & bn256PairingIstanbul {},
@@ -164,6 +164,7 @@ var PrecompiledContractsOsaka = PrecompiledContracts{
164
164
}
165
165
166
166
var (
167
+ PrecompiledAddressesOsaka []common.Address
167
168
PrecompiledAddressesPrague []common.Address
168
169
PrecompiledAddressesCancun []common.Address
169
170
PrecompiledAddressesBerlin []common.Address
@@ -191,6 +192,9 @@ func init() {
191
192
for k := range PrecompiledContractsPrague {
192
193
PrecompiledAddressesPrague = append (PrecompiledAddressesPrague , k )
193
194
}
195
+ for k := range PrecompiledContractsOsaka {
196
+ PrecompiledAddressesOsaka = append (PrecompiledAddressesOsaka , k )
197
+ }
194
198
}
195
199
196
200
func activePrecompiledContracts (rules params.Rules ) PrecompiledContracts {
@@ -222,6 +226,8 @@ func ActivePrecompiledContracts(rules params.Rules) PrecompiledContracts {
222
226
// ActivePrecompiles returns the precompile addresses enabled with the current configuration.
223
227
func ActivePrecompiles (rules params.Rules ) []common.Address {
224
228
switch {
229
+ case rules .IsOsaka :
230
+ return PrecompiledAddressesOsaka
225
231
case rules .IsPrague :
226
232
return PrecompiledAddressesPrague
227
233
case rules .IsCancun :
@@ -342,6 +348,7 @@ func (c *dataCopy) Run(in []byte) ([]byte, error) {
342
348
type bigModExp struct {
343
349
eip2565 bool
344
350
eip7823 bool
351
+ eip7883 bool
345
352
}
346
353
347
354
var (
@@ -417,7 +424,11 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 {
417
424
adjExpLen := new (big.Int )
418
425
if expLen .Cmp (big32 ) > 0 {
419
426
adjExpLen .Sub (expLen , big32 )
420
- adjExpLen .Lsh (adjExpLen , 3 )
427
+ if c .eip7883 {
428
+ adjExpLen .Lsh (adjExpLen , 4 )
429
+ } else {
430
+ adjExpLen .Lsh (adjExpLen , 3 )
431
+ }
421
432
}
422
433
adjExpLen .Add (adjExpLen , big .NewInt (int64 (msb )))
423
434
// Calculate the gas cost of the operation
@@ -427,19 +438,30 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 {
427
438
} else {
428
439
gas .Set (modLen )
429
440
}
441
+
442
+ maxLenOver32 := gas .Cmp (big32 ) > 0
430
443
if c .eip2565 {
431
- // EIP-2565 has three changes
444
+ // EIP-2565 (Berlin fork) has three changes:
445
+ //
432
446
// 1. Different multComplexity (inlined here)
433
447
// in EIP-2565 (https://eips.ethereum.org/EIPS/eip-2565):
434
448
//
435
449
// def mult_complexity(x):
436
450
// ceiling(x/8)^2
437
451
//
438
- //where is x is max(length_of_MODULUS, length_of_BASE)
452
+ // where is x is max(length_of_MODULUS, length_of_BASE)
439
453
gas .Add (gas , big7 )
440
454
gas .Rsh (gas , 3 )
441
455
gas .Mul (gas , gas )
442
456
457
+ var minPrice uint64 = 200
458
+ if c .eip7883 {
459
+ minPrice = 500
460
+ if maxLenOver32 {
461
+ gas .Add (gas , gas )
462
+ }
463
+ }
464
+
443
465
if adjExpLen .Cmp (big1 ) > 0 {
444
466
gas .Mul (gas , adjExpLen )
445
467
}
@@ -448,18 +470,15 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 {
448
470
if gas .BitLen () > 64 {
449
471
return math .MaxUint64
450
472
}
451
- // 3. Minimum price of 200 gas
452
- if gas .Uint64 () < 200 {
453
- return 200
454
- }
455
- return gas .Uint64 ()
473
+ return max (minPrice , gas .Uint64 ())
456
474
}
475
+
476
+ // Pre-Berlin logic.
457
477
gas = modexpMultComplexity (gas )
458
478
if adjExpLen .Cmp (big1 ) > 0 {
459
479
gas .Mul (gas , adjExpLen )
460
480
}
461
481
gas .Div (gas , big20 )
462
-
463
482
if gas .BitLen () > 64 {
464
483
return math .MaxUint64
465
484
}
0 commit comments