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

Add BlindBlockUtil for EIP-4844 #6532

Merged
merged 5 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -17,13 +17,15 @@
import tech.pegasys.teku.api.schema.altair.SignedBeaconBlockAltair;
import tech.pegasys.teku.api.schema.bellatrix.SignedBlindedBeaconBlockBellatrix;
import tech.pegasys.teku.api.schema.capella.SignedBlindedBeaconBlockCapella;
import tech.pegasys.teku.api.schema.eip4844.SignedBlindedBeaconBlockEip4844;
import tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0;

@Schema(
oneOf = {
SignedBeaconBlockPhase0.class,
SignedBeaconBlockAltair.class,
SignedBlindedBeaconBlockBellatrix.class,
SignedBlindedBeaconBlockCapella.class
SignedBlindedBeaconBlockCapella.class,
SignedBlindedBeaconBlockEip4844.class
})
public interface SignedBlindedBlock {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import tech.pegasys.teku.api.schema.altair.SignedBeaconBlockAltair;
import tech.pegasys.teku.api.schema.bellatrix.SignedBeaconBlockBellatrix;
import tech.pegasys.teku.api.schema.capella.SignedBeaconBlockCapella;
import tech.pegasys.teku.api.schema.eip4844.SignedBeaconBlockEip4844;
import tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0;

@Schema(
oneOf = {
SignedBeaconBlockPhase0.class,
SignedBeaconBlockAltair.class,
SignedBeaconBlockBellatrix.class,
SignedBeaconBlockCapella.class
SignedBeaconBlockCapella.class,
SignedBeaconBlockEip4844.class
})
public interface SignedBlock {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import tech.pegasys.teku.api.schema.altair.BeaconStateAltair;
import tech.pegasys.teku.api.schema.bellatrix.BeaconStateBellatrix;
import tech.pegasys.teku.api.schema.capella.BeaconStateCapella;
import tech.pegasys.teku.api.schema.eip4844.BeaconStateEip4844;
import tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0;

@Schema(
oneOf = {
BeaconStatePhase0.class,
BeaconStateAltair.class,
BeaconStateBellatrix.class,
BeaconStateCapella.class
BeaconStateCapella.class,
BeaconStateEip4844.class
})
public interface State {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import tech.pegasys.teku.api.schema.altair.BeaconBlockAltair;
import tech.pegasys.teku.api.schema.bellatrix.BlindedBlockBellatrix;
import tech.pegasys.teku.api.schema.capella.BlindedBlockCapella;
import tech.pegasys.teku.api.schema.eip4844.BlindedBlockEip4844;
import tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0;

@Schema(
oneOf = {
BeaconBlockPhase0.class,
BeaconBlockAltair.class,
BlindedBlockBellatrix.class,
BlindedBlockCapella.class
BlindedBlockCapella.class,
BlindedBlockEip4844.class
})
public interface UnsignedBlindedBlock {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

package tech.pegasys.teku.spec.datastructures.blocks.blockbody.common;

import static com.google.common.base.Preconditions.checkState;

import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockBlinder;
import tech.pegasys.teku.spec.schemas.SchemaDefinitions;

Expand All @@ -22,4 +25,17 @@ public abstract class AbstractSignedBeaconBlockBlinder implements SignedBeaconBl
public AbstractSignedBeaconBlockBlinder(final SchemaDefinitions schemaDefinitions) {
this.schemaDefinitions = schemaDefinitions;
}

@Override
public SignedBeaconBlock blind(SignedBeaconBlock signedUnblindedBock) {
final SignedBeaconBlock blindedSignedBeaconBlock = signedUnblindedBock.blind(schemaDefinitions);
checkState(
blindedSignedBeaconBlock
.getMessage()
.hashTreeRoot()
.equals(signedUnblindedBock.getMessage().hashTreeRoot()),
"blinded block root do not match original unblinded block root");

return blindedSignedBeaconBlock;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,12 @@

package tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.bellatrix;

import static com.google.common.base.Preconditions.checkState;

import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.common.AbstractSignedBeaconBlockBlinder;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix;

public class SignedBeaconBlockBlinderBellatrix extends AbstractSignedBeaconBlockBlinder {
public SignedBeaconBlockBlinderBellatrix(SchemaDefinitionsBellatrix schemaDefinitions) {
super(schemaDefinitions);
}

@Override
public SignedBeaconBlock blind(SignedBeaconBlock signedUnblindedBock) {
final BeaconBlockBodyBellatrixImpl unblindedBlockBody =
BeaconBlockBodyBellatrixImpl.required(signedUnblindedBock.getMessage().getBody());

final BlindedBeaconBlockBodySchemaBellatrixImpl schema =
(BlindedBeaconBlockBodySchemaBellatrixImpl)
schemaDefinitions.getBlindedBeaconBlockBodySchema();

final BlindedBeaconBlockBodyBellatrixImpl blindedBody =
new BlindedBeaconBlockBodyBellatrixImpl(
schema,
unblindedBlockBody.getRandaoRevealSsz(),
unblindedBlockBody.getEth1Data(),
unblindedBlockBody.getGraffitiSsz(),
unblindedBlockBody.getProposerSlashings(),
unblindedBlockBody.getAttesterSlashings(),
unblindedBlockBody.getAttestations(),
unblindedBlockBody.getDeposits(),
unblindedBlockBody.getVoluntaryExits(),
unblindedBlockBody.getSyncAggregate(),
schema
.getExecutionPayloadHeaderSchema()
.createFromExecutionPayload(unblindedBlockBody.getExecutionPayload()));

final BeaconBlock blindedBeaconBlock =
schemaDefinitions
.getBlindedBeaconBlockSchema()
.create(
signedUnblindedBock.getSlot(),
signedUnblindedBock.getProposerIndex(),
signedUnblindedBock.getParentRoot(),
signedUnblindedBock.getStateRoot(),
blindedBody);

checkState(
blindedBeaconBlock.hashTreeRoot().equals(signedUnblindedBock.getMessage().hashTreeRoot()),
"blinded block root do not match original unblinded block root");

return schemaDefinitions
.getSignedBlindedBeaconBlockSchema()
.create(blindedBeaconBlock, signedUnblindedBock.getSignature());
public SignedBeaconBlockBlinderBellatrix(final SchemaDefinitionsBellatrix schemaDefinitions) {
super(schemaDefinitions.toVersionBellatrix().orElseThrow());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip4844;

import static com.google.common.base.Preconditions.checkArgument;

import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.bls.BLSSignature;
Expand All @@ -21,6 +23,7 @@
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
import tech.pegasys.teku.spec.datastructures.execution.versions.eip4844.ExecutionPayloadEip4844;
import tech.pegasys.teku.spec.datastructures.execution.versions.eip4844.ExecutionPayloadEip4844Impl;
Expand Down Expand Up @@ -89,6 +92,14 @@ public class BeaconBlockBodyEip4844Impl
super(type, backingNode);
}

public static BeaconBlockBodyEip4844Impl required(final BeaconBlockBody body) {
checkArgument(
body instanceof BeaconBlockBodyEip4844Impl,
"Expected EIP-4844 block body but got %s",
body.getClass());
return (BeaconBlockBodyEip4844Impl) body;
}

@Override
public BLSSignature getRandaoReveal() {
return getField0().getSignature();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.spec.datastructures.blocks.blockbody.versions.eip4844;

import tech.pegasys.teku.spec.datastructures.blocks.blockbody.common.AbstractSignedBeaconBlockBlinder;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsEip4844;

public class SignedBeaconBlockBlinderEip4844 extends AbstractSignedBeaconBlockBlinder {

public SignedBeaconBlockBlinderEip4844(final SchemaDefinitionsEip4844 schemaDefinitions) {
super(schemaDefinitions.toVersionEip4844().orElseThrow());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.spec.datastructures.blocks.blockbody.versions.eip4844;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;

import java.util.function.Supplier;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.common.AbstractSignedBeaconBlockUnblinder;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.versions.eip4844.ExecutionPayloadEip4844;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix;

public class SignedBeaconBlockUnblinderEip4844 extends AbstractSignedBeaconBlockUnblinder {
protected SafeFuture<ExecutionPayload> executionPayloadFuture;

public SignedBeaconBlockUnblinderEip4844(
final SchemaDefinitionsBellatrix schemaDefinitions,
final SignedBeaconBlock signedBlindedBeaconBlock) {
super(schemaDefinitions, signedBlindedBeaconBlock);
}

@Override
public void setExecutionPayloadSupplier(
final Supplier<SafeFuture<ExecutionPayload>> executionPayloadSupplier) {
this.executionPayloadFuture = executionPayloadSupplier.get();
}

@Override
public SafeFuture<SignedBeaconBlock> unblind() {
BeaconBlock blindedBeaconBlock = signedBlindedBeaconBlock.getMessage();
if (!blindedBeaconBlock.getBody().isBlinded()) {
return SafeFuture.completedFuture(signedBlindedBeaconBlock);
}

checkNotNull(executionPayloadFuture, "executionPayload must be set");

return executionPayloadFuture.thenApply(
executionPayload -> {
ExecutionPayloadEip4844.required(executionPayload);
final BlindedBeaconBlockBodyEip4844 blindedBody =
BlindedBeaconBlockBodyEip4844.required(blindedBeaconBlock.getBody());
checkState(
executionPayload
.hashTreeRoot()
.equals(blindedBody.getExecutionPayloadHeader().hashTreeRoot()),
"executionPayloadHeader root in blinded block do not match provided executionPayload root");
return signedBlindedBeaconBlock.unblind(schemaDefinitions, executionPayload);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
import tech.pegasys.teku.spec.logic.versions.bellatrix.helpers.BeaconStateMutatorsBellatrix;
import tech.pegasys.teku.spec.logic.versions.bellatrix.helpers.BellatrixTransitionHelpers;
import tech.pegasys.teku.spec.logic.versions.bellatrix.statetransition.epoch.EpochProcessorBellatrix;
import tech.pegasys.teku.spec.logic.versions.bellatrix.util.BlindBlockUtilBellatrix;
import tech.pegasys.teku.spec.logic.versions.capella.block.BlockProcessorCapella;
import tech.pegasys.teku.spec.logic.versions.eip4844.block.BlockProcessorEip4844;
import tech.pegasys.teku.spec.logic.versions.eip4844.forktransition.Eip4844StateUpgrade;
import tech.pegasys.teku.spec.logic.versions.eip4844.helpers.MiscHelpersEip4844;
import tech.pegasys.teku.spec.logic.versions.eip4844.util.BlindBlockUtilEip4844;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsEip4844;

public class SpecLogicEip4844 extends AbstractSpecLogic {
Expand Down Expand Up @@ -146,7 +146,7 @@ public static SpecLogicEip4844 create(
final BlockProposalUtil blockProposalUtil =
new BlockProposalUtil(schemaDefinitions, blockProcessor);

final BlindBlockUtilBellatrix blindBlockUtil = new BlindBlockUtilBellatrix(schemaDefinitions);
final BlindBlockUtilEip4844 blindBlockUtil = new BlindBlockUtilEip4844(schemaDefinitions);

// State upgrade
final Eip4844StateUpgrade stateUpgrade =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.spec.logic.versions.eip4844.util;

import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockBlinder;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockUnblinder;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip4844.SignedBeaconBlockBlinderEip4844;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip4844.SignedBeaconBlockUnblinderEip4844;
import tech.pegasys.teku.spec.logic.common.util.BlindBlockUtil;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsEip4844;

public class BlindBlockUtilEip4844 extends BlindBlockUtil {
private final SchemaDefinitionsEip4844 schemaDefinitions;
private final SignedBeaconBlockBlinder signedBeaconBlockBlinder;

public BlindBlockUtilEip4844(final SchemaDefinitionsEip4844 schemaDefinitions) {
this.schemaDefinitions = schemaDefinitions;
this.signedBeaconBlockBlinder = new SignedBeaconBlockBlinderEip4844(schemaDefinitions);
}

@Override
protected SignedBeaconBlockUnblinder createSignedBeaconBlockUnblinder(
final SignedBeaconBlock signedBeaconBlock) {
return new SignedBeaconBlockUnblinderEip4844(schemaDefinitions, signedBeaconBlock);
}

@Override
protected SignedBeaconBlockBlinder getSignedBeaconBlockBlinder() {
return signedBeaconBlockBlinder;
}
}
Loading