Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit e64d0d8

Browse files
siladugaryschulte
authored andcommitted
Support authorizationList parsing in reference test txs (#8116)
Support authorizationList parsing in reference tests for execution-spec-tests Allow zero chainId Signed-off-by: Simon Dudley <[email protected]>
1 parent abef4ff commit e64d0d8

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/CodeDelegation.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@
2121
import org.hyperledger.besu.datatypes.Address;
2222
import org.hyperledger.besu.datatypes.Hash;
2323
import org.hyperledger.besu.ethereum.core.encoding.CodeDelegationTransactionEncoder;
24+
import org.hyperledger.besu.ethereum.core.json.ChainIdDeserializer;
2425
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
2526

2627
import java.math.BigInteger;
2728
import java.util.Optional;
2829
import java.util.function.Supplier;
2930

3031
import com.fasterxml.jackson.annotation.JsonCreator;
32+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
3133
import com.fasterxml.jackson.annotation.JsonProperty;
34+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
3235
import com.google.common.base.Suppliers;
3336
import org.apache.tuweni.bytes.Bytes;
3437

38+
// ignore `signer` field used in execution-spec-tests
39+
@JsonIgnoreProperties(ignoreUnknown = true)
3540
public class CodeDelegation implements org.hyperledger.besu.datatypes.CodeDelegation {
3641
private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM =
3742
Suppliers.memoize(SignatureAlgorithmFactory::getInstance);
@@ -77,14 +82,23 @@ public CodeDelegation(
7782
*/
7883
@JsonCreator
7984
public static org.hyperledger.besu.datatypes.CodeDelegation createCodeDelegation(
80-
@JsonProperty("chainId") final BigInteger chainId,
85+
@JsonProperty("chainId") @JsonDeserialize(using = ChainIdDeserializer.class)
86+
final BigInteger chainId,
8187
@JsonProperty("address") final Address address,
82-
@JsonProperty("nonce") final long nonce,
83-
@JsonProperty("v") final byte v,
84-
@JsonProperty("r") final BigInteger r,
85-
@JsonProperty("s") final BigInteger s) {
88+
@JsonProperty("nonce") final String nonce,
89+
@JsonProperty("v") final String v,
90+
@JsonProperty("r") final String r,
91+
@JsonProperty("s") final String s) {
8692
return new CodeDelegation(
87-
chainId, address, nonce, SIGNATURE_ALGORITHM.get().createSignature(r, s, v));
93+
chainId,
94+
address,
95+
Bytes.fromHexStringLenient(nonce).toLong(),
96+
SIGNATURE_ALGORITHM
97+
.get()
98+
.createSignature(
99+
Bytes.fromHexStringLenient(r).toUnsignedBigInteger(),
100+
Bytes.fromHexStringLenient(s).toUnsignedBigInteger(),
101+
Bytes.fromHexStringLenient(v).get(0)));
88102
}
89103

90104
@JsonProperty("chainId")

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/json/ChainIdDeserializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public BigInteger deserialize(final JsonParser jsonparser, final Deserialization
3838
final var chainId =
3939
UInt256.fromHexString(jsonparser.getCodec().readValue(jsonparser, String.class))
4040
.toBigInteger();
41-
if (chainId.signum() <= 0) {
42-
throw new IllegalArgumentException("Non positive chain id: " + chainId);
41+
if (chainId.signum() < 0) {
42+
throw new IllegalArgumentException("Negative chain id: " + chainId);
4343
}
4444
return chainId;
4545
}

ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/StateTestVersionedTransaction.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public class StateTestVersionedTransaction {
7575
// String instead of VersionedHash because reference tests intentionally use bad hashes.
7676
private final List<String> blobVersionedHashes;
7777

78+
@JsonDeserialize(contentAs = org.hyperledger.besu.ethereum.core.CodeDelegation.class)
79+
private final List<org.hyperledger.besu.datatypes.CodeDelegation> authorizationList;
80+
7881
/**
7982
* Constructor for populating a mock transaction with json data.
8083
*
@@ -103,7 +106,9 @@ public StateTestVersionedTransaction(
103106
@JsonDeserialize(using = StateTestAccessListDeserializer.class) @JsonProperty("accessLists")
104107
final List<List<AccessListEntry>> maybeAccessLists,
105108
@JsonProperty("maxFeePerBlobGas") final String maxFeePerBlobGas,
106-
@JsonProperty("blobVersionedHashes") final List<String> blobVersionedHashes) {
109+
@JsonProperty("blobVersionedHashes") final List<String> blobVersionedHashes,
110+
@JsonProperty("authorizationList")
111+
final List<org.hyperledger.besu.datatypes.CodeDelegation> authorizationList) {
107112

108113
this.nonce = Bytes.fromHexStringLenient(nonce).toLong();
109114
this.gasPrice = Optional.ofNullable(gasPrice).map(Wei::fromHexString).orElse(null);
@@ -124,6 +129,7 @@ public StateTestVersionedTransaction(
124129
this.maxFeePerBlobGas =
125130
Optional.ofNullable(maxFeePerBlobGas).map(Wei::fromHexString).orElse(null);
126131
this.blobVersionedHashes = blobVersionedHashes;
132+
this.authorizationList = authorizationList;
127133
}
128134

129135
private static <T> List<T> parseArray(final String[] array, final Function<String, T> parseFct) {
@@ -170,6 +176,7 @@ public Transaction get(final GeneralStateTestCaseSpec.Indexes indexes) {
170176
// versioned hash string was bad, so this is an invalid transaction
171177
return null;
172178
}
179+
Optional.ofNullable(authorizationList).ifPresent(transactionBuilder::codeDelegations);
173180

174181
transactionBuilder.guessType();
175182
if (transactionBuilder.getTransactionType().requiresChainId()) {

0 commit comments

Comments
 (0)