Skip to content

Commit

Permalink
add evmtool compability, fixing bugs related to sender recovery of 77…
Browse files Browse the repository at this point in the history
…02 txs and handling authorizations to empty accounts

Signed-off-by: Daniel Lehrner <[email protected]>
  • Loading branch information
daniellehrner committed Jul 4, 2024
1 parent 17d2b12 commit 37db021
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public record SetCodeAuthorization(
* @return SetCodeTransactionEntry
*/
@JsonCreator
public static SetCodeAuthorization createAccessListEntry(
public static SetCodeAuthorization createSetCodeAuthorizationEntry(
@JsonProperty("chainId") final BigInteger chainId,
@JsonProperty("address") final Address address,
@JsonProperty("nonce") final List<Long> nonces,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ private static Bytes setCodePreimage(
SetCodeTransactionEncoder.encodeSetCodeInner(setCodePayloads, rlpOutput);
rlpOutput.endList();
});
return Bytes.concatenate(Bytes.of(TransactionType.BLOB.getSerializedType()), encoded);
return Bytes.concatenate(Bytes.of(TransactionType.SET_CODE.getSerializedType()), encoded);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.encoding.SetCodeTransactionEncoder;
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
import org.hyperledger.besu.evm.account.Account;
import org.hyperledger.besu.evm.account.AccountState;
import org.hyperledger.besu.evm.account.MutableAccount;
import org.hyperledger.besu.evm.worldstate.WorldUpdater;
Expand Down Expand Up @@ -79,8 +80,12 @@ public Set<Address> addContractToAuthority(
return;
}

final Optional<Account> maybeCodeOriginAccount =
Optional.ofNullable(worldUpdater.getAccount(payload.address()));
worldUpdater.addCodeToEOA(
authorityAddress, worldUpdater.getAccount(payload.address()).getCode());
authorityAddress,
maybeCodeOriginAccount.map(Account::getCode).orElse(Bytes.EMPTY));

authorityList.add(authorityAddress);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.SetCodeAuthorization;
import org.hyperledger.besu.datatypes.TransactionType;
import org.hyperledger.besu.datatypes.VersionedHash;
import org.hyperledger.besu.datatypes.Wei;
Expand Down Expand Up @@ -209,6 +210,68 @@ protected static List<Transaction> extractTransactions(
builder.accessList(entries);
}

if (txNode.has("authorizationList")) {
JsonNode authorizationList = txNode.get("authorizationList");

if (!authorizationList.isArray()) {
out.printf(
"TX json node unparseable: expected authorizationList to be an array - %s%n",
txNode);
continue;
}

List<SetCodeAuthorization> authorizations = new ArrayList<>(authorizationList.size());
for (JsonNode entryAsJson : authorizationList) {
final BigInteger authorizationChainId =
Bytes.fromHexStringLenient(entryAsJson.get("chainId").textValue())
.toUnsignedBigInteger();
final Address authorizationAddress =
Address.fromHexString(entryAsJson.get("address").textValue());

JsonNode nonces = txNode.get("nonce");

if (nonces == null) {
out.printf(
"TX json node unparseable: expected nonce field to be provided - %s%n",
txNode);
continue;
}

List<Long> authorizationNonces;
if (nonces.isArray()) {
authorizationNonces = new ArrayList<>(nonces.size());
for (JsonNode nonceAsJson : nonces) {
authorizationNonces.add(
Bytes.fromHexStringLenient(nonceAsJson.textValue()).toLong());
}
} else {
authorizationNonces =
List.of(Bytes.fromHexStringLenient(nonces.textValue()).toLong());
}

final byte authorizationV =
Bytes.fromHexStringLenient(entryAsJson.get("v").textValue())
.toUnsignedBigInteger()
.byteValueExact();
final BigInteger authorizationR =
Bytes.fromHexStringLenient(entryAsJson.get("r").textValue())
.toUnsignedBigInteger();
final BigInteger authorizationS =
Bytes.fromHexStringLenient(entryAsJson.get("s").textValue())
.toUnsignedBigInteger();

authorizations.add(
SetCodeAuthorization.createSetCodeAuthorizationEntry(
authorizationChainId,
authorizationAddress,
authorizationNonces,
authorizationV,
authorizationR,
authorizationS));
}
builder.setCodeTransactionPayloads(authorizations);
}

if (txNode.has("blobVersionedHashes")) {
JsonNode blobVersionedHashes = txNode.get("blobVersionedHashes");
if (!blobVersionedHashes.isArray()) {
Expand Down Expand Up @@ -252,7 +315,22 @@ protected static List<Transaction> extractTransactions(
Bytes.fromHexStringLenient(txNode.get("s").textValue())
.toUnsignedBigInteger(),
v.byteValueExact()));
transactions.add(builder.build());

final Transaction tx = builder.build();

if (txNode.has("sender")) {
final Address senderAddress =
Address.fromHexString(txNode.get("sender").textValue());

if (!tx.getSender().equals(senderAddress)) {
out.printf(
"TX json node unparseable: sender address does not match signature - %s%n",
txNode);
continue;
}
}

transactions.add(tx);
}
}
} else {
Expand Down

0 comments on commit 37db021

Please sign in to comment.