Skip to content

Commit

Permalink
Updated consolidation rules for devnet5
Browse files Browse the repository at this point in the history
 - updated fuzzUtil to use prettyJson to report diffs for the tests that broke...

 - currently the fuzz utils need some changes, will just raise a draft until we're ready...

fixes Consensys#8875

Signed-off-by: Paul Harris <paul.harris@consensys.net>
  • Loading branch information
rolfyone committed Dec 3, 2024
1 parent 5aa4bd8 commit 1ff5f21
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ private void processConsolidationRequest(
return;
}

// Verify that target has execution withdrawal credentials
if (!predicatesElectra.hasExecutionWithdrawalCredential(targetValidator)) {
// Verify that target has compounding withdrawal credentials
if (!predicatesElectra.hasCompoundingWithdrawalCredential(targetValidator)) {
LOG.debug("process_consolidation_request: invalid target credentials");
return;
}
Expand Down Expand Up @@ -545,11 +545,6 @@ private void processConsolidationRequest(
SszUInt64.of(UInt64.valueOf(targetValidatorIndex)));
state.getPendingConsolidations().append(pendingConsolidation);

// Churn any target excess active balance of target and raise its max
if (predicatesElectra.hasEth1WithdrawalCredential(targetValidator)) {
beaconStateMutatorsElectra.switchToCompoundingValidator(state, targetValidatorIndex);
}

LOG.debug("process_consolidation_request: created {}", pendingConsolidation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MAX_ATTESTER_SLASHINGS_ELECTRA: 1
# `uint64(2**3)` (= 8)
MAX_ATTESTATIONS_ELECTRA: 8
# `uint64(2**0)` (= 1)
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 1
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 2

# Execution
# ---------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MAX_ATTESTER_SLASHINGS_ELECTRA: 1
# `uint64(2**3)` (= 8)
MAX_ATTESTATIONS_ELECTRA: 8
# `uint64(2**0)` (= 1)
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 1
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 2

# Execution
# ---------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MAX_ATTESTER_SLASHINGS_ELECTRA: 1
# `uint64(2**3)` (= 8)
MAX_ATTESTATIONS_ELECTRA: 8
# `uint64(2**0)` (= 1)
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 1
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 2

# Execution
# ---------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions fuzz/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dependencies {
api 'com.fasterxml.jackson.core:jackson-databind'
implementation project(':ethereum:networks')
implementation project(':ethereum:spec')
implementation testFixtures(project(':ethereum:spec'))
Expand All @@ -10,6 +11,7 @@ dependencies {

testImplementation 'org.xerial.snappy:snappy-java'
testImplementation testFixtures(project(':ethereum:spec'))
testImplementation project(':infrastructure:json')
}


Expand Down
38 changes: 24 additions & 14 deletions fuzz/src/test/java/tech/pegasys/teku/fuzz/FuzzUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
Expand All @@ -38,6 +39,7 @@
import tech.pegasys.teku.fuzz.input.SyncAggregateFuzzInput;
import tech.pegasys.teku.fuzz.input.VoluntaryExitFuzzInput;
import tech.pegasys.teku.fuzz.input.WithdrawalRequestFuzzInput;
import tech.pegasys.teku.infrastructure.json.JsonUtil;
import tech.pegasys.teku.infrastructure.ssz.SszData;
import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema;
import tech.pegasys.teku.spec.Spec;
Expand All @@ -62,6 +64,7 @@
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.electra.BeaconStateElectra;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.electra.BeaconStateSchemaElectra;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsElectra;

Expand Down Expand Up @@ -166,23 +169,26 @@ public void fuzzBlock_minimal() {
}

@Test
public void fuzzBlockHeader_minimal() {
public void fuzzBlockHeader_minimal() throws JsonProcessingException {
final FuzzUtil fuzzUtil = new FuzzUtil(false, true);

final Path testCaseDir =
Path.of("minimal/operations/block_header/pyspec_tests/basic_block_header");
final BeaconBlock data = loadSsz(testCaseDir.resolve("block.ssz_snappy"), beaconBlockSchema);
final BeaconState preState = loadSsz(testCaseDir.resolve("pre.ssz_snappy"), beaconStateSchema);
final BeaconState postState =
final BeaconStateElectra postState =
loadSsz(testCaseDir.resolve("post.ssz_snappy"), beaconStateSchema);

BlockHeaderFuzzInput input = new BlockHeaderFuzzInput(spec, preState, data);
byte[] rawInput = input.sszSerialize().toArrayUnsafe();
Optional<Bytes> result = fuzzUtil.fuzzBlockHeader(rawInput).map(Bytes::wrap);
final BlockHeaderFuzzInput input = new BlockHeaderFuzzInput(spec, preState, data);
final byte[] rawInput = input.sszSerialize().toArrayUnsafe();
final Optional<Bytes> result = fuzzUtil.fuzzBlockHeader(rawInput).map(Bytes::wrap);

Bytes expected = postState.sszSerialize();
assertThat(result).isNotEmpty();
assertThat(result.get()).isEqualTo(expected);
final BeaconStateElectra resultState =
BeaconStateElectra.required(
spec.getGenesisSchemaDefinitions().getBeaconStateSchema().sszDeserialize(result.get()));
assertThat(JsonUtil.prettySerialize(resultState, beaconStateSchema.getJsonTypeDefinition()))
.isEqualTo(JsonUtil.prettySerialize(postState, beaconStateSchema.getJsonTypeDefinition()));
}

@Test
Expand Down Expand Up @@ -377,7 +383,7 @@ public void fuzzWithdrawalRequest_minimal() {
}

@Test
public void fuzzConsolidationRequest_minimal() {
public void fuzzConsolidationRequest_minimal() throws JsonProcessingException {
final FuzzUtil fuzzUtil = new FuzzUtil(false, true);

final Path testCaseDir =
Expand All @@ -391,16 +397,20 @@ public void fuzzConsolidationRequest_minimal() {
.getConsolidationRequestsSchema()
.getElementSchema());
final BeaconState preState = loadSsz(testCaseDir.resolve("pre.ssz_snappy"), beaconStateSchema);
final BeaconState postState =
final BeaconStateElectra postState =
loadSsz(testCaseDir.resolve("post.ssz_snappy"), beaconStateSchema);

ConsolidationRequestFuzzInput input = new ConsolidationRequestFuzzInput(spec, preState, data);
byte[] rawInput = input.sszSerialize().toArrayUnsafe();
Optional<Bytes> result = fuzzUtil.fuzzConsolidationRequest(rawInput).map(Bytes::wrap);
final ConsolidationRequestFuzzInput input =
new ConsolidationRequestFuzzInput(spec, preState, data);
final byte[] rawInput = input.sszSerialize().toArrayUnsafe();
final Optional<Bytes> result = fuzzUtil.fuzzConsolidationRequest(rawInput).map(Bytes::wrap);

Bytes expected = postState.sszSerialize();
assertThat(result).isNotEmpty();
assertThat(result.get()).isEqualTo(expected);
final BeaconStateElectra resultState =
BeaconStateElectra.required(
spec.getGenesisSchemaDefinitions().getBeaconStateSchema().sszDeserialize(result.get()));
assertThat(JsonUtil.prettySerialize(resultState, beaconStateSchema.getJsonTypeDefinition()))
.isEqualTo(JsonUtil.prettySerialize(postState, beaconStateSchema.getJsonTypeDefinition()));
}

@Test
Expand Down

0 comments on commit 1ff5f21

Please sign in to comment.