Skip to content

Commit

Permalink
removed KZG tests till library settled
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Florentine <justin+github@florentine.us>
  • Loading branch information
jflo committed Jun 5, 2023
1 parent ffc218f commit 3c5f2ec
Show file tree
Hide file tree
Showing 21 changed files with 222 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public static Hash hash(final Bytes value) {
return new Hash(keccak256(value));
}

public static Hash sha256(final Bytes value) {
return new Hash(org.hyperledger.besu.crypto.Hash.sha256(value));
}

/**
* Wrap bytes to hash.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;

import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.blobs.VersionedHash;
import org.hyperledger.besu.ethereum.core.encoding.TransactionEncoder;
import org.hyperledger.besu.evm.AccessListEntry;
import org.hyperledger.besu.plugin.data.TransactionType;
Expand Down Expand Up @@ -81,7 +81,7 @@ public class TransactionPendingResult implements TransactionResult {
private final String s;

@JsonInclude(JsonInclude.Include.NON_NULL)
private final List<Hash> versionedHashes;
private final List<VersionedHash> versionedHashes;

public TransactionPendingResult(final Transaction transaction) {
final TransactionType transactionType = transaction.getType();
Expand Down Expand Up @@ -223,7 +223,7 @@ public String getTransactionIndex() {
}

@JsonGetter(value = "blobVersionedHashes")
public List<Hash> getVersionedHashes() {
public List<VersionedHash> getVersionedHashes() {
return versionedHashes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ static GasLimitCalculator constant() {
}

default long currentDataGasLimit() {
return 0L;
return 1 << 19;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hyperledger.besu.ethereum.core.blobs.BlobsWithCommitments;
import org.hyperledger.besu.ethereum.core.blobs.KZGCommitment;
import org.hyperledger.besu.ethereum.core.blobs.KZGProof;
import org.hyperledger.besu.ethereum.core.blobs.VersionedHash;
import org.hyperledger.besu.ethereum.core.encoding.BlobTransactionDecoder;
import org.hyperledger.besu.ethereum.core.encoding.TransactionDecoder;
import org.hyperledger.besu.ethereum.core.encoding.TransactionEncoder;
Expand Down Expand Up @@ -112,7 +113,7 @@ public class Transaction
private final TransactionType transactionType;

private final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithmFactory.getInstance();
private final Optional<List<Hash>> versionedHashes;
private final Optional<List<VersionedHash>> versionedHashes;

private final Optional<BlobsWithCommitments> blobsWithCommitments;

Expand Down Expand Up @@ -166,7 +167,7 @@ public Transaction(
final Optional<List<AccessListEntry>> maybeAccessList,
final Address sender,
final Optional<BigInteger> chainId,
final Optional<List<Hash>> versionedHashes,
final Optional<List<VersionedHash>> versionedHashes,
final Optional<BlobsWithCommitments> blobsWithCommitments) {

if (transactionType.requiresChainId()) {
Expand Down Expand Up @@ -235,7 +236,7 @@ public Transaction(
final Bytes payload,
final Address sender,
final Optional<BigInteger> chainId,
final Optional<List<Hash>> versionedHashes,
final Optional<List<VersionedHash>> versionedHashes,
final Optional<BlobsWithCommitments> blobsWithCommitments) {
this(
TransactionType.FRONTIER,
Expand Down Expand Up @@ -265,7 +266,7 @@ public Transaction(
final SECPSignature signature,
final Bytes payload,
final Optional<BigInteger> chainId,
final Optional<List<Hash>> versionedHashes,
final Optional<List<VersionedHash>> versionedHashes,
final Optional<BlobsWithCommitments> blobsWithCommitments) {
this(
TransactionType.FRONTIER,
Expand Down Expand Up @@ -313,7 +314,7 @@ public Transaction(
final Bytes payload,
final Address sender,
final Optional<BigInteger> chainId,
final Optional<List<Hash>> versionedHashes) {
final Optional<List<VersionedHash>> versionedHashes) {
this(
nonce,
Optional.of(gasPrice),
Expand Down Expand Up @@ -359,7 +360,7 @@ public Transaction(
final Address sender,
final Optional<BigInteger> chainId,
final Optional<Wei> maxFeePerDataGas,
final Optional<List<Hash>> versionedHashes,
final Optional<List<VersionedHash>> versionedHashes,
final Optional<BlobsWithCommitments> blobsWithCommitments) {
this(
nonce,
Expand Down Expand Up @@ -805,7 +806,7 @@ public TransactionType getType() {
return this.transactionType;
}

public Optional<List<Hash>> getVersionedHashes() {
public Optional<List<VersionedHash>> getVersionedHashes() {
return versionedHashes;
}

Expand Down Expand Up @@ -849,7 +850,7 @@ private static Bytes32 computeSenderRecoveryHash(
final Wei value,
final Bytes payload,
final Optional<List<AccessListEntry>> accessList,
final List<Hash> versionedHashes,
final List<VersionedHash> versionedHashes,
final Optional<BigInteger> chainId) {
if (transactionType.requiresChainId()) {
checkArgument(chainId.isPresent(), "Transaction type %s requires chainId", transactionType);
Expand Down Expand Up @@ -998,7 +999,7 @@ private static Bytes blobPreimage(
final Bytes payload,
final Optional<BigInteger> chainId,
final Optional<List<AccessListEntry>> accessList,
final List<Hash> versionedHashes) {
final List<VersionedHash> versionedHashes) {

final Bytes encoded =
RLP.encode(
Expand Down Expand Up @@ -1181,7 +1182,7 @@ public static class Builder {

protected Optional<BigInteger> chainId = Optional.empty();

protected List<Hash> versionedHashes = null;
protected List<VersionedHash> versionedHashes = null;
private BlobsWithCommitments blobsWithCommitments;

public Builder type(final TransactionType transactionType) {
Expand Down Expand Up @@ -1257,7 +1258,7 @@ public Builder signature(final SECPSignature signature) {
return this;
}

public Builder versionedHashes(final List<Hash> versionedHashes) {
public Builder versionedHashes(final List<VersionedHash> versionedHashes) {
this.versionedHashes = versionedHashes;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.hyperledger.besu.ethereum.core.blobs;

import org.hyperledger.besu.datatypes.Hash;

import java.util.Objects;

import org.apache.tuweni.bytes.Bytes32;

public class VersionedHash {

private final byte versionId;
Bytes32 hashish;

public VersionedHash(final byte versionId, final Hash hash) {
if (versionId != 1) {
throw new IllegalArgumentException("Only supported hash version is 0x01, sha256 hash.");
}

this.versionId = versionId;
this.hashish = hash;
}

public VersionedHash(final Bytes32 typedHash) {
byte versionId = typedHash.get(0);
if (versionId != 1) {
throw new IllegalArgumentException("Only supported hash version is 0x01, sha256 hash.");
}
this.versionId = versionId;
this.hashish = typedHash;
}

public Bytes32 toBytes() {
byte[] bytes = hashish.toArray();
bytes[0] = versionId;
return Bytes32.wrap(bytes);
}

public byte getVersionId() {
return versionId;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VersionedHash that = (VersionedHash) o;
return getVersionId() == that.getVersionId() && Objects.equals(this.toBytes(), that.toBytes());
}

@Override
public int hashCode() {
return Objects.hash(getVersionId(), hashish);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import org.hyperledger.besu.crypto.SignatureAlgorithm;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.blobs.Blob;
import org.hyperledger.besu.ethereum.core.blobs.KZGCommitment;
import org.hyperledger.besu.ethereum.core.blobs.KZGProof;
import org.hyperledger.besu.ethereum.core.blobs.VersionedHash;
import org.hyperledger.besu.ethereum.rlp.RLPInput;
import org.hyperledger.besu.ethereum.rlp.RLPOutput;
import org.hyperledger.besu.evm.AccessListEntry;
Expand Down Expand Up @@ -82,7 +82,7 @@ private static void readTransactionPayloadInner(
}))
.maxFeePerDataGas(Wei.of(input.readUInt256Scalar()))
.versionedHashes(
input.readList(versionedHashes -> Hash.wrap(versionedHashes.readBytes32())));
input.readList(versionedHashes -> new VersionedHash(versionedHashes.readBytes32())));

final byte recId = (byte) input.readIntScalar();
builder.signature(
Expand All @@ -109,7 +109,7 @@ private static Transaction readNetworkWrapperInner(final RLPInput input) {
}

public static void writeBlobVersionedHashes(
final RLPOutput rlpOutput, final List<Hash> versionedHashes) {
rlpOutput.writeList(versionedHashes, (h, out) -> out.writeBytes(h));
final RLPOutput rlpOutput, final List<VersionedHash> versionedHashes) {
rlpOutput.writeList(versionedHashes, (h, out) -> out.writeBytes(h.toBytes()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ public static void encodeEIP4844(final Transaction transaction, final RLPOutput
TransactionEncoder.writeAccessList(out, transaction.getAccessList());
out.writeUInt256Scalar(transaction.getMaxFeePerDataGas().orElseThrow());
out.startList();
transaction.getVersionedHashes().get().forEach(out::writeBytes);
transaction
.getVersionedHashes()
.get()
.forEach(
vh -> {
out.writeBytes(vh.toBytes());
});
out.endList();
TransactionEncoder.writeSignatureAndRecoveryId(transaction, out);
out.endList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.blobs.VersionedHash;
import org.hyperledger.besu.ethereum.core.feemarket.CoinbaseFeePriceCalculator;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater;
Expand Down Expand Up @@ -377,8 +378,15 @@ public TransactionProcessingResult processTransaction(
.blockHashLookup(blockHashLookup)
.contextVariables(contextVariablesBuilder.build())
.accessListWarmAddresses(addressList)
.accessListWarmStorage(storageList)
.versionedHashes(transaction.getVersionedHashes());
.accessListWarmStorage(storageList);

if (transaction.getVersionedHashes().isPresent()) {
commonMessageFrameBuilder.versionedHashes(
Optional.of(
transaction.getVersionedHashes().get().stream()
.map(VersionedHash::toBytes)
.toList()));
}

final MessageFrame initialFrame;
if (transaction.isContractCreation()) {
Expand Down
Loading

0 comments on commit 3c5f2ec

Please sign in to comment.