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

[NO MERGE] Verkle trees #7890

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ protected void prepareValidPayload(final Spec spec, final BeaconState genericSta
state, beaconStateAccessors.getCurrentEpoch(state)))
.timestamp(
miscHelpers.computeTimeAtSlot(state.getGenesisTime(), state.getSlot()))
.withdrawals(Collections::emptyList));
.withdrawals(Collections::emptyList)
.executionWitness(dataStructureUtil::randomExecutionWitness));
executionPayloadHeader =
SchemaDefinitionsBellatrix.required(spec.getGenesisSpec().getSchemaDefinitions())
.getExecutionPayloadHeaderSchema()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ protected static void applyCapellaFields(
.baseFeePerGas(instance.latestExecutionPayloadHeader.baseFeePerGas)
.blockHash(instance.latestExecutionPayloadHeader.blockHash)
.transactionsRoot(instance.latestExecutionPayloadHeader.transactionsRoot)
.withdrawalsRoot(() -> instance.latestExecutionPayloadHeader.withdrawalsRoot)));
.withdrawalsRoot(() -> instance.latestExecutionPayloadHeader.withdrawalsRoot)
// TODO Verkle trees
.executionWitnessRoot(() -> Bytes32.ZERO)));

state.setNextWithdrawalIndex(instance.nextWithdrawalIndex);
state.setNextWithdrawalValidatorIndex(instance.nextWithdrawalValidatorIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public ExecutionPayloadHeader asInternalExecutionPayloadHeader(
.blockHash(blockHash)
.transactionsRoot(transactionsRoot)
.withdrawalsRoot(() -> withdrawalsRoot)
// TODO Verkle trees
.executionWitnessRoot(() -> Bytes32.ZERO)
.blobGasUsed(() -> blobGasUsed)
.excessBlobGas(() -> excessBlobGas));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

public class ExecutionPayloadV2 extends ExecutionPayloadV1 {
public final List<WithdrawalV1> withdrawals;
public final Bytes executionWitness;

public ExecutionPayloadV2(
@JsonProperty("parentHash") Bytes32 parentHash,
Expand All @@ -49,7 +50,8 @@ public ExecutionPayloadV2(
@JsonProperty("baseFeePerGas") UInt256 baseFeePerGas,
@JsonProperty("blockHash") Bytes32 blockHash,
@JsonProperty("transactions") List<Bytes> transactions,
@JsonProperty("withdrawals") List<WithdrawalV1> withdrawals) {
@JsonProperty("withdrawals") List<WithdrawalV1> withdrawals,
@JsonProperty("execution_witness") Bytes executionWitness) {
super(
parentHash,
feeRecipient,
Expand All @@ -66,6 +68,7 @@ public ExecutionPayloadV2(
blockHash,
transactions);
this.withdrawals = withdrawals;
this.executionWitness = executionWitness;
}

public static ExecutionPayloadV2 fromInternalExecutionPayload(ExecutionPayload executionPayload) {
Expand All @@ -85,7 +88,11 @@ public static ExecutionPayloadV2 fromInternalExecutionPayload(ExecutionPayload e
executionPayload.getBaseFeePerGas(),
executionPayload.getBlockHash(),
executionPayload.getTransactions().stream().map(SszByteListImpl::getBytes).toList(),
withdrawalsList);
withdrawalsList,
executionPayload
.toVersionCapella()
.map(capellaPayload -> capellaPayload.getExecutionWitness().sszSerialize())
.orElse(null));
}

@Override
Expand All @@ -99,7 +106,14 @@ protected ExecutionPayloadBuilder applyToBuilder(
.map(
withdrawalV1 ->
createInternalWithdrawal(withdrawalV1, executionPayloadSchema))
.toList());
.toList())
.executionWitness(
() -> {
checkNotNull(executionWitness, "execution witness not provided when required");
return executionPayloadSchema
.getExecutionWitnessSchemaRequired()
.sszDeserialize(executionWitness);
});
}

private Withdrawal createInternalWithdrawal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public ExecutionPayloadV3(
@JsonProperty("blockHash") Bytes32 blockHash,
@JsonProperty("transactions") List<Bytes> transactions,
@JsonProperty("withdrawals") List<WithdrawalV1> withdrawals,
@JsonProperty("execution_witness") Bytes executionWitness,
@JsonProperty("blobGasUsed") UInt64 blobGasUsed,
@JsonProperty("excessBlobGas") UInt64 excessBlobGas) {
super(
Expand All @@ -74,7 +75,8 @@ public ExecutionPayloadV3(
baseFeePerGas,
blockHash,
transactions,
withdrawals);
withdrawals,
executionWitness);
this.blobGasUsed = blobGasUsed;
this.excessBlobGas = excessBlobGas;
}
Expand All @@ -99,6 +101,10 @@ public static ExecutionPayloadV3 fromInternalExecutionPayload(
executionPayload.getBlockHash(),
executionPayload.getTransactions().stream().map(SszByteListImpl::getBytes).toList(),
withdrawalsList,
executionPayload
.toVersionDeneb()
.map(denebPayload -> denebPayload.getExecutionWitness().sszSerialize())
.orElse(null),
executionPayload.toVersionDeneb().map(ExecutionPayloadDeneb::getBlobGasUsed).orElse(null),
executionPayload
.toVersionDeneb()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Consensys Software Inc., 2022
*
* 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.
*/

package tech.pegasys.teku.ethereum.executionclient.serialization;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
import tech.pegasys.teku.infrastructure.bytes.Bytes31;

public class Bytes31Deserializer extends JsonDeserializer<Bytes31> {

@Override
public Bytes31 deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return Bytes31.fromHexString(p.getValueAsString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Consensys Software Inc., 2022
*
* 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.
*/

package tech.pegasys.teku.ethereum.executionclient.serialization;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.util.Locale;
import tech.pegasys.teku.infrastructure.bytes.Bytes31;

public class Bytes31Serializer extends JsonSerializer<Bytes31> {
@Override
public void serialize(Bytes31 value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
gen.writeString(value.toHexString().toLowerCase(Locale.ROOT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadStatusV1;
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes20Deserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes20Serializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes31Deserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes31Serializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes32Deserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes8Deserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.BytesSerializer;
Expand All @@ -48,6 +50,7 @@
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt64AsHexDeserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt64AsHexSerializer;
import tech.pegasys.teku.infrastructure.bytes.Bytes20;
import tech.pegasys.teku.infrastructure.bytes.Bytes31;
import tech.pegasys.teku.infrastructure.bytes.Bytes8;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.SpecMilestone;
Expand Down Expand Up @@ -100,6 +103,21 @@ void shouldSerializeDeserializeBytes20() throws IOException {
assertThat(originalBytes20).isEqualTo(result);
}

@TestTemplate
void shouldSerializeDeserializeBytes31() throws IOException {
final Bytes31 originalBytes31 = dataStructureUtil.randomBytes31();

new Bytes31Serializer().serialize(originalBytes31, jsonGenerator, serializerProvider);
jsonGenerator.flush();

final JsonParser parser = prepareDeserializationContext(jsonWriter.toString());
final Bytes31Deserializer deserializer = new Bytes31Deserializer();
final Bytes31 result =
deserializer.deserialize(parser, objectMapper.getDeserializationContext());

assertThat(originalBytes31).isEqualTo(result);
}

@TestTemplate
void shouldSerializeDeserializeBytes32() throws IOException {
Bytes32 originalBytes32 = dataStructureUtil.randomBytes32();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ private ExecutionPayloadHeader createExecutionPayloadHeaderWithGasLimit(
.blockHash(Bytes32.random())
.transactionsRoot(Bytes32.ZERO)
.withdrawalsRoot(() -> Bytes32.ZERO)
.executionWitnessRoot(() -> Bytes32.ZERO)
.blobGasUsed(() -> UInt64.ONE)
.excessBlobGas(() -> UInt64.ONE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,24 @@ public int getMaxValidatorsPerWithdrawalSweep() {
public int getMaxBlsToExecutionChanges() {
return specConfigCapella.getMaxBlsToExecutionChanges();
}

@Override
public int getMaxStems() {
return specConfigCapella.getMaxStems();
}

@Override
public int getMaxCommitmentsPerStem() {
return specConfigCapella.getMaxCommitmentsPerStem();
}

@Override
public int getVerkleWidth() {
return specConfigCapella.getVerkleWidth();
}

@Override
public int getIpaProofDepth() {
return specConfigCapella.getIpaProofDepth();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ static SpecConfigCapella required(SpecConfig specConfig) {
int getMaxWithdrawalsPerPayload();

int getMaxValidatorsPerWithdrawalSweep();

/**
* Experimental feature: `Verkle trees` as of
* https://github.com/ethereum/consensus-specs/pull/3230/
*/
int getMaxStems();

int getMaxCommitmentsPerStem();

int getVerkleWidth();

int getIpaProofDepth();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,32 @@ public class SpecConfigCapellaImpl extends DelegatingSpecConfigBellatrix
private final int maxWithdrawalsPerPayload;
private final int maxValidatorsPerWithdrawalSweep;

private final int maxStems;
private final int maxCommitmentsPerStem;
private final int verkleWidth;
private final int ipaProofDepth;

public SpecConfigCapellaImpl(
final SpecConfigBellatrix specConfig,
final Bytes4 capellaForkVersion,
final UInt64 capellaForkEpoch,
final int maxBlsToExecutionChanges,
final int maxWithdrawalsPerPayload,
final int maxValidatorsPerWithdrawalSweep) {
final int maxValidatorsPerWithdrawalSweep,
final int maxStems,
final int maxCommitmentsPerStem,
final int verkleWidth,
final int ipaProofDepth) {
super(specConfig);
this.capellaForkVersion = capellaForkVersion;
this.capellaForkEpoch = capellaForkEpoch;
this.maxBlsToExecutionChanges = maxBlsToExecutionChanges;
this.maxWithdrawalsPerPayload = maxWithdrawalsPerPayload;
this.maxValidatorsPerWithdrawalSweep = maxValidatorsPerWithdrawalSweep;
this.maxStems = maxStems;
this.maxCommitmentsPerStem = maxCommitmentsPerStem;
this.verkleWidth = verkleWidth;
this.ipaProofDepth = ipaProofDepth;
}

@Override
Expand All @@ -67,7 +80,11 @@ public boolean equals(final Object o) {
&& Objects.equals(capellaForkEpoch, that.capellaForkEpoch)
&& maxBlsToExecutionChanges == that.maxBlsToExecutionChanges
&& maxWithdrawalsPerPayload == that.maxWithdrawalsPerPayload
&& maxValidatorsPerWithdrawalSweep == that.maxValidatorsPerWithdrawalSweep;
&& maxValidatorsPerWithdrawalSweep == that.maxValidatorsPerWithdrawalSweep
&& maxStems == that.maxStems
&& maxCommitmentsPerStem == that.maxCommitmentsPerStem
&& verkleWidth == that.verkleWidth
&& ipaProofDepth == that.ipaProofDepth;
}

@Override
Expand All @@ -78,7 +95,11 @@ public int hashCode() {
capellaForkEpoch,
maxBlsToExecutionChanges,
maxWithdrawalsPerPayload,
maxValidatorsPerWithdrawalSweep);
maxValidatorsPerWithdrawalSweep,
maxStems,
maxCommitmentsPerStem,
verkleWidth,
ipaProofDepth);
}

@Override
Expand All @@ -96,6 +117,26 @@ public int getMaxValidatorsPerWithdrawalSweep() {
return maxValidatorsPerWithdrawalSweep;
}

@Override
public int getMaxStems() {
return maxStems;
}

@Override
public int getMaxCommitmentsPerStem() {
return maxCommitmentsPerStem;
}

@Override
public int getVerkleWidth() {
return verkleWidth;
}

@Override
public int getIpaProofDepth() {
return ipaProofDepth;
}

@Override
public Optional<SpecConfigCapella> toVersionCapella() {
return Optional.of(this);
Expand Down
Loading
Loading