|
|
@ -22,7 +22,6 @@ import org.hyperledger.besu.datatypes.Blob; |
|
|
|
import org.hyperledger.besu.datatypes.BlobsWithCommitments; |
|
|
|
import org.hyperledger.besu.datatypes.BlobsWithCommitments; |
|
|
|
import org.hyperledger.besu.datatypes.Hash; |
|
|
|
import org.hyperledger.besu.datatypes.Hash; |
|
|
|
import org.hyperledger.besu.datatypes.KZGCommitment; |
|
|
|
import org.hyperledger.besu.datatypes.KZGCommitment; |
|
|
|
import org.hyperledger.besu.datatypes.KZGProof; |
|
|
|
|
|
|
|
import org.hyperledger.besu.datatypes.TransactionType; |
|
|
|
import org.hyperledger.besu.datatypes.TransactionType; |
|
|
|
import org.hyperledger.besu.datatypes.VersionedHash; |
|
|
|
import org.hyperledger.besu.datatypes.VersionedHash; |
|
|
|
import org.hyperledger.besu.datatypes.Wei; |
|
|
|
import org.hyperledger.besu.datatypes.Wei; |
|
|
@ -51,8 +50,6 @@ import org.bouncycastle.crypto.digests.SHA256Digest; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class MainnetTransactionValidator implements TransactionValidator { |
|
|
|
public class MainnetTransactionValidator implements TransactionValidator { |
|
|
|
|
|
|
|
|
|
|
|
private static final byte BLOB_COMMITMENT_VERSION_KZG = 0x01; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final GasCalculator gasCalculator; |
|
|
|
private final GasCalculator gasCalculator; |
|
|
|
private final GasLimitCalculator gasLimitCalculator; |
|
|
|
private final GasLimitCalculator gasLimitCalculator; |
|
|
|
private final FeeMarket feeMarket; |
|
|
|
private final FeeMarket feeMarket; |
|
|
@ -336,11 +333,11 @@ public class MainnetTransactionValidator implements TransactionValidator { |
|
|
|
final KZGCommitment commitment = blobsWithCommitments.getKzgCommitments().get(i); |
|
|
|
final KZGCommitment commitment = blobsWithCommitments.getKzgCommitments().get(i); |
|
|
|
final VersionedHash versionedHash = versionedHashes.get(i); |
|
|
|
final VersionedHash versionedHash = versionedHashes.get(i); |
|
|
|
|
|
|
|
|
|
|
|
if (versionedHash.getVersionId() != BLOB_COMMITMENT_VERSION_KZG) { |
|
|
|
if (versionedHash.getVersionId() != VersionedHash.SHA256_VERSION_ID) { |
|
|
|
return ValidationResult.invalid( |
|
|
|
return ValidationResult.invalid( |
|
|
|
TransactionInvalidReason.INVALID_BLOBS, |
|
|
|
TransactionInvalidReason.INVALID_BLOBS, |
|
|
|
"transaction blobs commitment version is not supported. Expected " |
|
|
|
"transaction blobs commitment version is not supported. Expected " |
|
|
|
+ BLOB_COMMITMENT_VERSION_KZG |
|
|
|
+ VersionedHash.SHA256_VERSION_ID |
|
|
|
+ ", found " |
|
|
|
+ ", found " |
|
|
|
+ versionedHash.getVersionId()); |
|
|
|
+ versionedHash.getVersionId()); |
|
|
|
} |
|
|
|
} |
|
|
@ -353,30 +350,27 @@ public class MainnetTransactionValidator implements TransactionValidator { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final Bytes blobs = |
|
|
|
final byte[] blobs = |
|
|
|
blobsWithCommitments.getBlobs().stream() |
|
|
|
Bytes.wrap(blobsWithCommitments.getBlobs().stream().map(Blob::getData).toList()) |
|
|
|
.map(Blob::getData) |
|
|
|
.toArrayUnsafe(); |
|
|
|
.reduce(Bytes::concatenate) |
|
|
|
|
|
|
|
.orElseThrow(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Bytes kzgCommitments = |
|
|
|
final byte[] kzgCommitments = |
|
|
|
blobsWithCommitments.getKzgCommitments().stream() |
|
|
|
Bytes.wrap( |
|
|
|
.map(KZGCommitment::getData) |
|
|
|
blobsWithCommitments.getKzgCommitments().stream() |
|
|
|
.reduce(Bytes::concatenate) |
|
|
|
.map(kc -> (Bytes) kc.getData()) |
|
|
|
.orElseThrow(); |
|
|
|
.toList()) |
|
|
|
|
|
|
|
.toArrayUnsafe(); |
|
|
|
|
|
|
|
|
|
|
|
final Bytes kzgProofs = |
|
|
|
final byte[] kzgProofs = |
|
|
|
blobsWithCommitments.getKzgProofs().stream() |
|
|
|
Bytes.wrap( |
|
|
|
.map(KZGProof::getData) |
|
|
|
blobsWithCommitments.getKzgProofs().stream() |
|
|
|
.reduce(Bytes::concatenate) |
|
|
|
.map(kp -> (Bytes) kp.getData()) |
|
|
|
.orElseThrow(); |
|
|
|
.toList()) |
|
|
|
|
|
|
|
.toArrayUnsafe(); |
|
|
|
|
|
|
|
|
|
|
|
final boolean kzgVerification = |
|
|
|
final boolean kzgVerification = |
|
|
|
CKZG4844JNI.verifyBlobKzgProofBatch( |
|
|
|
CKZG4844JNI.verifyBlobKzgProofBatch( |
|
|
|
blobs.toArrayUnsafe(), |
|
|
|
blobs, kzgCommitments, kzgProofs, blobsWithCommitments.getBlobs().size()); |
|
|
|
kzgCommitments.toArrayUnsafe(), |
|
|
|
|
|
|
|
kzgProofs.toArrayUnsafe(), |
|
|
|
|
|
|
|
blobsWithCommitments.getBlobs().size()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!kzgVerification) { |
|
|
|
if (!kzgVerification) { |
|
|
|
return ValidationResult.invalid( |
|
|
|
return ValidationResult.invalid( |
|
|
@ -387,14 +381,6 @@ public class MainnetTransactionValidator implements TransactionValidator { |
|
|
|
return ValidationResult.valid(); |
|
|
|
return ValidationResult.valid(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
private VersionedHash hashCommitment(final Bytes32 commitment) { |
|
|
|
|
|
|
|
return new VersionedHash( |
|
|
|
|
|
|
|
VersionedHash.SHA256_VERSION_ID, Sha256Hash.hash(commitment)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private VersionedHash hashCommitment(final KZGCommitment commitment) { |
|
|
|
private VersionedHash hashCommitment(final KZGCommitment commitment) { |
|
|
|
final SHA256Digest digest = new SHA256Digest(); |
|
|
|
final SHA256Digest digest = new SHA256Digest(); |
|
|
|
digest.update(commitment.getData().toArrayUnsafe(), 0, commitment.getData().size()); |
|
|
|
digest.update(commitment.getData().toArrayUnsafe(), 0, commitment.getData().size()); |
|
|
@ -403,7 +389,7 @@ public class MainnetTransactionValidator implements TransactionValidator { |
|
|
|
|
|
|
|
|
|
|
|
digest.doFinal(dig, 0); |
|
|
|
digest.doFinal(dig, 0); |
|
|
|
|
|
|
|
|
|
|
|
dig[0] = BLOB_COMMITMENT_VERSION_KZG; |
|
|
|
dig[0] = VersionedHash.SHA256_VERSION_ID; |
|
|
|
return new VersionedHash(Bytes32.wrap(dig)); |
|
|
|
return new VersionedHash(Bytes32.wrap(dig)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|