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

Datablob transactions #1

Draft
wants to merge 61 commits into
base: base
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
92d7fa9
core/types: data blob transaction type and signer
protolambda Feb 19, 2022
562723e
accounts,signer: blob tx signer support
protolambda Feb 19, 2022
6bc5155
params/conf: add sharding fork defn
lightclient Feb 18, 2022
1d43675
all: add data hashes to evm msg
lightclient Feb 18, 2022
7c62e93
core/vm: impl DATAHASH opcode
lightclient Feb 19, 2022
e552a93
params: update gas per blob parameter to 120k
lightclient Feb 19, 2022
46a4b31
core/vm: use correct gas price for DATAHASH
lightclient Feb 19, 2022
59dc43f
core/types/data_blob_tx: grab correct r,s values from signature
lightclient Feb 19, 2022
5e37223
core/types/transaction_signing: use dank signer when needed
lightclient Feb 19, 2022
e61cf36
core/types/transaction: grab data hashes from blob txs for message
lightclient Feb 19, 2022
78187b8
core: add test for data blob txs
lightclient Feb 19, 2022
89c1e27
all: fix intrinsic gas calls in various tests
lightclient Feb 19, 2022
7a3a455
Merge pull request #2 from lightclient/simple-blob
protolambda Feb 20, 2022
204c556
work in progress, tx wrapper for blob tx pool / journal / block build…
protolambda Feb 20, 2022
cbcdcdd
core/types: implement data blob / kzg and lists ssz encoding
protolambda Feb 20, 2022
5b878b7
Import go-kzg to geth
asn-d6 Feb 19, 2022
dbfa618
Introduce dummy KZG trusted setup generator
asn-d6 Feb 19, 2022
72eced9
Introduce KZG crypto module (that implements the funcs from the mini-…
asn-d6 Feb 19, 2022
f83107f
Introduce unittests for KZG and the trusted setup
asn-d6 Feb 19, 2022
f4f1230
Add the trusted setup json data as a go file
asn-d6 Feb 19, 2022
9da9ab7
Introduce blobVerification precompile
asn-d6 Feb 19, 2022
b5c5515
Introduce blobVerification precompile test vector
asn-d6 Feb 20, 2022
b7db064
Introduce pointEvaluation precompile
asn-d6 Feb 20, 2022
5e18fbd
Introduce pointEvaluation precompile test vector (happy case)
asn-d6 Feb 20, 2022
cfb0440
eth/catalyst: GetBlobV1
protolambda Feb 20, 2022
b2d3882
go.mod,go.sum: update bls/kzg libs
protolambda Feb 20, 2022
b1dc9bc
go.mod,go.sum: update KZG lib
protolambda Feb 20, 2022
ff1a74f
core/vm,crypto/kzg,tests: update data blob kzg to use From/To Compres…
protolambda Feb 20, 2022
21836f0
core/types,crypto/kzg,signer: compute KZG commitment from raw blob data
protolambda Feb 20, 2022
e0b5cde
Update test vectors for blobVerification/pointEvaluation
asn-d6 Feb 21, 2022
f500191
Remove go-kzg dependency from kzg crypto module
asn-d6 Feb 21, 2022
96bf205
core/types: blob kzgs list ssz vector->list fix, fix blob tx encoding…
protolambda Feb 21, 2022
a38a121
core/types: test dynamic fee and blob tx binary+json encoding
protolambda Feb 21, 2022
803f31e
core: don't reinject incomplete transactions on reorg
protolambda Feb 21, 2022
c971490
core/types: encode/decode the block with transactions the minimal way
protolambda Feb 22, 2022
d19e6ee
core: consider blobs count for intrinsic gas check
protolambda Feb 25, 2022
a922276
Merge pull request #3 from asn-d6/prune-gokzg
protolambda Feb 25, 2022
587a212
eth/catalyst: implement GetBlobsBundleV1 - EIP-4844 engine api extension
protolambda Mar 12, 2022
4b0c1cb
core/types: compute kzgs for blobs list
protolambda Mar 13, 2022
e9279d9
accounts,internal/ethapi: blob transaction api arguments
protolambda Mar 13, 2022
5fa43da
signer/core/apitypes: fix wrap-data NewTx option
protolambda Mar 13, 2022
e539920
core/types: fix marshal/unmarshal text Blob type, BLSFieldElement, KZ…
protolambda Mar 13, 2022
184ba49
Add functions to extract the crypto out of Blobs/KZGCommitment/BlobKzgs
asn-d6 Mar 1, 2022
6cd16f1
Use optimized VerifyBlobs() function
asn-d6 Mar 1, 2022
dafbb4d
Add unittest for VerifyBlobs() function
asn-d6 Mar 1, 2022
0c236b0
kzg: Rename CRS variables to match the EIP naming
asn-d6 Mar 1, 2022
9f6e026
kzg: Document kzg code further
asn-d6 Mar 1, 2022
5009206
core/types: clean up blob and commitment parse methods, use ptr recei…
protolambda Mar 15, 2022
f80048e
tests: blob test update, Parse blobs/commitments, fix mutation on copy
protolambda Mar 15, 2022
d48a83e
params,core/types: remove duplicate kzg version param
protolambda Mar 15, 2022
52abcb8
core/vm,crypto/kzg,tests: remove versioned-hash func from crypto, app…
protolambda Mar 15, 2022
6e4051e
tests: benchmark kzg funcs
protolambda Mar 15, 2022
db23602
crypto/kzg: batch verification for multiple txs
protolambda Mar 17, 2022
d3ab1dd
core/types: support blobs batch-verify of multiple txs
protolambda Mar 17, 2022
6f21779
core: refactor TxPool.add and .addTxsLocked to batch-verify txs
protolambda Mar 17, 2022
bfe1f35
Update LatestSignerForChainID() to return a danksigner by default
asn-d6 Mar 21, 2022
7512b91
Transaction inner size should be computed on-demand
asn-d6 Mar 21, 2022
f87c6d6
Include versioned hashes when creating a transaction using the JSON-R…
asn-d6 Mar 22, 2022
d6fb210
Merge pull request #5 from asn-d6/eip4844-tooling
protolambda Mar 22, 2022
b58bd6e
remove blob verification precompile in favor of point evaluation prec…
protolambda Jun 7, 2022
ff35a44
fix lint
protolambda Jun 7, 2022
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
59 changes: 59 additions & 0 deletions crypto/kzg/kzg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package kzg
import (
"encoding/json"
"errors"
"fmt"
"sync"

"github.com/ethereum/go-ethereum/params"
"github.com/protolambda/go-kzg/bls"
Expand Down Expand Up @@ -37,6 +39,63 @@ func VerifyKzgProof(commitment *bls.G1Point, x *bls.Fr, y *bls.Fr, proof *bls.G1
return bls.PairingsVerify(&commitmentMinusY, &bls.GenG2, proof, &sMinuxX)
}

type BlobsBatch struct {
sync.Mutex
init bool
aggregateCommitment bls.G1Point
aggregateBlob [params.FieldElementsPerBlob]bls.Fr
}

func (batch *BlobsBatch) Join(commitments []*bls.G1Point, blobs [][]bls.Fr) error {
batch.Lock()
defer batch.Unlock()
if len(commitments) != len(blobs) {
return fmt.Errorf("expected commitments len %d to equal blobs len %d", len(commitments), len(blobs))
}
if !batch.init && len(commitments) > 0 {
batch.init = true
bls.CopyG1(&batch.aggregateCommitment, commitments[0])
copy(batch.aggregateBlob[:], blobs[0])
commitments = commitments[1:]
blobs = blobs[1:]
}
for i, commit := range commitments {
batch.join(commit, blobs[i])
}
return nil
}

func (batch *BlobsBatch) join(commitment *bls.G1Point, blob []bls.Fr) {
// we multiply the input we are joining with a random scalar, so we can add it to the aggregate safely
randomScalar := bls.RandomFr()

// TODO: instead of computing the lin-comb of the commitments on the go, we could buffer
// the random scalar and commitment, and run a LinCombG1 over all of them during Verify()
var tmpG1 bls.G1Point
bls.MulG1(&tmpG1, commitment, randomScalar)
bls.AddG1(&batch.aggregateCommitment, &batch.aggregateCommitment, &tmpG1)

var tmpFr bls.Fr
for i := 0; i < params.FieldElementsPerBlob; i++ {
bls.MulModFr(&tmpFr, &blob[i], randomScalar)
bls.AddModFr(&batch.aggregateBlob[i], &batch.aggregateBlob[i], &tmpFr)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming nitpick: s/aggregateBlob/aggregateScalar

It's not actually a single blob that is aggregated in every aggregateBlob scalar; it's actually all the blobs.

}
}

func (batch *BlobsBatch) Verify() error {
batch.Lock()
defer batch.Unlock()
if !batch.init {
return nil // empty batch
}
// Compute both MSMs and check equality
lResult := bls.LinCombG1(kzgSetupLagrange, batch.aggregateBlob[:])
if !bls.EqualG1(lResult, &batch.aggregateCommitment) {
return errors.New("BlobsBatch failed to Verify")
}
return nil
}

// Verify that the list of `commitments` maps to the list of `blobs`
//
// This is an optimization over the naive approach (found in the EIP) of iteratively checking each blob against each
Expand Down