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

Create MiscHelpersEip4844 #6474

Merged
merged 10 commits into from
Nov 22, 2022
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.execution.versions.eip4844;

import tech.pegasys.teku.infrastructure.bytes.Bytes20;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.collections.SszByteVector;
import tech.pegasys.teku.infrastructure.ssz.containers.Container2;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszByteVectorSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;

public class AccessTuple extends Container2<AccessTuple, SszByteVector, SszList<SszBytes32>> {

private static final long MAX_ACCESS_LIST_STORAGE_KEYS = 16777216; // 2**24

public static class AccessTupleSchema
extends ContainerSchema2<AccessTuple, SszByteVector, SszList<SszBytes32>> {

public AccessTupleSchema() {
super(
"AccessTuple",
namedSchema("address", SszByteVectorSchema.create(Bytes20.SIZE)),
namedSchema(
"storage_keys",
SszListSchema.create(
SszPrimitiveSchemas.BYTES32_SCHEMA, MAX_ACCESS_LIST_STORAGE_KEYS)));
}

@SuppressWarnings("unchecked")
public SszListSchema<SszBytes32, ?> getStorageKeysSchema() {
return (SszListSchema<SszBytes32, ?>) getFieldSchema1();
}

@Override
public AccessTuple createFromBackingNode(TreeNode node) {
return new AccessTuple(this, node);
}
}

public static final AccessTuple.AccessTupleSchema SSZ_SCHEMA =
new AccessTuple.AccessTupleSchema();

AccessTuple(final AccessTupleSchema type, final TreeNode backingNode) {
super(type, backingNode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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.execution.versions.eip4844;

import java.util.List;
import java.util.stream.Collectors;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.SszUnion;
import tech.pegasys.teku.infrastructure.ssz.collections.SszByteList;
import tech.pegasys.teku.infrastructure.ssz.containers.Container11;
import tech.pegasys.teku.infrastructure.ssz.impl.AbstractSszPrimitive;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt256;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;

public class BlobTransaction
extends Container11<
BlobTransaction,
SszUInt256,
SszUInt64,
SszUInt256,
SszUInt256,
SszUInt64,
SszUnion,
SszUInt256,
SszByteList,
SszList<AccessTuple>,
SszUInt256,
SszList<SszBytes32>> {

BlobTransaction(final BlobTransactionSchema type, final TreeNode backingNode) {
super(type, backingNode);
}

public BlobTransaction(
final BlobTransactionSchema schema,
final SszUInt256 chainId,
final SszUInt64 nonce,
final SszUInt256 maxPriorityFeePerGas,
final SszUInt256 maxFeePerGas,
final SszUInt64 gas,
final SszUnion to,
final SszUInt256 value,
final SszByteList data,
final SszList<AccessTuple> accessList,
final SszUInt256 maxFeePerDataGas,
final SszList<SszBytes32> blobVersionedHashes) {
super(
schema,
chainId,
nonce,
maxPriorityFeePerGas,
maxFeePerGas,
gas,
to,
value,
data,
accessList,
maxFeePerDataGas,
blobVersionedHashes);
}

public static final BlobTransactionSchema SSZ_SCHEMA = new BlobTransactionSchema();

public List<Bytes32> getBlobVersionedHashes() {
return getField10().stream().map(AbstractSszPrimitive::get).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.execution.versions.eip4844;

import java.util.List;
import tech.pegasys.teku.infrastructure.bytes.Bytes20;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.SszUnion;
import tech.pegasys.teku.infrastructure.ssz.collections.SszByteList;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema11;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt256;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.schema.SszUnionSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszByteListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszByteVectorSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;

public class BlobTransactionSchema
extends ContainerSchema11<
BlobTransaction,
SszUInt256,
SszUInt64,
SszUInt256,
SszUInt256,
SszUInt64,
SszUnion,
SszUInt256,
SszByteList,
SszList<AccessTuple>,
SszUInt256,
SszList<SszBytes32>> {

private static final long MAX_VERSIONED_HASHES_LIST_SIZE = 16777216; // 2**24
private static final long MAX_CALLDATA_SIZE = 16777216; // 2**24
private static final long MAX_ACCESS_LIST_SIZE = 16777216; // 2**24

BlobTransactionSchema() {
super(
"BlobTransaction",
namedSchema("chain_id", SszPrimitiveSchemas.UINT256_SCHEMA),
namedSchema("nonce", SszPrimitiveSchemas.UINT64_SCHEMA),
namedSchema("max_priority_fee_per_gas", SszPrimitiveSchemas.UINT256_SCHEMA),
namedSchema("max_fee_per_gas", SszPrimitiveSchemas.UINT256_SCHEMA),
namedSchema("gas", SszPrimitiveSchemas.UINT64_SCHEMA),
namedSchema(
"to",
SszUnionSchema.create(
List.of(
SszPrimitiveSchemas.NONE_SCHEMA, SszByteVectorSchema.create(Bytes20.SIZE)))),
namedSchema("value", SszPrimitiveSchemas.UINT256_SCHEMA),
namedSchema("data", SszByteListSchema.create(MAX_CALLDATA_SIZE)),
namedSchema(
"access_list", SszListSchema.create(AccessTuple.SSZ_SCHEMA, MAX_ACCESS_LIST_SIZE)),
namedSchema("max_fee_per_data_gas", SszPrimitiveSchemas.UINT256_SCHEMA),
namedSchema(
"blob_versioned_hashes",
SszListSchema.create(
SszPrimitiveSchemas.BYTES32_SCHEMA, MAX_VERSIONED_HASHES_LIST_SIZE)));
}

@Override
public BlobTransaction createFromBackingNode(final TreeNode node) {
return new BlobTransaction(this, node);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.execution.versions.eip4844;

import tech.pegasys.teku.infrastructure.ssz.containers.Container3;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema3;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBit;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt256;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;

public class ECDSASignature extends Container3<ECDSASignature, SszBit, SszUInt256, SszUInt256> {

public static class ECDSASignatureSchema
extends ContainerSchema3<ECDSASignature, SszBit, SszUInt256, SszUInt256> {

public ECDSASignatureSchema() {
super(
"ECDSASignature",
namedSchema("y_parity", SszPrimitiveSchemas.BIT_SCHEMA),
namedSchema("r", SszPrimitiveSchemas.UINT256_SCHEMA),
namedSchema("s", SszPrimitiveSchemas.UINT256_SCHEMA));
}

@Override
public ECDSASignature createFromBackingNode(TreeNode node) {
return new ECDSASignature(this, node);
}
}

public static final ECDSASignature.ECDSASignatureSchema SSZ_SCHEMA =
new ECDSASignature.ECDSASignatureSchema();

ECDSASignature(final ECDSASignatureSchema type, final TreeNode backingNode) {
super(type, backingNode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.execution.versions.eip4844;

import tech.pegasys.teku.infrastructure.ssz.containers.Container2;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;

public class SignedBlobTransaction
extends Container2<SignedBlobTransaction, BlobTransaction, ECDSASignature> {

public static class SignedBlobTransactionSchema
extends ContainerSchema2<SignedBlobTransaction, BlobTransaction, ECDSASignature> {

public SignedBlobTransactionSchema() {
super(
"SignedBlobTransaction",
namedSchema("message", BlobTransaction.SSZ_SCHEMA),
namedSchema("signature", ECDSASignature.SSZ_SCHEMA));
}

@Override
public SignedBlobTransaction createFromBackingNode(TreeNode node) {
return new SignedBlobTransaction(this, node);
}
}

public BlobTransaction getBlobTransaction() {
return getField0();
}

public static final SignedBlobTransaction.SignedBlobTransactionSchema SSZ_SCHEMA =
new SignedBlobTransaction.SignedBlobTransactionSchema();

SignedBlobTransaction(final SignedBlobTransactionSchema type, final TreeNode backingNode) {
super(type, backingNode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import tech.pegasys.teku.spec.logic.versions.altair.util.AttestationUtilAltair;
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.helpers.MiscHelpersBellatrix;
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.capella.forktransition.CapellaStateUpgrade;
import tech.pegasys.teku.spec.logic.versions.capella.helpers.MiscHelpersCapella;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsCapella;

public class SpecLogicCapella extends AbstractSpecLogic {
Expand All @@ -44,7 +44,7 @@ public class SpecLogicCapella extends AbstractSpecLogic {

private SpecLogicCapella(
final Predicates predicates,
final MiscHelpersBellatrix miscHelpers,
final MiscHelpersCapella miscHelpers,
final BeaconStateAccessorsAltair beaconStateAccessors,
final BeaconStateMutatorsBellatrix beaconStateMutators,
final OperationSignatureVerifier operationSignatureVerifier,
Expand Down Expand Up @@ -86,7 +86,7 @@ public static SpecLogicCapella create(
final SpecConfigCapella config, final SchemaDefinitionsCapella schemaDefinitions) {
// Helpers
final Predicates predicates = new Predicates(config);
final MiscHelpersBellatrix miscHelpers = new MiscHelpersBellatrix(config);
final MiscHelpersCapella miscHelpers = new MiscHelpersCapella(config);
zilm13 marked this conversation as resolved.
Show resolved Hide resolved
final BeaconStateAccessorsAltair beaconStateAccessors =
new BeaconStateAccessorsAltair(config, predicates, miscHelpers);
final BeaconStateMutatorsBellatrix beaconStateMutators =
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.logic.versions.capella.helpers;

import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.logic.versions.bellatrix.helpers.MiscHelpersBellatrix;

public class MiscHelpersCapella extends MiscHelpersBellatrix {

public MiscHelpersCapella(final SpecConfig specConfig) {
super(specConfig);
}
}
Loading