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

Eip4844 types #6421

Merged
merged 4 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions ethereum/spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
implementation project(':infrastructure:events')
implementation project(':infrastructure:exceptions')
implementation project(':infrastructure:io')
implementation project(':infrastructure:kzg')
implementation project(':infrastructure:logging')
implementation project(':infrastructure:ssz')
implementation project(':infrastructure:time')
Expand All @@ -45,6 +46,7 @@ dependencies {
testFixturesImplementation project(':infrastructure:crypto')
testFixturesImplementation project(':infrastructure:events')
testFixturesImplementation project(':infrastructure:io')
testFixturesImplementation project(':infrastructure:kzg')
testFixturesImplementation project(':infrastructure:time')
testFixturesImplementation project(':infrastructure:unsigned')
testFixturesImplementation testFixtures(project(':infrastructure:async'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public interface SpecConfigEip4844 extends SpecConfigCapella {
Bytes BLOB_TX_TYPE = Bytes.fromHexString("0x05");
Bytes VERSIONED_HASH_VERSION_KZG = Bytes.fromHexString("0x01");
UInt64 BYTES_PER_FIELD_ELEMENT = UInt64.valueOf(32);

static SpecConfigEip4844 required(final SpecConfig specConfig) {
return specConfig
Expand Down
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.spec.datastructures.execution.versions.eip4844;

import tech.pegasys.teku.infrastructure.ssz.collections.impl.SszByteVectorImpl;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;

public class Blob extends SszByteVectorImpl {

Blob(BlobSchema schema, TreeNode backingNode) {
super(schema, backingNode);
}

@Override
public BlobSchema getSchema() {
return (BlobSchema) super.getSchema();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.impl.SszByteVectorSchemaImpl;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.config.SpecConfigEip4844;

public class BlobSchema extends SszByteVectorSchemaImpl<Blob> {

public BlobSchema(final SpecConfigEip4844 specConfig) {
super(
SszPrimitiveSchemas.BYTE_SCHEMA,
SpecConfigEip4844.BYTES_PER_FIELD_ELEMENT
.times(specConfig.getFieldElementsPerBlob())
.longValue());
}

@Override
public Blob createFromBackingNode(TreeNode node) {
return new Blob(this, node);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.type;

import com.google.common.base.Suppliers;
import java.util.function.Supplier;
import org.apache.tuweni.bytes.Bytes48;
import tech.pegasys.teku.infrastructure.ssz.collections.impl.SszByteVectorImpl;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.kzg.KZGCommitment;

public class SszKZGCommitment extends SszByteVectorImpl {

private final Supplier<KZGCommitment> kzgCommitment;

public SszKZGCommitment(final Bytes48 kzgCommitmentBytes) {
super(SszKZGCommitmentSchema.INSTANCE, kzgCommitmentBytes);
this.kzgCommitment = Suppliers.memoize(this::createKZGCommitment);
}

public SszKZGCommitment(final KZGCommitment kzgCommitment) {
super(SszKZGCommitmentSchema.INSTANCE, kzgCommitment.getBytesCompressed());
this.kzgCommitment = Suppliers.memoize(this::createKZGCommitment);
}

SszKZGCommitment(final TreeNode backingNode) {
super(SszKZGCommitmentSchema.INSTANCE, backingNode);
this.kzgCommitment = Suppliers.memoize(this::createKZGCommitment);
}

public KZGCommitment getKZGCommitment() {
return kzgCommitment.get();
}

private KZGCommitment createKZGCommitment() {
return KZGCommitment.fromBytesCompressed(getBytes());
}

@Override
public Bytes48 getBytes() {
return Bytes48.wrap(super.getBytes());
}

@Override
public SszKZGCommitmentSchema getSchema() {
return (SszKZGCommitmentSchema) super.getSchema();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.type;

import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.impl.SszByteVectorSchemaImpl;
import tech.pegasys.teku.infrastructure.ssz.schema.json.SszPrimitiveTypeDefinitions;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;

public class SszKZGCommitmentSchema extends SszByteVectorSchemaImpl<SszKZGCommitment> {
private static final int KZG_COMMITMENT_SIZE = 48;

public static final SszKZGCommitmentSchema INSTANCE = new SszKZGCommitmentSchema();

private SszKZGCommitmentSchema() {
super(SszPrimitiveSchemas.BYTE_SCHEMA, KZG_COMMITMENT_SIZE);
}

@Override
protected DeserializableTypeDefinition<SszKZGCommitment> createTypeDefinition() {
return SszPrimitiveTypeDefinitions.sszSerializedType(this, "Bytes48 hexadecimal");
}

@Override
public SszKZGCommitment createFromBackingNode(final TreeNode node) {
return new SszKZGCommitment(node);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.type;

import com.google.common.base.Suppliers;
import java.util.function.Supplier;
import org.apache.tuweni.bytes.Bytes48;
import tech.pegasys.teku.infrastructure.ssz.collections.impl.SszByteVectorImpl;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.kzg.KZGProof;

public class SszKZGProof extends SszByteVectorImpl {

private final Supplier<KZGProof> kzgProof;

public SszKZGProof(final Bytes48 kzgProofBytes) {
super(SszKZGProofSchema.INSTANCE, kzgProofBytes);
this.kzgProof = Suppliers.memoize(this::createKZGProof);
}

public SszKZGProof(final KZGProof kzgProof) {
super(SszKZGProofSchema.INSTANCE, kzgProof.getBytesCompressed());
this.kzgProof = Suppliers.memoize(this::createKZGProof);
}

SszKZGProof(final TreeNode backingNode) {
super(SszKZGProofSchema.INSTANCE, backingNode);
this.kzgProof = Suppliers.memoize(this::createKZGProof);
}

public KZGProof getKZGProof() {
return kzgProof.get();
}

private KZGProof createKZGProof() {
return KZGProof.fromBytesCompressed(getBytes());
}

@Override
public Bytes48 getBytes() {
return Bytes48.wrap(super.getBytes());
}

@Override
public SszKZGProofSchema getSchema() {
return (SszKZGProofSchema) super.getSchema();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.type;

import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.impl.SszByteVectorSchemaImpl;
import tech.pegasys.teku.infrastructure.ssz.schema.json.SszPrimitiveTypeDefinitions;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;

public class SszKZGProofSchema extends SszByteVectorSchemaImpl<SszKZGProof> {
private static final int KZG_PROOF_SIZE = 48;

public static final SszKZGProofSchema INSTANCE = new SszKZGProofSchema();

private SszKZGProofSchema() {
super(SszPrimitiveSchemas.BYTE_SCHEMA, KZG_PROOF_SIZE);
}

@Override
protected DeserializableTypeDefinition<SszKZGProof> createTypeDefinition() {
return SszPrimitiveTypeDefinitions.sszSerializedType(this, "Bytes48 hexadecimal");
}

@Override
public SszKZGProof createFromBackingNode(final TreeNode node) {
return new SszKZGProof(node);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.type;

import static tech.pegasys.teku.spec.datastructures.util.PropertyTestHelper.assertDeserializeMutatedThrowsExpected;
import static tech.pegasys.teku.spec.datastructures.util.PropertyTestHelper.assertRoundTrip;

import com.fasterxml.jackson.core.JsonProcessingException;
import net.jqwik.api.ForAll;
import net.jqwik.api.Property;

public class SszKZGCommitmentPropertyTest {
@Property
void roundTrip(
@ForAll(supplier = SszKZGCommitmentSupplier.class) final SszKZGCommitment sszKZGCommitment)
throws JsonProcessingException {
assertRoundTrip(sszKZGCommitment);
}

@Property
void deserializeMutated(
@ForAll(supplier = SszKZGCommitmentSupplier.class) final SszKZGCommitment sszKZGCommitment,
@ForAll final int seed) {
assertDeserializeMutatedThrowsExpected(sszKZGCommitment, seed);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.type;

import tech.pegasys.teku.spec.propertytest.suppliers.DataStructureUtilSupplier;
import tech.pegasys.teku.spec.util.DataStructureUtil;

public class SszKZGCommitmentSupplier extends DataStructureUtilSupplier<SszKZGCommitment> {
public SszKZGCommitmentSupplier() {
super(DataStructureUtil::randomSszKZGCommitment);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.type;

import static tech.pegasys.teku.spec.datastructures.util.PropertyTestHelper.assertDeserializeMutatedThrowsExpected;
import static tech.pegasys.teku.spec.datastructures.util.PropertyTestHelper.assertRoundTrip;

import com.fasterxml.jackson.core.JsonProcessingException;
import net.jqwik.api.ForAll;
import net.jqwik.api.Property;

public class SszKZGProofPropertyTest {
@Property
void roundTrip(@ForAll(supplier = SszKZGProofSupplier.class) final SszKZGProof sszKZGProof)
throws JsonProcessingException {
assertRoundTrip(sszKZGProof);
}

@Property
void deserializeMutated(
@ForAll(supplier = SszKZGProofSupplier.class) final SszKZGProof sszKZGProof,
@ForAll final int seed) {
assertDeserializeMutatedThrowsExpected(sszKZGProof, seed);
}
}
Loading