Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions antimev/keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/bane-labs/zk-dkg/encryption"
bls12381 "github.com/consensys/gnark-crypto/ecc/bls12-381"
"github.com/consensys/gnark-crypto/ecc/bls12-381/fp"
"github.com/consensys/gnark-crypto/ecc/secp256k1"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/ecies"
Expand Down Expand Up @@ -506,11 +507,11 @@ func encryptShareMessages(pubs []*ecies.PublicKey, shares []*big.Int) ([][]byte,
}

func encryptShareMessage(pub *ecies.PublicKey, share *big.Int) ([]byte, error) {
nonce, ess, _, bigR, err := encryption.ECIESEncrypt(pub, share.Bytes())
nonce, ess, r, err := encryption.ECIESEncrypt(pub, share.Bytes())
if err != nil {
return nil, err
}
bigRBytes := bigR.RawBytes()
bigRBytes := new(secp256k1.G1Affine).ScalarMultiplicationBase(r).RawBytes()
// len(message)=64+12+len(ess)
msg := make([]byte, 0)
msg = append(msg, bigRBytes[:]...)
Expand Down
25 changes: 14 additions & 11 deletions consensus/dbft/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ executeLoop:
sevenMsgR1CS constraint.ConstraintSystem
sevenMsgPK *groth16.ProvingKey
)
c.lock.RLock()
sender := c.amevKeystore.Address()
c.lock.RUnlock()

