Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4844] wip - added versioned hashes checking #5520

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
60be8c0
SSZ - encoding (#4979)
gezero Jan 23, 2023
6fef25a
verfifying kzg proof (#4994)
gezero Jan 24, 2023
36577b6
4844 engine api (#4991)
jflo Jan 24, 2023
332fb08
[Interop-4844] Data gas accounting (#4998)
fab-10 Jan 25, 2023
573a942
Adding trace logs to mention ssz transaction encoding/deconding in lo…
gezero Jan 26, 2023
bf73985
adding test for nonblob blob transaction (#5008)
gezero Jan 27, 2023
6c24554
Blob tx network size and hash (#5015)
fab-10 Jan 27, 2023
9eec66b
Consumed data gas receipt fix (#5018)
fab-10 Jan 27, 2023
ffb36cb
Fix data gas calculation during block import (#5023)
fab-10 Jan 31, 2023
adf1da6
Fix getBloblsBundleV1 response (#5049)
fab-10 Feb 3, 2023
f9ea8be
Fix GetBlobBundleV1 response (#5075)
fab-10 Feb 9, 2023
ffb6e96
4844: read blobs as raw bytes not as unit256 and fix blob versioned h…
fab-10 Feb 10, 2023
2badf77
Temporary embed devnet 4 trusted setup until a configuration option i…
fab-10 Feb 14, 2023
acc4956
update verification for tuweni ssz
jflo May 3, 2023
44d4228
passing tests up till SSL stuff
jflo May 8, 2023
a4503c6
updated from main
jflo May 9, 2023
a483981
made hardforks optional
jflo May 10, 2023
00cfc5a
new tx type got lost
jflo May 11, 2023
b3cd177
fixes wrong encoding method on persisting to RocksDB
jflo May 15, 2023
ffd383d
extend correct parent gas calc
jflo May 17, 2023
1146309
spotless
jflo May 17, 2023
1f308be
plugin api version
jflo May 17, 2023
2716b85
SSZ - encoding (#4979)
gezero Jan 23, 2023
e9644ff
verfifying kzg proof (#4994)
gezero Jan 24, 2023
8b37cfd
4844 engine api (#4991)
jflo Jan 24, 2023
16b2427
[Interop-4844] Data gas accounting (#4998)
fab-10 Jan 25, 2023
c208bd2
Adding trace logs to mention ssz transaction encoding/deconding in lo…
gezero Jan 26, 2023
6ef302a
adding test for nonblob blob transaction (#5008)
gezero Jan 27, 2023
a4abc7f
Blob tx network size and hash (#5015)
fab-10 Jan 27, 2023
fa3f6c9
Consumed data gas receipt fix (#5018)
fab-10 Jan 27, 2023
fdd8c25
Fix data gas calculation during block import (#5023)
fab-10 Jan 31, 2023
ef3fdf4
Fix getBloblsBundleV1 response (#5049)
fab-10 Feb 3, 2023
2f877c2
Fix GetBlobBundleV1 response (#5075)
fab-10 Feb 9, 2023
1e779f1
4844: read blobs as raw bytes not as unit256 and fix blob versioned h…
fab-10 Feb 10, 2023
4df6fdc
passing tests up till SSL stuff
jflo May 8, 2023
ef21b1c
updated from main
jflo May 9, 2023
97b70b9
made hardforks optional
jflo May 10, 2023
c2aaa72
new tx type got lost
jflo May 11, 2023
c1f19c2
fixes wrong encoding method on persisting to RocksDB
jflo May 15, 2023
669c54b
spotless
jflo May 17, 2023
1298ffb
toString updates
jflo May 18, 2023
3ab84ae
update sigs
jflo May 18, 2023
4a97dae
adds test coverage for broken transaction root calc on block 62717 fr…
jflo May 18, 2023
0b389d2
workaround for incorrect SSZ implementation for BytesList[]
jflo May 20, 2023
832cb2d
block validation test coverage for cancun, handle blob transactions w…
jflo May 22, 2023
24064b3
test fixup
jflo May 22, 2023
b47d6db
should run like the other txs
jflo May 23, 2023
3ab97e4
goldarn fuzzer
jflo May 23, 2023
a351daa
correct optional handling
jflo May 23, 2023
2a26fb1
pass versionedHashes to child frames
jflo May 23, 2023
17c66da
add proofs to blobs bundle
gfukushima Apr 28, 2023
63f1684
cherrypicked in blob decoupling
jflo May 24, 2023
cce26f7
wip - added versioned hashes checking
macfarla May 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,318 changes: 4,159 additions & 4,159 deletions config/src/main/resources/kzg-trusted-setups/mainnet.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public BftProtocolSchedule create(
Optional.ofNullable(forkSpecs.higher(spec)).map(ForkSpec::getBlock);
protocolSchedule.getScheduledProtocolSpecs().stream()
.filter(protocolSpecMatchesConsensusBlockRange(spec.getBlock(), endBlock))
.forEach(s -> combinedProtocolSchedule.putBlockNumberMilestone(s.milestone(), s.spec()));
.forEach(
s ->
combinedProtocolSchedule.putBlockNumberMilestone(s.fork().milestone(), s.spec()));

// When moving to a new consensus mechanism we want to use the last milestone but created by
// our consensus mechanism's BesuControllerBuilder so any additional rules are applied
Expand All @@ -67,7 +69,7 @@ public BftProtocolSchedule create(
private Predicate<ScheduledProtocolSpec> protocolSpecMatchesConsensusBlockRange(
final long startBlock, final Optional<Long> endBlock) {
return scheduledProtocolSpec ->
scheduledProtocolSpec.milestone() >= startBlock
&& endBlock.map(b -> scheduledProtocolSpec.milestone() < b).orElse(true);
scheduledProtocolSpec.fork().milestone() >= startBlock
&& endBlock.map(b -> scheduledProtocolSpec.fork().milestone() < b).orElse(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ public ProtocolSpec getByBlockNumber(final long number) {
checkArgument(
!protocolSpecs.isEmpty(), "At least 1 milestone must be provided to the protocol schedule");
checkArgument(
protocolSpecs.last().milestone() == 0, "There must be a milestone starting from block 0");
protocolSpecs.last().fork().milestone() == 0,
"There must be a milestone starting from block 0");
// protocolSpecs is sorted in descending block order, so the first one we find that's lower than
// the requested level will be the most appropriate spec
for (final ScheduledProtocolSpec s : protocolSpecs) {
if (number >= s.milestone()) {
if (number >= s.fork().milestone()) {
return s.spec();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.apache.tuweni.bytes.Bytes;
import org.junit.Test;

public class IbftExtraDataEncoderTest {
public class IbftExtraDataRLPEncoderTest {

private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM =
Suppliers.memoize(SignatureAlgorithmFactory::getInstance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ public void putTimestampMilestone(final long timestamp, final ProtocolSpec proto
"Should not use TransitionProtocolSchedule wrapper class to create milestones");
}

@Override
public Optional<ScheduledProtocolSpec.Hardfork> hardforkFor(
final Predicate<ScheduledProtocolSpec> predicate) {
return this.transitionUtils.dispatchFunctionAccordingToMergeState(
schedule -> schedule.hardforkFor(predicate));
}

/**
* List milestones.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ public TransactionResult transaction(
.byteValueExact()))
.payload(bytes(input))
.sender(address(fromAddress))
.v(bigInteger(v))
.build();

return new TransactionCompleteResult(
Expand Down Expand Up @@ -224,10 +223,6 @@ private String removeHexPrefix(final String prefixedHex) {
return prefixedHex.startsWith("0x") ? prefixedHex.substring(2) : prefixedHex;
}

private BigInteger bigInteger(final String hex) {
return hex == null ? null : new BigInteger(removeHexPrefix(hex), HEX_RADIX);
}

private Wei wei(final String hex) {
return Wei.fromHexString(hex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,19 @@ public enum RpcMethod {
DEBUG_GET_RAW_RECEIPTS("debug_getRawReceipts"),
ENGINE_GET_PAYLOAD_V1("engine_getPayloadV1"),
ENGINE_GET_PAYLOAD_V2("engine_getPayloadV2"),
ENGINE_GET_PAYLOAD_V3("engine_getPayloadV3"),
ENGINE_EXECUTE_PAYLOAD("engine_executePayloadV1"),
ENGINE_NEW_PAYLOAD_V1("engine_newPayloadV1"),
ENGINE_NEW_PAYLOAD_V2("engine_newPayloadV2"),
ENGINE_NEW_PAYLOAD_V3("engine_newPayloadV3"),
ENGINE_FORKCHOICE_UPDATED_V1("engine_forkchoiceUpdatedV1"),
ENGINE_FORKCHOICE_UPDATED_V2("engine_forkchoiceUpdatedV2"),
ENGINE_EXCHANGE_TRANSITION_CONFIGURATION("engine_exchangeTransitionConfigurationV1"),
ENGINE_GET_PAYLOAD_BODIES_BY_HASH_V1("engine_getPayloadBodiesByHashV1"),
ENGINE_GET_PAYLOAD_BODIES_BY_RANGE_V1("engine_getPayloadBodiesByRangeV1"),
ENGINE_EXCHANGE_CAPABILITIES("engine_exchangeCapabilities"),
ENGINE_PREPARE_PAYLOAD_DEBUG("engine_preparePayload_debug"),
ENGINE_GET_BLOBS_BUNDLE_V1("engine_getBlobsBundleV1"),
PRIV_CALL("priv_call"),
PRIV_GET_PRIVATE_TRANSACTION("priv_getPrivateTransaction"),
PRIV_GET_TRANSACTION_COUNT("priv_getTransactionCount"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockWithReceipts;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;

import java.util.Optional;

Expand All @@ -39,15 +40,19 @@ public abstract class AbstractEngineGetPayload extends ExecutionEngineJsonRpcMet
protected final BlockResultFactory blockResultFactory;
private static final Logger LOG = LoggerFactory.getLogger(AbstractEngineGetPayload.class);

protected final Optional<ProtocolSchedule> schedule;

public AbstractEngineGetPayload(
final Vertx vertx,
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeMiningCoordinator,
final BlockResultFactory blockResultFactory,
final EngineCallListener engineCallListener) {
final EngineCallListener engineCallListener,
final ProtocolSchedule schedule) {
super(vertx, protocolContext, engineCallListener);
this.mergeMiningCoordinator = mergeMiningCoordinator;
this.blockResultFactory = blockResultFactory;
this.schedule = Optional.ofNullable(schedule);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.INVALID_PARAMS;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.datatypes.DataGas;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.BlockProcessingResult;
Expand Down Expand Up @@ -160,7 +161,9 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
blockParam.getPrevRandao(),
0,
maybeWithdrawals.map(BodyValidation::withdrawalsRoot).orElse(null),
null,
blockParam.getExcessDataGas() == null
? null
: DataGas.fromHexString(blockParam.getExcessDataGas()),
null,
headerFunctions);

Expand Down Expand Up @@ -190,6 +193,41 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
"Block already present in bad block manager.");
}

final List<Hash> transactionVersionedHashes = new ArrayList<>();
// get versioned hashes, in order, from all blob tx
transactions.stream()
.filter(tx -> tx.getBlobCount() > 0)
.map(tx -> transactionVersionedHashes.addAll(tx.getVersionedHashes().get()));
// and compare with expected versioned hashes param
final Optional<List<Hash>> maybeVersionedHashes =
Optional.ofNullable(blockParam.getVersionedHashes());
// check if one is empty
if (maybeVersionedHashes.isPresent() && transactionVersionedHashes.isEmpty()) {
return respondWithInvalid(
reqId,
blockParam,
null,
INVALID,
"Versioned hashes from blob transactions (empty) do not match expected values");
}
if (maybeVersionedHashes.isEmpty() && !transactionVersionedHashes.isEmpty()) {
return respondWithInvalid(
reqId,
blockParam,
null,
INVALID,
"Versioned hashes from blob transactions do not match expected values (empty)");
}
// otherwise, check list contents
if (!maybeVersionedHashes.get().equals(transactionVersionedHashes)) {
return respondWithInvalid(
reqId,
blockParam,
null,
INVALID,
"Versioned hashes from blob transactions do not match expected values (empty)");
}

final Optional<BlockHeader> maybeParentHeader =
protocolContext.getBlockchain().getBlockHeader(blockParam.getParentHash());
if (maybeParentHeader.isPresent()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.api.jsonrpc.internal.methods.engine;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.consensus.merge.blockcreation.PayloadIdentifier;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlobsBundleV1;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockWithReceipts;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;

import java.util.List;

import io.vertx.core.Vertx;

public class EngineGetBlobsBundleV1 extends AbstractEngineGetPayload {

public EngineGetBlobsBundleV1(
final Vertx vertx,
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeMiningCoordinator,
final BlockResultFactory blockResultFactory,
final EngineCallListener engineCallListener,
final ProtocolSchedule schedule) {
super(
vertx,
protocolContext,
mergeMiningCoordinator,
blockResultFactory,
engineCallListener,
schedule);
}

@Override
protected JsonRpcResponse createResponse(
final JsonRpcRequestContext request,
final PayloadIdentifier payloadId,
final BlockWithReceipts blockWithReceipts) {

return new JsonRpcSuccessResponse(
request.getRequest().getId(), createResponse(blockWithReceipts.getBlock()));
}

private BlobsBundleV1 createResponse(final Block block) {

final List<Transaction> transactions = block.getBody().getTransactions();

return new BlobsBundleV1(transactions);
}

@Override
public String getName() {
return RpcMethod.ENGINE_GET_BLOBS_BUNDLE_V1.getMethodName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory;
import org.hyperledger.besu.ethereum.core.BlockWithReceipts;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;

import java.util.Optional;

Expand All @@ -35,8 +36,15 @@ public EngineGetPayloadV1(
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeMiningCoordinator,
final BlockResultFactory blockResultFactory,
final EngineCallListener engineCallListener) {
super(vertx, protocolContext, mergeMiningCoordinator, blockResultFactory, engineCallListener);
final EngineCallListener engineCallListener,
final ProtocolSchedule schedule) {
super(
vertx,
protocolContext,
mergeMiningCoordinator,
blockResultFactory,
engineCallListener,
schedule);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory;
import org.hyperledger.besu.ethereum.core.BlockWithReceipts;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;

import java.util.Optional;

Expand All @@ -36,8 +37,15 @@ public EngineGetPayloadV2(
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeMiningCoordinator,
final BlockResultFactory blockResultFactory,
final EngineCallListener engineCallListener) {
super(vertx, protocolContext, mergeMiningCoordinator, blockResultFactory, engineCallListener);
final EngineCallListener engineCallListener,
final ProtocolSchedule schedule) {
super(
vertx,
protocolContext,
mergeMiningCoordinator,
blockResultFactory,
engineCallListener,
schedule);
}

@Override
Expand Down
Loading