Skip to content

Commit

Permalink
have CL compute the aggregated proof for the block, per updated spec
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-bayardo committed Nov 14, 2022
1 parent a8701f8 commit 7245056
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 66 deletions.
16 changes: 8 additions & 8 deletions beacon-chain/core/blob/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@ func (s commitmentSequenceImpl) Len() int {
return len(s)
}

type blobImpl [][]byte
type BlobImpl [][]byte

func (b blobImpl) At(i int) [32]byte {
func (b BlobImpl) At(i int) [32]byte {
var out [32]byte
copy(out[:], b[i][:])
return out
}

func (b blobImpl) Len() int {
func (b BlobImpl) Len() int {
return len(b)
}

type blobsSequenceImpl []*v1.Blob
type BlobsSequenceImpl []*v1.Blob

func (s blobsSequenceImpl) At(i int) kzg.Blob {
return blobImpl(s[i].Blob)
func (s BlobsSequenceImpl) At(i int) kzg.Blob {
return BlobImpl(s[i].Blob)
}

func (s blobsSequenceImpl) Len() int {
func (s BlobsSequenceImpl) Len() int {
return len(s)
}

// ValidateBlobsSidecar verifies the integrity of a sidecar, returning nil if the blob is valid.
func ValidateBlobsSidecar(slot types.Slot, root [32]byte, commitments [][]byte, sidecar *eth.BlobsSidecar) error {
kzgSidecar := kzg.BlobsSidecar{
BeaconBlockSlot: kzg.Slot(sidecar.BeaconBlockSlot),
Blobs: blobsSequenceImpl(sidecar.Blobs),
Blobs: BlobsSequenceImpl(sidecar.Blobs),
}
copy(kzgSidecar.BeaconBlockRoot[:], sidecar.BeaconBlockRoot)
copy(kzgSidecar.KZGAggregatedProof[:], sidecar.AggregatedProof)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"context"
"fmt"

"github.com/ethereum/go-ethereum/crypto/kzg"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blob"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition/interop"
"github.com/prysmaticlabs/prysm/v3/config/params"
consensusblocks "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
Expand Down Expand Up @@ -108,11 +110,15 @@ func (vs *Server) assembleEip4844Block(ctx context.Context, altairBlk *ethpb.Bea

var sideCar *ethpb.BlobsSidecar
if len(blobsBundle.Blobs) != 0 {
aggregatedProof, err := kzg.ComputeAggregateKZGProof(blob.BlobsSequenceImpl(blobsBundle.Blobs))
if err != nil {
return nil, fmt.Errorf("failed to compute aggregated kzg proof: %v", err)
}
sideCar = &ethpb.BlobsSidecar{
BeaconBlockRoot: r[:],
BeaconBlockSlot: wsb.Block().Slot(),
Blobs: blobsBundle.Blobs,
AggregatedProof: blobsBundle.AggregatedProof,
AggregatedProof: aggregatedProof[:],
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,4 @@ replace github.com/json-iterator/go => github.com/prestonvanloon/go v1.1.7-0.201
replace github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20220721162526-0d1c40b5f064

// For eip-4844 types
replace github.com/ethereum/go-ethereum => github.com/mdehoog/go-ethereum v1.10.19-0.20221113220910-b4e09c8948db
replace github.com/ethereum/go-ethereum => github.com/mdehoog/go-ethereum v1.10.19-0.20221114011613-42a69e6e01ae
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,8 @@ github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsO
github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mdehoog/go-ethereum v1.10.19-0.20221113220910-b4e09c8948db h1:+it0Xflw4jcbnRqu0XLEMQfbh/SdBc/8z0Q5+eNyqBc=
github.com/mdehoog/go-ethereum v1.10.19-0.20221113220910-b4e09c8948db/go.mod h1:g+vX1+faxlr/KM1C0wybtfdcH5aPghqJAfpLGAn+Kbk=
github.com/mdehoog/go-ethereum v1.10.19-0.20221114011613-42a69e6e01ae h1:2wXfDkt06PPDhG4Lxkse69fDegYljvz9fSZExd5V41c=
github.com/mdehoog/go-ethereum v1.10.19-0.20221114011613-42a69e6e01ae/go.mod h1:g+vX1+faxlr/KM1C0wybtfdcH5aPghqJAfpLGAn+Kbk=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
Expand Down
63 changes: 26 additions & 37 deletions proto/engine/v1/execution_engine.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion proto/engine/v1/execution_engine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ message BlobsBundle {
bytes block_hash = 1 [(ethereum.eth.ext.ssz_size) = "32"];
repeated bytes kzgs = 2 [(ethereum.eth.ext.ssz_size) = "?,48", (ethereum.eth.ext.ssz_max) = "16"];
repeated Blob blobs = 3 [(ethereum.eth.ext.ssz_max) = "16"];
bytes aggregated_proof = 4 [(ethereum.eth.ext.ssz_size) = "48"];
}

message Blob {
Expand Down
2 changes: 1 addition & 1 deletion proto/engine/v1/generated.ssz.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions proto/engine/v1/json_marshal_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,9 @@ func (b *BlobsBundle) MarshalJSON() ([]byte, error) {
}

return json.Marshal(blobBundleJSON{
BlockHash: bytesutil.ToBytes32(b.BlockHash),
Kzgs: kzgs,
Blobs: blobs,
AggregatedProof: bytesutil.ToBytes48(b.AggregatedProof),
BlockHash: bytesutil.ToBytes32(b.BlockHash),
Kzgs: kzgs,
Blobs: blobs,
})
}

Expand All @@ -600,6 +599,5 @@ func (e *BlobsBundle) UnmarshalJSON(enc []byte) error {
}
}
e.Blobs = blobs
e.AggregatedProof = bytesutil.PadTo(dec.AggregatedProof[:], fieldparams.BLSPubkeyLength)
return nil
}
14 changes: 7 additions & 7 deletions proto/eth/ext/options.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/eth/v1/generated.ssz.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/eth/v2/generated.ssz.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/prysm/v1alpha1/generated.ssz.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7245056

Please sign in to comment.