Skip to content

Commit a5ed392

Browse files
shemnonmacfarla
andauthored
Change eth_config hashing and config members (#9015)
* Change eth_config hashing and config members - Remove ConfigHash - move ForkID into config - invert key/value of precompiles Signed-off-by: Danno Ferrin <danno@numisight.com> * linting Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com> --------- Signed-off-by: Danno Ferrin <danno@numisight.com> Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com> Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
1 parent 2ffd464 commit a5ed392

File tree

3 files changed

+76
-117
lines changed

3 files changed

+76
-117
lines changed

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthConfig.java

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@
3232
import org.hyperledger.besu.evm.EvmSpecVersion;
3333
import org.hyperledger.besu.evm.precompile.PrecompileContractRegistry;
3434

35-
import java.nio.charset.StandardCharsets;
3635
import java.util.Map;
36+
import java.util.Map.Entry;
3737
import java.util.Optional;
3838
import java.util.TreeMap;
3939
import java.util.function.Supplier;
40-
import java.util.zip.CRC32;
4140

42-
import com.fasterxml.jackson.databind.JsonNode;
4341
import com.fasterxml.jackson.databind.ObjectMapper;
4442
import com.fasterxml.jackson.databind.node.ObjectNode;
4543
import com.google.common.base.Suppliers;
@@ -82,29 +80,17 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
8280
ObjectNode result = mapperSupplier.get().createObjectNode();
8381
ObjectNode currentNode = result.putObject("current");
8482
generateConfig(currentNode, current);
85-
String currentHash = configHash(currentNode);
86-
result.put("currentHash", currentHash);
87-
result.put("currentForkId", getForkIdAsHexString(currentTime));
8883
if (next.isPresent()) {
84+
// if next is present, last will be present as next may be last.
8985
ObjectNode nextNode = result.putObject("next");
90-
generateConfig(nextNode, next.get());
91-
String nextHash = configHash(nextNode);
92-
result.put("nextHash", nextHash);
93-
result.put("nextForkId", getForkIdAsHexString(next.get().fork().milestone()));
94-
95-
if (last.isPresent()) {
96-
ObjectNode lastNode = result.putObject("last");
97-
generateConfig(lastNode, last.get());
98-
String lastHash = configHash(lastNode);
99-
result.put("lastHash", lastHash);
100-
result.put("lastForkId", getForkIdAsHexString(last.get().fork().milestone()));
101-
} else {
102-
appendEmptyLast(result);
103-
}
86+
ScheduledProtocolSpec nextSpec = next.get();
87+
generateConfig(nextNode, nextSpec);
88+
ObjectNode lastNode = result.putObject("last");
89+
generateConfig(lastNode, last.orElse(nextSpec));
10490
} else {
10591
// if next is empty, last is empty (no future forks)
106-
appendEmptyNext(result);
107-
appendEmptyLast(result);
92+
result.putNull("next");
93+
result.putNull("last");
10894
}
10995

11096
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), result);
@@ -134,11 +120,14 @@ void generateConfig(final ObjectNode result, final Hardfork forkId, final Protoc
134120
result.put(
135121
"chainId", protocolSchedule.getChainId().map(c -> "0x" + c.toString(16)).orElse(null));
136122

123+
result.put("forkId", getForkIdAsHexString(forkId.milestone()));
124+
137125
PrecompileContractRegistry registry = spec.getPrecompileContractRegistry();
138126
ObjectNode precompiles = result.putObject("precompiles");
139127
registry.getPrecompileAddresses().stream()
140-
.sorted()
141-
.forEach(a -> precompiles.put(a.toHexString(), registry.get(a).getName()));
128+
.map(a -> Map.entry(registry.get(a).getName(), a.toHexString()))
129+
.sorted(Entry.comparingByKey())
130+
.forEach(e -> precompiles.put(e.getKey(), e.getValue()));
142131

143132
TreeMap<String, String> systemContracts =
144133
new TreeMap<>(
@@ -156,26 +145,4 @@ void generateConfig(final ObjectNode result, final Hardfork forkId, final Protoc
156145
systemContracts.forEach(jsonContracts::put);
157146
}
158147
}
159-
160-
String configHash(final JsonNode node) {
161-
if (node == null) {
162-
return null;
163-
} else {
164-
final CRC32 crc = new CRC32();
165-
crc.update(node.toString().getBytes(StandardCharsets.UTF_8));
166-
return "0x" + Long.toHexString(crc.getValue());
167-
}
168-
}
169-
170-
private static void appendEmptyNext(final ObjectNode result) {
171-
result.putNull("next");
172-
result.putNull("nextHash");
173-
result.putNull("nextForkId");
174-
}
175-
176-
private static void appendEmptyLast(final ObjectNode result) {
177-
result.putNull("last");
178-
result.putNull("lastHash");
179-
result.putNull("lastForkId");
180-
}
181148
}

ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/config/eth_config.json

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,23 @@
1818
"target": 3
1919
},
2020
"chainId": "0x1",
21+
"forkId": "0x1ac6901c",
2122
"precompiles": {
22-
"0x0000000000000000000000000000000000000001": "ECREC",
23-
"0x0000000000000000000000000000000000000002": "SHA256",
24-
"0x0000000000000000000000000000000000000003": "RIPEMD160",
25-
"0x0000000000000000000000000000000000000004": "ID",
26-
"0x0000000000000000000000000000000000000005": "MODEXP",
27-
"0x0000000000000000000000000000000000000006": "BN254_ADD",
28-
"0x0000000000000000000000000000000000000007": "BN254_MUL",
29-
"0x0000000000000000000000000000000000000008": "BN254_PAIRING",
30-
"0x0000000000000000000000000000000000000009": "BLAKE2F",
31-
"0x000000000000000000000000000000000000000a": "KZG_POINT_EVALUATION"
23+
"BLAKE2F": "0x0000000000000000000000000000000000000009",
24+
"BN254_ADD": "0x0000000000000000000000000000000000000006",
25+
"BN254_MUL": "0x0000000000000000000000000000000000000007",
26+
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
27+
"ECREC": "0x0000000000000000000000000000000000000001",
28+
"ID": "0x0000000000000000000000000000000000000004",
29+
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
30+
"MODEXP": "0x0000000000000000000000000000000000000005",
31+
"RIPEMD160": "0x0000000000000000000000000000000000000003",
32+
"SHA256": "0x0000000000000000000000000000000000000002"
3233
},
3334
"systemContracts": {
3435
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02"
3536
}
3637
},
37-
"currentHash": "0x407087b0",
38-
"currentForkId": "0x1ac6901c",
3938
"next": {
4039
"activationTime": 9999999999999,
4140
"blobSchedule": {
@@ -44,24 +43,25 @@
4443
"target": 6
4544
},
4645
"chainId": "0x1",
46+
"forkId": "0x1ac6901c",
4747
"precompiles": {
48-
"0x0000000000000000000000000000000000000001": "ECREC",
49-
"0x0000000000000000000000000000000000000002": "SHA256",
50-
"0x0000000000000000000000000000000000000003": "RIPEMD160",
51-
"0x0000000000000000000000000000000000000004": "ID",
52-
"0x0000000000000000000000000000000000000005": "MODEXP",
53-
"0x0000000000000000000000000000000000000006": "BN254_ADD",
54-
"0x0000000000000000000000000000000000000007": "BN254_MUL",
55-
"0x0000000000000000000000000000000000000008": "BN254_PAIRING",
56-
"0x0000000000000000000000000000000000000009": "BLAKE2F",
57-
"0x000000000000000000000000000000000000000a": "KZG_POINT_EVALUATION",
58-
"0x000000000000000000000000000000000000000b": "BLS12_G1ADD",
59-
"0x000000000000000000000000000000000000000c": "BLS12_G1MSM",
60-
"0x000000000000000000000000000000000000000d": "BLS12_G2ADD",
61-
"0x000000000000000000000000000000000000000e": "BLS12_G2MSM",
62-
"0x000000000000000000000000000000000000000f": "BLS12_PAIRING_CHECK",
63-
"0x0000000000000000000000000000000000000010": "BLS12_MAP_FP_TO_G1",
64-
"0x0000000000000000000000000000000000000011": "BLS12_MAP_FP2_TO_G2"
48+
"BLAKE2F": "0x0000000000000000000000000000000000000009",
49+
"BLS12_G1ADD": "0x000000000000000000000000000000000000000b",
50+
"BLS12_G1MSM": "0x000000000000000000000000000000000000000c",
51+
"BLS12_G2ADD": "0x000000000000000000000000000000000000000d",
52+
"BLS12_G2MSM": "0x000000000000000000000000000000000000000e",
53+
"BLS12_MAP_FP2_TO_G2": "0x0000000000000000000000000000000000000011",
54+
"BLS12_MAP_FP_TO_G1": "0x0000000000000000000000000000000000000010",
55+
"BLS12_PAIRING_CHECK": "0x000000000000000000000000000000000000000f",
56+
"BN254_ADD": "0x0000000000000000000000000000000000000006",
57+
"BN254_MUL": "0x0000000000000000000000000000000000000007",
58+
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
59+
"ECREC": "0x0000000000000000000000000000000000000001",
60+
"ID": "0x0000000000000000000000000000000000000004",
61+
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
62+
"MODEXP": "0x0000000000000000000000000000000000000005",
63+
"RIPEMD160": "0x0000000000000000000000000000000000000003",
64+
"SHA256": "0x0000000000000000000000000000000000000002"
6565
},
6666
"systemContracts": {
6767
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02",
@@ -71,8 +71,6 @@
7171
"WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": "0x00000961ef480eb55e80d19ad83579a64c007002"
7272
}
7373
},
74-
"nextHash": "0x50457308",
75-
"nextForkId": "0x1ac6901c",
7674
"last": {
7775
"activationTime": 9999999999999,
7876
"blobSchedule": {
@@ -81,24 +79,25 @@
8179
"target": 6
8280
},
8381
"chainId": "0x1",
82+
"forkId": "0x1ac6901c",
8483
"precompiles": {
85-
"0x0000000000000000000000000000000000000001": "ECREC",
86-
"0x0000000000000000000000000000000000000002": "SHA256",
87-
"0x0000000000000000000000000000000000000003": "RIPEMD160",
88-
"0x0000000000000000000000000000000000000004": "ID",
89-
"0x0000000000000000000000000000000000000005": "MODEXP",
90-
"0x0000000000000000000000000000000000000006": "BN254_ADD",
91-
"0x0000000000000000000000000000000000000007": "BN254_MUL",
92-
"0x0000000000000000000000000000000000000008": "BN254_PAIRING",
93-
"0x0000000000000000000000000000000000000009": "BLAKE2F",
94-
"0x000000000000000000000000000000000000000a": "KZG_POINT_EVALUATION",
95-
"0x000000000000000000000000000000000000000b": "BLS12_G1ADD",
96-
"0x000000000000000000000000000000000000000c": "BLS12_G1MSM",
97-
"0x000000000000000000000000000000000000000d": "BLS12_G2ADD",
98-
"0x000000000000000000000000000000000000000e": "BLS12_G2MSM",
99-
"0x000000000000000000000000000000000000000f": "BLS12_PAIRING_CHECK",
100-
"0x0000000000000000000000000000000000000010": "BLS12_MAP_FP_TO_G1",
101-
"0x0000000000000000000000000000000000000011": "BLS12_MAP_FP2_TO_G2"
84+
"BLAKE2F": "0x0000000000000000000000000000000000000009",
85+
"BLS12_G1ADD": "0x000000000000000000000000000000000000000b",
86+
"BLS12_G1MSM": "0x000000000000000000000000000000000000000c",
87+
"BLS12_G2ADD": "0x000000000000000000000000000000000000000d",
88+
"BLS12_G2MSM": "0x000000000000000000000000000000000000000e",
89+
"BLS12_MAP_FP2_TO_G2": "0x0000000000000000000000000000000000000011",
90+
"BLS12_MAP_FP_TO_G1": "0x0000000000000000000000000000000000000010",
91+
"BLS12_PAIRING_CHECK": "0x000000000000000000000000000000000000000f",
92+
"BN254_ADD": "0x0000000000000000000000000000000000000006",
93+
"BN254_MUL": "0x0000000000000000000000000000000000000007",
94+
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
95+
"ECREC": "0x0000000000000000000000000000000000000001",
96+
"ID": "0x0000000000000000000000000000000000000004",
97+
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
98+
"MODEXP": "0x0000000000000000000000000000000000000005",
99+
"RIPEMD160": "0x0000000000000000000000000000000000000003",
100+
"SHA256": "0x0000000000000000000000000000000000000002"
102101
},
103102
"systemContracts": {
104103
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02",
@@ -107,10 +106,8 @@
107106
"HISTORY_STORAGE_ADDRESS": "0x0000f90827f1c53a10cb7a02335b175320002935",
108107
"WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": "0x00000961ef480eb55e80d19ad83579a64c007002"
109108
}
110-
},
111-
"lastHash": "0x50457308",
112-
"lastForkId": "0x1ac6901c"
109+
}
113110
}
114111
},
115112
"statusCode": 200
116-
}
113+
}

ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_config.json

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"request": {
33
"id": 8,
4-
"comment" : "eth_config for hive genesis",
4+
"comment": "eth_config for hive genesis",
55
"jsonrpc": "2.0",
66
"method": "eth_config",
77
"params": []
@@ -10,38 +10,33 @@
1010
"jsonrpc": "2.0",
1111
"id": 8,
1212
"result": {
13-
"current": {
13+
"current" : {
1414
"activationTime" : 1444660040,
1515
"blobSchedule" : {
1616
"baseFeeUpdateFraction" : 3338477,
1717
"max" : 6,
1818
"target" : 3
1919
},
2020
"chainId" : "0x1",
21+
"forkId" : "0x97fa8ff0",
2122
"precompiles" : {
22-
"0x0000000000000000000000000000000000000001" : "ECREC",
23-
"0x0000000000000000000000000000000000000002" : "SHA256",
24-
"0x0000000000000000000000000000000000000003" : "RIPEMD160",
25-
"0x0000000000000000000000000000000000000004" : "ID",
26-
"0x0000000000000000000000000000000000000005" : "MODEXP",
27-
"0x0000000000000000000000000000000000000006" : "BN254_ADD",
28-
"0x0000000000000000000000000000000000000007" : "BN254_MUL",
29-
"0x0000000000000000000000000000000000000008" : "BN254_PAIRING",
30-
"0x0000000000000000000000000000000000000009" : "BLAKE2F",
31-
"0x000000000000000000000000000000000000000a" : "KZG_POINT_EVALUATION"
23+
"BLAKE2F" : "0x0000000000000000000000000000000000000009",
24+
"BN254_ADD" : "0x0000000000000000000000000000000000000006",
25+
"BN254_MUL" : "0x0000000000000000000000000000000000000007",
26+
"BN254_PAIRING" : "0x0000000000000000000000000000000000000008",
27+
"ECREC" : "0x0000000000000000000000000000000000000001",
28+
"ID" : "0x0000000000000000000000000000000000000004",
29+
"KZG_POINT_EVALUATION" : "0x000000000000000000000000000000000000000a",
30+
"MODEXP" : "0x0000000000000000000000000000000000000005",
31+
"RIPEMD160" : "0x0000000000000000000000000000000000000003",
32+
"SHA256" : "0x0000000000000000000000000000000000000002"
3233
},
3334
"systemContracts" : {
3435
"BEACON_ROOTS_ADDRESS" : "0x000f3df6d732807ef1319fb7b8bb8522d0beac02"
3536
}
3637
},
37-
"currentHash" : "0x3af40c89",
38-
"currentForkId" : "0x97fa8ff0",
3938
"next" : null,
40-
"nextHash" : null,
41-
"nextForkId" : null,
42-
"last" : null,
43-
"lastHash" : null,
44-
"lastForkId" : null
39+
"last" : null
4540
}
4641
},
4742
"statusCode": 200

0 commit comments

Comments
 (0)