Skip to content

Commit 459fcf2

Browse files
Merge branch 'bing/blst-z' into cayman/bls-verifier
2 parents ec98851 + 45b08e6 commit 459fcf2

File tree

5 files changed

+605
-25
lines changed

5 files changed

+605
-25
lines changed

packages/beacon-node/src/chain/validation/attestation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export async function validateGossipAttestationsSameAttData(
183183
chain.seenAttesters.add(targetEpoch, validatorIndex);
184184
} else {
185185
step0ResultOrErrors[oldIndex] = {
186-
err: new AttestationError(GossipAction.IGNORE, {
186+
err: new AttestationError(GossipAction.REJECT, {
187187
code: AttestationErrorCode.INVALID_SIGNATURE,
188188
}),
189189
};

packages/beacon-node/src/chain/validation/attesterSlashing.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
assertValidAttesterSlashing,
33
getAttesterSlashableIndices,
44
getAttesterSlashingSignatureSets,
5+
isSlashableValidator,
56
} from "@lodestar/state-transition";
67
import {AttesterSlashing} from "@lodestar/types";
78
import {AttesterSlashingError, AttesterSlashingErrorCode, GossipAction} from "../errors/index.js";
@@ -58,6 +59,14 @@ export async function validateAttesterSlashing(
5859
});
5960
}
6061

62+
const currentEpoch = state.epochCtx.epoch;
63+
if (!intersectingIndices.some((index) => isSlashableValidator(state.validators.getReadonly(index), currentEpoch))) {
64+
throw new AttesterSlashingError(GossipAction.REJECT, {
65+
code: AttesterSlashingErrorCode.INVALID,
66+
error: Error("AttesterSlashing has no slashable validators"),
67+
});
68+
}
69+
6170
const signatureSets = getAttesterSlashingSignatureSets(chain.config, state.slot, attesterSlashing);
6271
if (!(await chain.bls.verifySignatureSets(signatureSets, {batchable: true, priority: prioritizeBls}))) {
6372
throw new AttesterSlashingError(GossipAction.REJECT, {

packages/beacon-node/src/chain/validation/block.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export async function validateGossipBlock(
104104

105105
// [REJECT] The block is from a higher slot than its parent.
106106
if (parentBlock.slot >= blockSlot) {
107-
throw new BlockGossipError(GossipAction.IGNORE, {
107+
throw new BlockGossipError(GossipAction.REJECT, {
108108
code: BlockErrorCode.NOT_LATER_THAN_PARENT,
109109
parentSlot: parentBlock.slot,
110110
slot: blockSlot,
Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import fs from "node:fs";
12
import path from "node:path";
3+
import {expect, it} from "vitest";
24
import {config} from "@lodestar/config/default";
35
import {ACTIVE_PRESET} from "@lodestar/params";
4-
import {InputType} from "@lodestar/spec-test-util";
5-
import {bigIntToBytes} from "@lodestar/utils";
6+
import {bigIntToBytes, loadYaml} from "@lodestar/utils";
67
import {computeColumnsForCustodyGroup, getCustodyGroups} from "../../../src/util/dataColumns.js";
78
import {ethereumConsensusSpecsTests} from "../specTestVersioning.js";
8-
import {specTestIterator} from "../utils/specTestIterator.js";
9-
import {RunnerType, TestRunnerFn} from "../utils/types.js";
9+
import {isGossipValidationHandler, runGossipValidationTest} from "../utils/gossipValidation.js";
10+
import {readdirSyncSpec, specTestIterator} from "../utils/specTestIterator.js";
11+
import {RunnerType, TestRunnerCustom} from "../utils/types.js";
1012

1113
type ComputeColumnForCustodyGroupInput = {
1214
custody_group: number;
@@ -28,30 +30,50 @@ const networkingFns: Record<string, NetworkFn> = {
2830
},
2931
};
3032

31-
const networking: TestRunnerFn<NetworkingTestCase, unknown> = (_fork, testName) => {
32-
return {
33-
testFunction: (testcase) => {
34-
const networkingFn = networkingFns[testName];
35-
if (networkingFn === undefined) {
36-
throw Error(`No networkingFn for ${testName}`);
37-
}
38-
39-
return networkingFn(testcase.meta);
40-
},
41-
options: {
42-
inputTypes: {meta: InputType.YAML},
43-
getExpected: (testCase) => testCase.meta.result.map(Number),
44-
// Do not manually skip tests here, do it in packages/beacon-node/test/spec/presets/index.test.ts
45-
},
46-
};
47-
};
48-
4933
type NetworkingTestCase = {
5034
meta: {
5135
result: number[];
5236
};
5337
};
5438

39+
function loadNetworkingTestMeta(testCaseDir: string): NetworkingTestCase["meta"] {
40+
return loadYaml<NetworkingTestCase["meta"]>(fs.readFileSync(path.join(testCaseDir, "meta.yaml"), "utf8"));
41+
}
42+
43+
function runNetworkingFnTests(testHandler: string, testSuite: string, testSuiteDirpath: string): void {
44+
const networkingFn = networkingFns[testHandler];
45+
if (networkingFn === undefined) {
46+
throw Error(`No networkingFn for ${testHandler}`);
47+
}
48+
49+
for (const testCaseName of readdirSyncSpec(testSuiteDirpath)) {
50+
const testCaseDir = path.join(testSuiteDirpath, testCaseName);
51+
it(testCaseName, () => {
52+
const meta = loadNetworkingTestMeta(testCaseDir);
53+
const actual = networkingFn(meta);
54+
expect(actual).toEqualWithMessage(
55+
meta.result.map(Number),
56+
`Unexpected networking result for ${testHandler}/${testSuite}/${testCaseName}`
57+
);
58+
});
59+
}
60+
}
61+
62+
const networking: TestRunnerCustom = (fork, testHandler, testSuite, testSuiteDirpath) => {
63+
if (isGossipValidationHandler(testHandler)) {
64+
for (const testCaseName of readdirSyncSpec(testSuiteDirpath)) {
65+
const testCaseDir = path.join(testSuiteDirpath, testCaseName);
66+
it(testCaseName, async () => {
67+
await runGossipValidationTest(fork, testHandler, testCaseDir);
68+
}, 30_000);
69+
}
70+
} else if (networkingFns[testHandler] !== undefined) {
71+
runNetworkingFnTests(testHandler, testSuite, testSuiteDirpath);
72+
} else {
73+
throw new Error(`No runner for networking handler ${testHandler}`);
74+
}
75+
};
76+
5577
specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), {
56-
networking: {type: RunnerType.default, fn: networking},
78+
networking: {type: RunnerType.custom, fn: networking},
5779
});

0 commit comments

Comments
 (0)