Skip to content

Commit

Permalink
Use computeAggregateKzgProof from the c-kzg package and delete all th…
Browse files Browse the repository at this point in the history
…e code it encapsulates
  • Loading branch information
dgcoffman committed Nov 7, 2022
1 parent 2fe076b commit 3db4f57
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 303 deletions.
8 changes: 4 additions & 4 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"@chainsafe/discv5": "^1.1.2",
"@chainsafe/ssz": "^0.9.2",
"@libp2p/peer-id-factory": "^1.0.18",
"@multiformats/multiaddr": "^11.0.0",
"@lodestar/api": "^1.1.1",
"@lodestar/beacon-node": "^1.1.1",
"@lodestar/config": "^1.1.1",
Expand All @@ -69,6 +68,7 @@
"@lodestar/types": "^1.1.1",
"@lodestar/utils": "^1.1.1",
"@lodestar/validator": "^1.1.1",
"@multiformats/multiaddr": "^11.0.0",
"@types/lockfile": "^1.0.1",
"bip39": "^3.0.2",
"deepmerge": "^4.2.2",
Expand All @@ -85,15 +85,15 @@
"source-map-support": "^0.5.19",
"uint8arrays": "^3.1.0",
"uuidv4": "^6.1.1",
"yargs": "^16.1.0",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.5",
"winston-transport": "^4.3.0"
"winston-transport": "^4.3.0",
"yargs": "^16.1.0"
},
"devDependencies": {
"@types/expand-tilde": "^2.0.0",
"@types/got": "^9.6.11",
"@types/inquirer": "^7.3.0",
"@types/inquirer": "^9.0.2",
"@types/js-yaml": "^3.12.5",
"@types/lodash": "^4.14.157",
"@types/rimraf": "^3.0.2",
Expand Down
6 changes: 4 additions & 2 deletions packages/types/src/eip4844/sszTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ContainerType, ListCompositeType} from "@chainsafe/ssz";
import {ContainerType, ListCompositeType, ByteVectorType} from "@chainsafe/ssz";
import {HISTORICAL_ROOTS_LIMIT, FIELD_ELEMENTS_PER_BLOB, MAX_BLOBS_PER_BLOCK} from "@lodestar/params";
import {ssz as primitiveSsz} from "../primitive/index.js";
import {ssz as phase0Ssz} from "../phase0/index.js";
Expand All @@ -18,12 +18,14 @@ export const BLSFieldElement = Bytes32;
export const KZGCommitment = Bytes48;
export const KZGProof = Bytes48;

const BYTES_PER_FIELD_ELEMENT = 32;

// Beacon chain

// Custom types
// https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/beacon-chain.md#custom-types

export const Blob = new ListCompositeType(BLSFieldElement, FIELD_ELEMENTS_PER_BLOB);
export const Blob = new ByteVectorType(BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_BLOB);
export const Blobs = new ListCompositeType(Blob, MAX_BLOBS_PER_BLOCK);
export const VersionedHash = Bytes32;
export const BlobKzgCommitments = new ListCompositeType(KZGCommitment, MAX_BLOBS_PER_BLOCK);
Expand Down
1 change: 1 addition & 0 deletions packages/validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@lodestar/types": "^1.1.1",
"@lodestar/utils": "^1.1.1",
"bigint-buffer": "^1.1.5",
"c-kzg": "^0.0.6",
"cross-fetch": "^3.1.4",
"strict-event-emitter-types": "^2.0.0"
},
Expand Down
28 changes: 25 additions & 3 deletions packages/validator/src/services/block.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {computeAggregateKzgProof} from "c-kzg";
import {BLSPubkey, Slot, BLSSignature, allForks, bellatrix, isBlindedBeaconBlock, eip4844, ssz} from "@lodestar/types";
import {IChainForkConfig} from "@lodestar/config";
import {ForkName, ForkSeq} from "@lodestar/params";
import {extendError, prettyBytes} from "@lodestar/utils";
import {toHexString} from "@chainsafe/ssz";
import {Api} from "@lodestar/api";
import {Blobs} from "@lodestar/types/eip4844";
import {Blobs, BlobsSidecar} from "@lodestar/types/eip4844";
import {blindedOrFullBlockHashTreeRoot} from "@lodestar/state-transition";
import {IClock, ILoggerVc} from "../util/index.js";
import {PubkeyHex} from "../types.js";
import {Metrics} from "../metrics.js";
import {getBlobsSidecar} from "../util/blobs/polynomialCommitments.js";
import {ValidatorStore} from "./validatorStore.js";
import {BlockDutiesService, GENESIS_SLOT} from "./blockDuties.js";

Expand Down Expand Up @@ -106,7 +107,7 @@ export class BlockProposingService {

const signedBlockWithBlobs = ssz.eip4844.SignedBeaconBlockAndBlobsSidecar.defaultValue();
signedBlockWithBlobs.beaconBlock = signedBlock as eip4844.SignedBeaconBlock;
signedBlockWithBlobs.blobsSidecar = getBlobsSidecar(this.config, block, blobs);
signedBlockWithBlobs.blobsSidecar = this.getBlobsSidecar(block, blobs);

// TODO EIP-4844: Blinded blocks??? No clue!
await this.api.beacon.publishBlockWithBlobs(signedBlockWithBlobs).catch(onPublishError);
Expand All @@ -121,6 +122,27 @@ export class BlockProposingService {
}
}

/**
* https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/validator.md#sidecar
* def get_blobs_sidecar(block: BeaconBlock, blobs: Sequence[Blob]) -> BlobsSidecar:
* return BlobsSidecar(
* beacon_block_root=hash_tree_root(block),
* beacon_block_slot=block.slot,
* blobs=blobs,
* kzg_aggregated_proof=compute_proof_from_blobs(blobs),
* )
*/
private getBlobsSidecar(block: allForks.FullOrBlindedBeaconBlock, blobs: Blobs): BlobsSidecar {
const blobsSidecar = ssz.eip4844.BlobsSidecar.defaultValue();

blobsSidecar.beaconBlockRoot = blindedOrFullBlockHashTreeRoot(this.config, block);
blobsSidecar.beaconBlockSlot = block.slot;
blobsSidecar.blobs = blobs;
blobsSidecar.kzgAggregatedProof = computeAggregateKzgProof(blobs);

return blobsSidecar;
}

private publishBlockWrapper = async (signedBlock: allForks.FullOrBlindedSignedBeaconBlock): Promise<void> => {
return isBlindedBeaconBlock(signedBlock.message)
? this.api.beacon.publishBlindedBlock(signedBlock as bellatrix.SignedBlindedBeaconBlock)
Expand Down
54 changes: 0 additions & 54 deletions packages/validator/src/util/blobs/bitReversalPermutation.ts

This file was deleted.

70 changes: 0 additions & 70 deletions packages/validator/src/util/blobs/bls.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/validator/src/util/blobs/constants.ts

This file was deleted.

Loading

0 comments on commit 3db4f57

Please sign in to comment.