Skip to content

Commit 5f2355a

Browse files
committed
params,internal: add eth_config
1 parent 264c06a commit 5f2355a

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed

core/vm/contracts.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
type PrecompiledContract interface {
4747
RequiredGas(input []byte) uint64 // RequiredPrice calculates the contract gas use
4848
Run(input []byte) ([]byte, error) // Run runs the precompiled contract
49+
Name() string
4950
}
5051

5152
// PrecompiledContracts contains the precompiled contracts supported at the given fork.
@@ -308,6 +309,10 @@ func (c *ecrecover) Run(input []byte) ([]byte, error) {
308309
return common.LeftPadBytes(crypto.Keccak256(pubKey[1:])[12:], 32), nil
309310
}
310311

312+
func (c *ecrecover) Name() string {
313+
return "ECREC"
314+
}
315+
311316
// SHA256 implemented as a native contract.
312317
type sha256hash struct{}
313318

@@ -323,6 +328,10 @@ func (c *sha256hash) Run(input []byte) ([]byte, error) {
323328
return h[:], nil
324329
}
325330

331+
func (c *sha256hash) Name() string {
332+
return "SHA256"
333+
}
334+
326335
// RIPEMD160 implemented as a native contract.
327336
type ripemd160hash struct{}
328337

@@ -339,6 +348,10 @@ func (c *ripemd160hash) Run(input []byte) ([]byte, error) {
339348
return common.LeftPadBytes(ripemd.Sum(nil), 32), nil
340349
}
341350

351+
func (c *ripemd160hash) Name() string {
352+
return "RIPEMD160"
353+
}
354+
342355
// data copy implemented as a native contract.
343356
type dataCopy struct{}
344357

@@ -353,6 +366,10 @@ func (c *dataCopy) Run(in []byte) ([]byte, error) {
353366
return common.CopyBytes(in), nil
354367
}
355368