// Handle new tasks immediately but one by one.
for _, task := range *pendingList {
Expand All @@ -419,13 +422,13 @@ executeLoop:
fis[i] = new(fr.Element).SetBigInt(s)
}
// Compute necessary inputs for circuit.
fisBytes, fisInts, bigFis, nonces, encryptedFis, rs, bigRs, err := circuit.PrepareEncryptedKeyShares(pubs, fis)
fisInts, nonces, encryptedFis, rs, err := circuit.PrepareEncryptedKeyShares(pubs, fis)
if err != nil {
log.Error("failed to prepare encrypted key shares", "err", err, "method", task.Method)
continue
}
// Update the task parameters for sending a transaction.
msgs := encodeMessages(encryptedFis, bigRs, nonces)
msgs := encodeMessages(encryptedFis, rs, nonces)
// Send transactions based on ZK settings.
switch task.ZKVersion {
case 0:
Expand All @@ -445,7 +448,7 @@ executeLoop:
}
var err error
if sevenMsgR1CS == nil {
sevenMsgR1CS, err = helper.ReadCSS(c.zkFiles.sevenMsgR1CSPath)
sevenMsgR1CS, err = helper.ReadCCS(c.zkFiles.sevenMsgR1CSPath)
if err != nil {
log.Error("invalid r1cs file", "file", c.zkFiles.sevenMsgR1CSPath, "err", err)
continue
Expand All @@ -459,7 +462,7 @@ executeLoop:
}
}
// Compute zk proof.
proof, _, err := zkdkg.ProveMultipleKeyShareEncryption(sevenMsgR1CS, sevenMsgPK, pubs, rs, bigRs, fisBytes, fisInts, bigFis, encryptedFis, nonces)
proof, _, err := zkdkg.ProveMultipleKeyShareEncryption(sevenMsgR1CS, sevenMsgPK, sender, pubs, rs, fisInts, encryptedFis, nonces)
if err != nil {
log.Error("failed to prove DKG", "method", task.Method)
continue
Expand Down Expand Up @@ -498,13 +501,13 @@ executeLoop:
idxsBigInt[i] = big.NewInt(int64(idx))
}
// Compute necessary inputs for circuit.
fisBytes, fisInts, bigFis, nonces, encryptedFis, rs, bigRs, err := circuit.PrepareEncryptedKeyShares(pubs, fis)
fisInts, nonces, encryptedFis, rs, err := circuit.PrepareEncryptedKeyShares(pubs, fis)
if err != nil {
log.Error("failed to prepare encrypted key shares", "err", err, "method", task.Method)
continue
}
// Update the task parameters for sending a transaction.
msgs := encodeMessages(encryptedFis, bigRs, nonces)
msgs := encodeMessages(encryptedFis, rs, nonces)
// Send transactions based on ZK settings.
switch task.ZKVersion {
case 0:
Expand All @@ -526,7 +529,7 @@ executeLoop:
)
switch len(indexes) {
case 1:
r1cs, err = helper.ReadCSS(c.zkFiles.oneMsgR1CSPath)
r1cs, err = helper.ReadCCS(c.zkFiles.oneMsgR1CSPath)
if err != nil {
log.Error("invalid r1cs file", "file", c.zkFiles.oneMsgR1CSPath, "err", err)
continue
Expand All @@ -537,7 +540,7 @@ executeLoop:
continue
}
case 2:
r1cs, err = helper.ReadCSS(c.zkFiles.twoMsgR1CSPath)
r1cs, err = helper.ReadCCS(c.zkFiles.twoMsgR1CSPath)
if err != nil {
log.Error("invalid r1cs file", "file", c.zkFiles.twoMsgR1CSPath, "err", err)
continue
Expand All @@ -551,7 +554,7 @@ executeLoop:
// The circuit setup is limited for proofs of 1-or-2-message tasks, other cases shouldn't happen.
panic(fmt.Errorf("invalid number of %s message inputs: expect 1 or 2, get %d", task.Method, len(fis)))
}
proof, _, err := zkdkg.ProveMultipleKeyShareEncryption(r1cs, provingKey, pubs, rs, bigRs, fisBytes, fisInts, bigFis, encryptedFis, nonces)
proof, _, err := zkdkg.ProveMultipleKeyShareEncryption(r1cs, provingKey, sender, pubs, rs, fisInts, encryptedFis, nonces)
if err != nil {
log.Error("failed to prove DKG", "method", task.Method)
continue
Expand Down Expand Up @@ -1100,10 +1103,10 @@ func sendTransactionToKeyManagement(api *ethapi.TransactionAPI, signer common.Ad
}

// encodeMessages encodes the output from message encryption.
func encodeMessages(encryptedFis [][]byte, bigRs []*secp256k1.G1Affine, nonces [][]byte) [][]byte {
func encodeMessages(encryptedFis [][]byte, rs []*big.Int, nonces [][]byte) [][]byte {
result := make([][]byte, 0)
for i := range encryptedFis {
bigRBytes := bigRs[i].RawBytes()
bigRBytes := new(secp256k1.G1Affine).ScalarMultiplicationBase(rs[i]).RawBytes()
prefix := append(bigRBytes[:], nonces[i]...)
result = append(result, append(prefix, encryptedFis[i]...))
}
Expand Down
14 changes: 10 additions & 4 deletions crypto/tpke/dkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
bls12381 "github.com/consensys/gnark-crypto/ecc/bls12-381"
"github.com/consensys/gnark-crypto/ecc/secp256k1"
"github.com/consensys/gnark-crypto/ecc/secp256k1/fp"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -61,6 +62,7 @@ func TestReplayPVSS(t *testing.T) {

func TestReplayPubHash(t *testing.T) {
size := 7
sender := common.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
// Recover the secret
p0, err := hex.DecodeString("704e6038571bcd1c8cfac37e821fa49b8f6eee724b00156a229fd69975e30933")
require.NoError(t, err)
Expand Down Expand Up @@ -152,8 +154,12 @@ func TestReplayPubHash(t *testing.T) {
}

// Compute allHash
hashDomain := "DKG_BATCH_HASH_V1"
batch := 7
rawPubInputs := make([]byte, 0)
rawPubInputs = append(rawPubInputs, hashDomain...)
rawPubInputs = append(rawPubInputs, sender[:]...)
rawPubInputs = append(rawPubInputs, byte(batch))
for index := 0; index < batch; index++ {
// Format data
var px fp.Element
Expand Down Expand Up @@ -182,10 +188,10 @@ func TestReplayPubHash(t *testing.T) {
for i := 0; i < bls12381G1ByteLength; i++ {
rawBigFi[i] = bigFiBytes[i] // bytes
}
singleHash := helper.GetHash(append(append(append(append(append(rawBigR, rawPub...), rawBigFi...), messages[index][64:76]...), 2), messages[index][76:]...))
t.Log(hex.EncodeToString(append(append(append(append(append(rawBigR, rawPub...), rawBigFi...), messages[index][64:76]...), 2), messages[index][76:]...)))
rawPubInputs = append(rawPubInputs, singleHash...)
innerHash := helper.GetHash(append(append(append(append(append(rawBigR, rawPub...), rawBigFi...), messages[index][64:76]...), 2), messages[index][76:]...))
rawPubInputs = append(rawPubInputs, byte(index), byte(len(innerHash)))
rawPubInputs = append(rawPubInputs, innerHash[:]...)
}
sumHash := helper.GetHash(rawPubInputs)
t.Log(hex.EncodeToString(sumHash))
t.Log(hex.EncodeToString(sumHash[:]))
}
42 changes: 20 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/ethereum/go-ethereum

go 1.22
go 1.23.0

toolchain go1.23.1

require (
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0
Expand All @@ -10,13 +12,13 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.18.45
github.com/aws/aws-sdk-go-v2/credentials v1.13.43
github.com/aws/aws-sdk-go-v2/service/route53 v1.30.2
github.com/bane-labs/zk-dkg v0.2.2
github.com/bane-labs/zk-dkg v0.3.0
github.com/btcsuite/btcd/btcec/v2 v2.2.0
github.com/cespare/cp v0.1.0
github.com/cloudflare/cloudflare-go v0.79.0
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593
github.com/consensys/gnark v0.12.1-0.20250319074137-a123a4045e01
github.com/consensys/gnark-crypto v0.16.1-0.20250217214835-5ed804970f85
github.com/consensys/gnark v0.13.0
github.com/consensys/gnark-crypto v0.18.0
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233
github.com/crate-crypto/go-kzg-4844 v1.1.0
github.com/davecgh/go-spew v1.1.1
Expand Down Expand Up @@ -50,7 +52,7 @@ require (
github.com/julienschmidt/httprouter v1.3.0
github.com/karalabe/usb v0.0.2
github.com/kylelemons/godebug v1.1.0
github.com/mattn/go-colorable v0.1.13
github.com/mattn/go-colorable v0.1.14
github.com/mattn/go-isatty v0.0.20
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
github.com/nspcc-dev/dbft v0.3.2
Expand All @@ -68,13 +70,13 @@ require (
github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.4.1
go.uber.org/automaxprocs v1.5.2
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.33.0
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948
golang.org/x/sync v0.11.0
golang.org/x/sys v0.30.0
golang.org/x/text v0.22.0
golang.org/x/crypto v0.39.0
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476
golang.org/x/sync v0.15.0
golang.org/x/sys v0.33.0
golang.org/x/text v0.26.0
golang.org/x/time v0.3.0
golang.org/x/tools v0.24.0
golang.org/x/tools v0.34.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -94,31 +96,29 @@ require (
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 // indirect
github.com/aws/smithy-go v1.15.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.20.0 // indirect
github.com/bits-and-blooms/bitset v1.22.0 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.8.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f // indirect
github.com/cockroachdb/redact v1.0.8 // indirect
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.29 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/deepmap/oapi-codegen v1.6.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.8.0 // indirect
github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
github.com/google/pprof v0.0.0-20250607225305-033d6d78b36a // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/ingonyama-zk/icicle/v3 v3.1.1-0.20241118092657-fccdb2f0921b // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kilic/bls12-381 v0.1.0 // indirect
github.com/klauspost/compress v1.15.15 // indirect
Expand All @@ -130,7 +130,6 @@ require (
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/pointerstructure v1.2.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand All @@ -141,17 +140,16 @@ require (
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/ronanh/intcomp v1.1.0 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/ronanh/intcomp v1.1.1 // indirect
github.com/rs/zerolog v1.34.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/mod v0.25.0 // indirect
golang.org/x/net v0.41.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading
Loading