369+
func (c *dataCopy) Name() string {
370+
return "ID"
371+
}
372+
356373
// bigModExp implements a native big integer exponential modular operation.
357374
type bigModExp struct {
358375
eip2565 bool
@@ -537,6 +554,10 @@ func (c *bigModExp) Run(input []byte) ([]byte, error) {
537554
return common.LeftPadBytes(v, int(modLen)), nil
538555
}
539556

557+
func (c *bigModExp) Name() string {
558+
return "MODEXP"
559+
}
560+
540561
// newCurvePoint unmarshals a binary blob into a bn256 elliptic curve point,
541562
// returning it, or an error if the point is invalid.
542563
func newCurvePoint(blob []byte) (*bn256.G1, error) {
@@ -586,6 +607,10 @@ func (c *bn256AddIstanbul) Run(input []byte) ([]byte, error) {
586607
return runBn256Add(input)
587608
}
588609

610+
func (c *bn256AddIstanbul) Name() string {
611+
return "BN256_ADD"
612+
}
613+
589614
// bn256AddByzantium implements a native elliptic curve point addition
590615
// conforming to Byzantium consensus rules.
591616
type bn256AddByzantium struct{}
@@ -599,6 +624,10 @@ func (c *bn256AddByzantium) Run(input []byte) ([]byte, error) {
599624
return runBn256Add(input)
600625
}
601626

627+
func (c *bn256AddByzantium) Name() string {
628+
return "BN256_ADD"
629+
}
630+
602631
// runBn256ScalarMul implements the Bn256ScalarMul precompile, referenced by
603632
// both Byzantium and Istanbul operations.
604633
func runBn256ScalarMul(input []byte) ([]byte, error) {
@@ -624,6 +653,10 @@ func (c *bn256ScalarMulIstanbul) Run(input []byte) ([]byte, error) {
624653
return runBn256ScalarMul(input)
625654
}
626655

656+
func (c *bn256ScalarMulIstanbul) Name() string {
657+
return "BN256_MUL"
658+
}
659+
627660
// bn256ScalarMulByzantium implements a native elliptic curve scalar
628661
// multiplication conforming to Byzantium consensus rules.
629662
type bn256ScalarMulByzantium struct{}
@@ -637,6 +670,10 @@ func (c *bn256ScalarMulByzantium) Run(input []byte) ([]byte, error) {
637670
return runBn256ScalarMul(input)
638671
}
639672

673+
func (c *bn256ScalarMulByzantium) Name() string {
674+
return "BN256_MUL"
675+
}
676+
640677
var (
641678
// true32Byte is returned if the bn256 pairing check succeeds.
642679
true32Byte = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
@@ -692,6 +729,10 @@ func (c *bn256PairingIstanbul) Run(input []byte) ([]byte, error) {
692729
return runBn256Pairing(input)
693730
}
694731

732+
func (c *bn256PairingIstanbul) Name() string {
733+
return "BN256_PAIRING"
734+
}
735+
695736
// bn256PairingByzantium implements a pairing pre-compile for the bn256 curve
696737
// conforming to Byzantium consensus rules.
697738
type bn256PairingByzantium struct{}
@@ -705,6 +746,10 @@ func (c *bn256PairingByzantium) Run(input []byte) ([]byte, error) {
705746
return runBn256Pairing(input)
706747
}
707748

749+
func (c *bn256PairingByzantium) Name() string {
750+
return "BN256_PAIRING"
751+
}
752+
708753
type blake2F struct{}
709754

710755
func (c *blake2F) RequiredGas(input []byte) uint64 {
@@ -766,6 +811,10 @@ func (c *blake2F) Run(input []byte) ([]byte, error) {
766811
return output, nil
767812
}
768813

814+
func (c *blake2F) Name() string {
815+
return "BLAKE2F"
816+
}
817+
769818
var (
770819
errBLS12381InvalidInputLength = errors.New("invalid input length")
771820
errBLS12381InvalidFieldElementTopBytes = errors.New("invalid field element top bytes")
@@ -809,6 +858,10 @@ func (c *bls12381G1Add) Run(input []byte) ([]byte, error) {
809858
return encodePointG1(p0), nil
810859
}
811860

861+
func (c *bls12381G1Add) Name() string {
862+
return "BLS12_G1ADD"
863+
}
864+
812865
// bls12381G1MultiExp implements EIP-2537 G1MultiExp precompile.
813866
type bls12381G1MultiExp struct{}
814867

@@ -869,6 +922,10 @@ func (c *bls12381G1MultiExp) Run(input []byte) ([]byte, error) {
869922
return encodePointG1(r), nil
870923
}
871924

925+
func (c *bls12381G1MultiExp) Name() string {
926+
return "BLS12_G1MSM"
927+
}
928+
872929
// bls12381G2Add implements EIP-2537 G2Add precompile.
873930
type bls12381G2Add struct{}
874931

@@ -906,6 +963,10 @@ func (c *bls12381G2Add) Run(input []byte) ([]byte, error) {
906963
return encodePointG2(r), nil
907964
}
908965

966+
func (c *bls12381G2Add) Name() string {
967+
return "BLS12_G2ADD"
968+
}
969+
909970
// bls12381G2MultiExp implements EIP-2537 G2MultiExp precompile.
910971
type bls12381G2MultiExp struct{}
911972

@@ -966,6 +1027,10 @@ func (c *bls12381G2MultiExp) Run(input []byte) ([]byte, error) {
9661027
return encodePointG2(r), nil
9671028
}
9681029

1030+
func (c *bls12381G2MultiExp) Name() string {
1031+
return "BLS12_G2MSM"
1032+
}
1033+
9691034
// bls12381Pairing implements EIP-2537 Pairing precompile.
9701035
type bls12381Pairing struct{}
9711036

@@ -1029,6 +1094,10 @@ func (c *bls12381Pairing) Run(input []byte) ([]byte, error) {
10291094
return out, nil
10301095
}
10311096

1097+
func (c *bls12381Pairing) Name() string {
1098+
return "BLS12_PAIRING_CHECK"
1099+
}
1100+
10321101
func decodePointG1(in []byte) (*bls12381.G1Affine, error) {
10331102
if len(in) != 128 {
10341103
return nil, errors.New("invalid g1 point length")
@@ -1147,6 +1216,10 @@ func (c *bls12381MapG1) Run(input []byte) ([]byte, error) {
11471216
return encodePointG1(&r), nil
11481217
}
11491218

1219+
func (c *bls12381MapG1) Name() string {
1220+
return "BLS12_MAP_FP_TO_G1"
1221+
}
1222+
11501223
// bls12381MapG2 implements EIP-2537 MapG2 precompile.
11511224
type bls12381MapG2 struct{}
11521225

@@ -1180,6 +1253,10 @@ func (c *bls12381MapG2) Run(input []byte) ([]byte, error) {
11801253
return encodePointG2(&r), nil
11811254
}
11821255

1256+
func (c *bls12381MapG2) Name() string {
1257+
return "BLS12_MAP_FP2_TO_G2"
1258+
}
1259+
11831260
// kzgPointEvaluation implements the EIP-4844 point evaluation precompile.
11841261
type kzgPointEvaluation struct{}
11851262

@@ -1236,6 +1313,10 @@ func (b *kzgPointEvaluation) Run(input []byte) ([]byte, error) {
12361313
return common.Hex2Bytes(blobPrecompileReturnValue), nil
12371314
}
12381315

1316+
func (c *kzgPointEvaluation) Name() string {
1317+
return "KZG_POINT_EVALUATION"
1318+
}
1319+
12391320
// kZGToVersionedHash implements kzg_to_versioned_hash from EIP-4844
12401321
func kZGToVersionedHash(kzg kzg4844.Commitment) common.Hash {
12411322
h := sha256.Sum256(kzg[:])
@@ -1271,3 +1352,7 @@ func (c *p256Verify) Run(input []byte) ([]byte, error) {
12711352
}
12721353
return nil, nil
12731354
}
1355+
1356+
func (c *p256Verify) Name() string {
1357+
return "P256VERIFY"
1358+
}

internal/ethapi/api.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,34 @@ func (api *BlockChainAPI) CreateAccessList(ctx context.Context, args Transaction
11351135
return result, nil
11361136
}
11371137

1138+
type config struct {
1139+
ActivationTime uint64 `json:"activationTime"`
1140+
BlobSchedule *params.BlobConfig `json:"blobSchedule"`
1141+
ChainId *hexutil.Big `json:"chainId"`
1142+
Precompiles map[common.Address]string `json:"precompiles"`
1143+
SystemContracts map[string]common.Address `json:"systemContracts"`
1144+
}
1145+
1146+
// Config implements the EIP-7910 eth_config method.
1147+
func (api *BlockChainAPI) Config(ctx context.Context) config {
1148+
var (
1149+
c = api.b.ChainConfig()
1150+
h = api.b.CurrentBlock()
1151+
rules = c.Rules(h.Number, true, h.Time)
1152+
precompiles = make(map[common.Address]string)
1153+
)
1154+
for addr, c := range vm.ActivePrecompiledContracts(rules) {
1155+
precompiles[addr] = c.Name()
1156+
}
1157+
return config{
1158+
ActivationTime: c.NextForkTime(h.Time),
1159+
BlobSchedule: c.BlobConfig(c.LatestFork(h.Time)),
1160+
ChainId: (*hexutil.Big)(c.ChainID),
1161+
Precompiles: precompiles,
1162+
SystemContracts: c.ActiveSystemContracts(h.Time),
1163+
}
1164+
}
1165+
11381166
// AccessList creates an access list for the given transaction.
11391167
// If the accesslist creation fails an error is returned.
11401168
// If the transaction itself fails, an vmErr is returned.

internal/jsre/deps/web3.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5490,6 +5490,10 @@ var properties = function () {
54905490
new Property({
54915491
name: 'protocolVersion',
54925492
getter: 'eth_protocolVersion'
5493+
}),
5494+
new Property({
5495+
name: 'config',
5496+
getter: 'eth_config'
54935497
})
54945498
];
54955499
};

params/config.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,65 @@ func (c *ChainConfig) LatestFork(time uint64) forks.Fork {
985985
}
986986
}
987987

988+
// NextFork returns the next fork to activate or nil if the last defined fork is
989+
// active.
990+
func (c *ChainConfig) NextForkTime(time uint64) uint64 {
991+
// Assume last non-time-based fork has passed.
992+
london := c.LondonBlock
993+
next := newUint64(0)
994+
995+
switch {
996+
case c.IsOsaka(london, time):
997+
next = c.OsakaTime
998+
case c.IsPrague(london, time):
999+
next = c.OsakaTime
1000+
case c.IsCancun(london, time):
1001+
next = c.PragueTime
1002+
case c.IsShanghai(london, time):
1003+
next = c.CancunTime
1004+
default:
1005+
next = c.ShanghaiTime
1006+
}
1007+
if next == nil {
1008+
return 0
1009+
}
1010+
return *next
1011+
}
1012+
1013+
// BlobConfig returns the blob config associated with the provided fork.
1014+
func (c *ChainConfig) BlobConfig(fork forks.Fork) *BlobConfig {
1015+
switch fork {
1016+
case forks.Osaka:
1017+
return DefaultOsakaBlobConfig
1018+
case forks.Prague:
1019+
return DefaultPragueBlobConfig
1020+
case forks.Cancun:
1021+
return DefaultCancunBlobConfig
1022+
default:
1023+
return nil
1024+
}
1025+
}
1026+
1027+
// ActiveSystemContracts returns the currently active system contracts at the
1028+
// given timestamp.
1029+
func (c *ChainConfig) ActiveSystemContracts(time uint64) map[string]common.Address {
1030+
fork := c.LatestFork(time)
1031+
active := make(map[string]common.Address)
1032+
if fork >= forks.Osaka {
1033+
// no new system contracts
1034+
}
1035+
if fork >= forks.Prague {
1036+
active["CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS"] = ConsolidationQueueAddress
1037+
active["DEPOSIT_CONTRACT_ADDRESS"] = c.DepositContractAddress
1038+
active["HISTORY_STORAGE_ADDRESS"] = HistoryStorageAddress
1039+
active["WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS"] = WithdrawalQueueAddress
1040+
}
1041+
if fork >= forks.Cancun {
1042+
active["BEACON_ROOTS_ADDRESS"] = BeaconRootsAddress
1043+
}
1044+
return active
1045+
}
1046+
9881047
// Timestamp returns the timestamp associated with the fork or returns nil if
9891048
// the fork isn't defined or isn't a time-based fork.
9901049
func (c *ChainConfig) Timestamp(fork forks.Fork) *uint64 {

0 commit comments

Comments
 (0)