From cb855fec71598ca8816f7a121a2d4de002effa24 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Fri, 18 Oct 2024 17:59:54 +0200 Subject: [PATCH] Adding support for evmnet --- networks/fixed/fixed.go | 32 ++ networks/fixed/fixed_test.go | 374 ++++++++++++++++++ networks/http/http.go | 6 +- networks/http/http_test.go | 58 +++ ...em-timevault-fastnet-2024-01-17-16-12.tle} | 0 ...testnet-unchained-3s-2024-01-17-16-12.tle} | 0 tlock.go | 20 +- tlock_test.go | 78 +++- 8 files changed, 545 insertions(+), 23 deletions(-) create mode 100644 networks/fixed/fixed_test.go create mode 100644 networks/http/http_test.go rename testdata/{lorem-timevault-mainnet-2024-01-17-16-12.tle => lorem-timevault-fastnet-2024-01-17-16-12.tle} (100%) rename testdata/{lorem-timevault-testnet-2024-01-17-16-12.tle => lorem-timevault-testnet-unchained-3s-2024-01-17-16-12.tle} (100%) diff --git a/networks/fixed/fixed.go b/networks/fixed/fixed.go index 7cb216a..0478f19 100644 --- a/networks/fixed/fixed.go +++ b/networks/fixed/fixed.go @@ -2,6 +2,7 @@ package fixed import ( + "encoding/json" "errors" "time" @@ -31,6 +32,7 @@ func NewNetwork(chainHash string, publicKey kyber.Point, sch *crypto.Scheme, per case crypto.ShortSigSchemeID: case crypto.SigsOnG1ID: case crypto.UnchainedSchemeID: + case crypto.BN254UnchainedOnG1SchemeID: default: return nil, ErrNotUnchained } @@ -45,6 +47,36 @@ func NewNetwork(chainHash string, publicKey kyber.Point, sch *crypto.Scheme, per }, nil } +type infoV2 struct { + PublicKey chain.HexBytes `json:"public_key"` + ID string `json:"beacon_id,beaconID"` + Period int64 `json:"period"` + Scheme string `json:"scheme"` + GenesisTime int64 `json:"genesis_time"` + ChainHash string `json:"chain_hash,hash"` +} + +func FromInfo(jsonInfo string) (*Network, error) { + info := new(infoV2) + err := json.Unmarshal([]byte(jsonInfo), info) + if err != nil { + return nil, err + } + sch, err := crypto.SchemeFromName(info.Scheme) + if err != nil { + return nil, err + } + public := sch.KeyGroup.Point() + if err := public.UnmarshalBinary(info.PublicKey); err != nil { + return nil, err + } + return NewNetwork(info.ChainHash, public, sch, time.Duration(info.Period)*time.Second, info.GenesisTime, nil) +} + +func (n *Network) SetSignature(sig []byte) { + n.fixedSig = sig +} + // ChainHash returns the chain hash for this network. func (n *Network) ChainHash() string { return n.chainHash diff --git a/networks/fixed/fixed_test.go b/networks/fixed/fixed_test.go new file mode 100644 index 0000000..6782a60 --- /dev/null +++ b/networks/fixed/fixed_test.go @@ -0,0 +1,374 @@ +package fixed + +import ( + "reflect" + "testing" + "time" + + "github.com/drand/drand/v2/crypto" + "github.com/drand/kyber" + "github.com/stretchr/testify/require" +) + +func TestFromInfo(t *testing.T) { + tests := []struct { + name string + jsonStr string + wantHash string + wantScheme string + wantErr error + }{ + { + name: "default", + jsonStr: `{"public_key":"868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31","period":30,"genesis_time":1595431050,"genesis_seed":"176f93498eac9ca337150b46d21dd58673ea4e3581185f869672e59fa4cb390a","chain_hash":"8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce","scheme":"pedersen-bls-chained","beacon_id":"default"}`, + wantHash: "", + wantScheme: "", + wantErr: ErrNotUnchained, + }, { + name: "evmnet", + jsonStr: `{"public_key":"07e1d1d335df83fa98462005690372c643340060d205306a9aa8106b6bd0b3820557ec32c2ad488e4d4f6008f89a346f18492092ccc0d594610de2732c8b808f0095685ae3a85ba243747b1b2f426049010f6b73a0cf1d389351d5aaaa1047f6297d3a4f9749b33eb2d904c9d9ebf17224150ddd7abd7567a9bec6c74480ee0b","period":3,"genesis_time":1727521075,"genesis_seed":"cd7ad2f0e0cce5d8c288f2dd016ffe7bc8dc88dbb229b3da2b6ad736490dfed6","chain_hash":"04f1e9062b8a81f848fded9c12306733282b2727ecced50032187751166ec8c3","scheme":"bls-bn254-unchained-on-g1","beacon_id":"evmnet"}`, + wantHash: "04f1e9062b8a81f848fded9c12306733282b2727ecced50032187751166ec8c3", + wantScheme: "bls-bn254-unchained-on-g1", + wantErr: nil, + }, { + name: "quicknet", + jsonStr: `{"public_key":"83cf0f2896adee7eb8b5f01fcad3912212c437e0073e911fb90022d3e760183c8c4b450b6a0a6c3ac6a5776a2d1064510d1fec758c921cc22b0e17e63aaf4bcb5ed66304de9cf809bd274ca73bab4af5a6e9c76a4bc09e76eae8991ef5ece45a","period":3,"genesis_time":1692803367,"genesis_seed":"f477d5c89f21a17c863a7f937c6a6d15859414d2be09cd448d4279af331c5d3e","chain_hash":"52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971","scheme":"bls-unchained-g1-rfc9380","beacon_id":"quicknet"}`, + wantHash: "52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971", + wantScheme: "bls-unchained-g1-rfc9380", + wantErr: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := FromInfo(tt.jsonStr) + require.ErrorIs(t, err, tt.wantErr) + if err == nil { + if got.ChainHash() != tt.wantHash { + t.Errorf("FromInfo() got = %v, want %v", got.ChainHash(), tt.wantHash) + } + if got.Scheme().Name != tt.wantScheme { + t.Errorf("FromInfo() got = %v, want %v", got.ChainHash(), tt.wantHash) + } + require.Equal(t, uint64(1), got.RoundNumber(time.Unix(got.genesis, 0))) + } + }) + } +} + +func TestNetwork_ChainHash(t *testing.T) { + type fields struct { + chainHash string + publicKey kyber.Point + scheme *crypto.Scheme + period time.Duration + genesis int64 + fixedSig []byte + } + tests := []struct { + name string + fields fields + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + n := &Network{ + chainHash: tt.fields.chainHash, + publicKey: tt.fields.publicKey, + scheme: tt.fields.scheme, + period: tt.fields.period, + genesis: tt.fields.genesis, + fixedSig: tt.fields.fixedSig, + } + if got := n.ChainHash(); got != tt.want { + t.Errorf("ChainHash() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetwork_Current(t *testing.T) { + type fields struct { + chainHash string + publicKey kyber.Point + scheme *crypto.Scheme + period time.Duration + genesis int64 + fixedSig []byte + } + type args struct { + date time.Time + } + tests := []struct { + name string + fields fields + args args + want uint64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + n := &Network{ + chainHash: tt.fields.chainHash, + publicKey: tt.fields.publicKey, + scheme: tt.fields.scheme, + period: tt.fields.period, + genesis: tt.fields.genesis, + fixedSig: tt.fields.fixedSig, + } + if got := n.Current(tt.args.date); got != tt.want { + t.Errorf("Current() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetwork_PublicKey(t *testing.T) { + type fields struct { + chainHash string + publicKey kyber.Point + scheme *crypto.Scheme + period time.Duration + genesis int64 + fixedSig []byte + } + tests := []struct { + name string + fields fields + want kyber.Point + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + n := &Network{ + chainHash: tt.fields.chainHash, + publicKey: tt.fields.publicKey, + scheme: tt.fields.scheme, + period: tt.fields.period, + genesis: tt.fields.genesis, + fixedSig: tt.fields.fixedSig, + } + if got := n.PublicKey(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("PublicKey() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetwork_RoundNumber(t *testing.T) { + type fields struct { + chainHash string + publicKey kyber.Point + scheme *crypto.Scheme + period time.Duration + genesis int64 + fixedSig []byte + } + type args struct { + t time.Time + } + tests := []struct { + name string + fields fields + args args + want uint64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + n := &Network{ + chainHash: tt.fields.chainHash, + publicKey: tt.fields.publicKey, + scheme: tt.fields.scheme, + period: tt.fields.period, + genesis: tt.fields.genesis, + fixedSig: tt.fields.fixedSig, + } + if got := n.RoundNumber(tt.args.t); got != tt.want { + t.Errorf("RoundNumber() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetwork_Scheme(t *testing.T) { + type fields struct { + chainHash string + publicKey kyber.Point + scheme *crypto.Scheme + period time.Duration + genesis int64 + fixedSig []byte + } + tests := []struct { + name string + fields fields + want crypto.Scheme + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + n := &Network{ + chainHash: tt.fields.chainHash, + publicKey: tt.fields.publicKey, + scheme: tt.fields.scheme, + period: tt.fields.period, + genesis: tt.fields.genesis, + fixedSig: tt.fields.fixedSig, + } + if got := n.Scheme(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Scheme() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetwork_SetSignature(t *testing.T) { + type fields struct { + chainHash string + publicKey kyber.Point + scheme *crypto.Scheme + period time.Duration + genesis int64 + fixedSig []byte + } + type args struct { + sig []byte + } + tests := []struct { + name string + fields fields + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + n := &Network{ + chainHash: tt.fields.chainHash, + publicKey: tt.fields.publicKey, + scheme: tt.fields.scheme, + period: tt.fields.period, + genesis: tt.fields.genesis, + fixedSig: tt.fields.fixedSig, + } + n.SetSignature(tt.args.sig) + }) + } +} + +func TestNetwork_Signature(t *testing.T) { + type fields struct { + chainHash string + publicKey kyber.Point + scheme *crypto.Scheme + period time.Duration + genesis int64 + fixedSig []byte + } + type args struct { + in0 uint64 + } + tests := []struct { + name string + fields fields + args args + want []byte + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + n := &Network{ + chainHash: tt.fields.chainHash, + publicKey: tt.fields.publicKey, + scheme: tt.fields.scheme, + period: tt.fields.period, + genesis: tt.fields.genesis, + fixedSig: tt.fields.fixedSig, + } + got, err := n.Signature(tt.args.in0) + if (err != nil) != tt.wantErr { + t.Errorf("Signature() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("Signature() got = %v, want %v", got, tt.want) + } + }) + } +} + +func TestNetwork_SwitchChainHash(t *testing.T) { + type fields struct { + chainHash string + publicKey kyber.Point + scheme *crypto.Scheme + period time.Duration + genesis int64 + fixedSig []byte + } + type args struct { + c string + } + tests := []struct { + name string + fields fields + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + n := &Network{ + chainHash: tt.fields.chainHash, + publicKey: tt.fields.publicKey, + scheme: tt.fields.scheme, + period: tt.fields.period, + genesis: tt.fields.genesis, + fixedSig: tt.fields.fixedSig, + } + if err := n.SwitchChainHash(tt.args.c); (err != nil) != tt.wantErr { + t.Errorf("SwitchChainHash() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNewNetwork(t *testing.T) { + type args struct { + chainHash string + publicKey kyber.Point + sch *crypto.Scheme + period time.Duration + genesis int64 + sig []byte + } + tests := []struct { + name string + args args + want *Network + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := NewNetwork(tt.args.chainHash, tt.args.publicKey, tt.args.sch, tt.args.period, tt.args.genesis, tt.args.sig) + if (err != nil) != tt.wantErr { + t.Errorf("NewNetwork() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewNetwork() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/networks/http/http.go b/networks/http/http.go index 432d85e..e391f72 100644 --- a/networks/http/http.go +++ b/networks/http/http.go @@ -69,12 +69,16 @@ func NewNetwork(host string, chainHash string) (*Network, error) { return nil, fmt.Errorf("getting client information: %w", err) } + if info.HashString() != chainHash { + return nil, fmt.Errorf("chain hash mistmatch: (requested) %s!=%s (received)", chainHash, info.HashString()) + } + sch, err := crypto.SchemeFromName(info.Scheme) if err != nil { return nil, ErrNotUnchained } - if !(sch.Name == crypto.UnchainedSchemeID || sch.Name == crypto.ShortSigSchemeID || sch.Name == crypto.SigsOnG1ID) { + if sch.Name == crypto.DefaultSchemeID { return nil, ErrNotUnchained } diff --git a/networks/http/http_test.go b/networks/http/http_test.go new file mode 100644 index 0000000..466afdd --- /dev/null +++ b/networks/http/http_test.go @@ -0,0 +1,58 @@ +package http + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestNetwork_ChainHash(t *testing.T) { + if testing.Short() { + t.Skip("skipping interactive network tests in short mode.") + } + + tests := []struct { + name string + host string + want string + shouldError bool + }{ + { + "quicknet", + "api.drand.sh", + "52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971", + false, + }, + { + "quicknet-t", + "http://pl-eu.testnet.drand.sh", + "cc9c398442737cbd141526600919edd69f1d6f9b4adb67e4d912fbc64341a9a5", + false, + }, + { + "evmnet", + "https://api2.drand.sh", + "04f1e9062b8a81f848fded9c12306733282b2727ecced50032187751166ec8c3", + false, + }, + { + "default", + "https://api2.drand.sh", + "8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce", + true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + n, err := NewNetwork(tt.host, tt.want) + if tt.shouldError { + require.Error(t, err) + return + } + require.NoError(t, err) + if got := n.ChainHash(); got != tt.want { + t.Errorf("ChainHash() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/testdata/lorem-timevault-mainnet-2024-01-17-16-12.tle b/testdata/lorem-timevault-fastnet-2024-01-17-16-12.tle similarity index 100% rename from testdata/lorem-timevault-mainnet-2024-01-17-16-12.tle rename to testdata/lorem-timevault-fastnet-2024-01-17-16-12.tle diff --git a/testdata/lorem-timevault-testnet-2024-01-17-16-12.tle b/testdata/lorem-timevault-testnet-unchained-3s-2024-01-17-16-12.tle similarity index 100% rename from testdata/lorem-timevault-testnet-2024-01-17-16-12.tle rename to testdata/lorem-timevault-testnet-unchained-3s-2024-01-17-16-12.tle diff --git a/tlock.go b/tlock.go index a56be55..569e2f4 100644 --- a/tlock.go +++ b/tlock.go @@ -17,6 +17,7 @@ import ( "github.com/drand/kyber" bls "github.com/drand/kyber-bls12381" "github.com/drand/kyber/encrypt/ibe" + bn "github.com/drand/kyber/pairing/bn254" "gopkg.in/yaml.v3" ) @@ -136,7 +137,7 @@ func (t Tlock) Metadata(dst io.Writer) (err error) { // TimeLock encrypts the specified data for the given round number. The data // can't be decrypted until the specified round is reached by the network in use. func TimeLock(scheme crypto.Scheme, publicKey kyber.Point, roundNumber uint64, data []byte) (*ibe.Ciphertext, error) { - if publicKey.Equal(publicKey.Null()) { + if publicKey.Equal(publicKey.Clone().Null()) { return nil, ErrInvalidPublicKey } @@ -154,6 +155,11 @@ func TimeLock(scheme crypto.Scheme, publicKey kyber.Point, roundNumber uint64, d cipherText, err = ibe.EncryptCCAonG1(bls.NewBLS12381Suite(), publicKey, id, data) case crypto.SigsOnG1ID: cipherText, err = ibe.EncryptCCAonG2(bls.NewBLS12381Suite(), publicKey, id, data) + case crypto.BN254UnchainedOnG1SchemeID: + suite := bn.NewSuiteBn254() + suite.SetDomainG1([]byte("BLS_SIG_BN254G1_XMD:KECCAK-256_SVDW_RO_NUL_")) + suite.SetDomainG2([]byte("BLS_SIG_BN254G2_XMD:KECCAK-256_SVDW_RO_NUL_")) + cipherText, err = ibe.EncryptCCAonG2(suite, publicKey, id, data) default: return nil, fmt.Errorf("unsupported drand scheme '%s'", scheme.Name) } @@ -194,6 +200,15 @@ func TimeUnlock(scheme crypto.Scheme, publicKey kyber.Point, beacon chain.Beacon return nil, fmt.Errorf("unmarshal kyber G1: %w", err) } data, err = ibe.DecryptCCAonG2(bls.NewBLS12381Suite(), &signature, ciphertext) + case crypto.BN254UnchainedOnG1SchemeID: + suite := bn.NewSuiteBn254() + suite.SetDomainG1([]byte("BLS_SIG_BN254G1_XMD:KECCAK-256_SVDW_RO_NUL_")) + suite.SetDomainG2([]byte("BLS_SIG_BN254G2_XMD:KECCAK-256_SVDW_RO_NUL_")) + signature := suite.G1().Point() + if err := signature.UnmarshalBinary(beacon.Signature); err != nil { + return nil, fmt.Errorf("unmarshal kyber G1: %w", err) + } + data, err = ibe.DecryptCCAonG2(suite, signature, ciphertext) default: return nil, fmt.Errorf("unsupported drand scheme '%s'", scheme.Name) } @@ -248,6 +263,9 @@ func BytesToCiphertext(scheme crypto.Scheme, b []byte) (*ibe.Ciphertext, error) cipherW := make([]byte, cipherVLen) copy(cipherW, b[kyberPointLen+cipherVLen:]) + if len(b[kyberPointLen+cipherVLen:]) != cipherVLen { + return nil, fmt.Errorf("invalid ciphertext length: %d", len(b[kyberPointLen+cipherVLen:])) + } u := scheme.KeyGroup.Point() if err := u.UnmarshalBinary(kyberPoint); err != nil { diff --git a/tlock_test.go b/tlock_test.go index bd5a7b2..e29bda3 100644 --- a/tlock_test.go +++ b/tlock_test.go @@ -3,6 +3,7 @@ package tlock_test import ( "bytes" _ "embed" // Calls init function. + "encoding/hex" "errors" "os" "path/filepath" @@ -14,6 +15,7 @@ import ( "github.com/drand/drand/v2/crypto" bls "github.com/drand/kyber-bls12381" "github.com/drand/tlock" + "github.com/drand/tlock/networks/fixed" "github.com/drand/tlock/networks/http" "github.com/stretchr/testify/require" @@ -32,6 +34,7 @@ const ( testnetQuicknetT = "cc9c398442737cbd141526600919edd69f1d6f9b4adb67e4d912fbc64341a9a5" mainnetHost = "http://api.drand.sh/" mainnetQuicknet = "52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971" + mainnetEvm = "04f1e9062b8a81f848fded9c12306733282b2727ecced50032187751166ec8c3" ) func TestEarlyDecryptionWithDuration(t *testing.T) { @@ -244,29 +247,57 @@ func TestEncryptionWithRound(t *testing.T) { } func TestTimeLockUnlock(t *testing.T) { - network, err := http.NewNetwork(testnetHost, testnetQuicknetT) - require.NoError(t, err) + if testing.Short() { + t.Skip("skipping live testing in short mode") + } + tests := []struct { + name string + host string + chainhash string + }{ + { + "quicknetT", + testnetHost, + testnetQuicknetT, + }, + { + "quicknet", + mainnetHost, + mainnetQuicknet, + }, + { + "evmnet", + mainnetHost, + mainnetEvm, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + network, err := http.NewNetwork(tt.host, tt.chainhash) + require.NoError(t, err) - futureRound := network.RoundNumber(time.Now()) + futureRound := network.RoundNumber(time.Now()) - id, err := network.Signature(futureRound) - require.NoError(t, err) + id, err := network.Signature(futureRound) + require.NoError(t, err) - data := []byte(`anything`) + data := []byte(`anything`) - cipherText, err := tlock.TimeLock(network.Scheme(), network.PublicKey(), futureRound, data) - require.NoError(t, err) + cipherText, err := tlock.TimeLock(network.Scheme(), network.PublicKey(), futureRound, data) + require.NoError(t, err) - beacon := chain.Beacon{ - Round: futureRound, - Signature: id, - } + beacon := chain.Beacon{ + Round: futureRound, + Signature: id, + } - b, err := tlock.TimeUnlock(network.Scheme(), network.PublicKey(), beacon, cipherText) - require.NoError(t, err) + b, err := tlock.TimeUnlock(network.Scheme(), network.PublicKey(), beacon, cipherText) + require.NoError(t, err) - if !bytes.Equal(data, b) { - t.Fatalf("unexpected bytes; expected len %d; got %d", len(data), len(b)) + if !bytes.Equal(data, b) { + t.Fatalf("unexpected bytes; expected len %d; got %d", len(data), len(b)) + } + }) } } @@ -301,10 +332,15 @@ SW9KaGtndTVTRnJUOGVVQTJUOGk3aTBwQlBzTDlTWUJUZEJQb28KLS0tIEl6Q1Js WSt1RXp0d21CbEg0cTFVZGNJaW9pS2l0M0c0bHVxNlNjT2w3UUUKDI4cDlPHPgjy UnBmtsw6U2LlKh8iDf0E1PfwDenmKFfQaAGm0WLxdlzP8Q== -----END AGE ENCRYPTED FILE-----` + t.Run("With valid network", func(tt *testing.T) { - network, err := http.NewNetwork(mainnetHost, mainnetQuicknet) + network, err := fixed.FromInfo(`{"public_key":"83cf0f2896adee7eb8b5f01fcad3912212c437e0073e911fb90022d3e760183c8c4b450b6a0a6c3ac6a5776a2d1064510d1fec758c921cc22b0e17e63aaf4bcb5ed66304de9cf809bd274ca73bab4af5a6e9c76a4bc09e76eae8991ef5ece45a","period":3,"genesis_time":1692803367,"genesis_seed":"f477d5c89f21a17c863a7f937c6a6d15859414d2be09cd448d4279af331c5d3e","chain_hash":"52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971","scheme":"bls-unchained-g1-rfc9380","beacon_id":"quicknet"}`) + require.NoError(tt, err) + sig, err := hex.DecodeString("929906c959032ab363c9f26570d215d66f5c06cb0c44fe508c12bb5839f04ec895bb6868e5b9ff13ab289bdb5266b394") require.NoError(tt, err) + network.SetSignature(sig) + testReader := strings.NewReader(cipher) var plainData bytes.Buffer @@ -315,24 +351,24 @@ UnBmtsw6U2LlKh8iDf0E1PfwDenmKFfQaAGm0WLxdlzP8Q== }) t.Run("With invalid network", func(tt *testing.T) { - network, err := http.NewNetwork(testnetHost, testnetUnchainedOnG2) + network, err := fixed.FromInfo(`{"public_key":"07e1d1d335df83fa98462005690372c643340060d205306a9aa8106b6bd0b3820557ec32c2ad488e4d4f6008f89a346f18492092ccc0d594610de2732c8b808f0095685ae3a85ba243747b1b2f426049010f6b73a0cf1d389351d5aaaa1047f6297d3a4f9749b33eb2d904c9d9ebf17224150ddd7abd7567a9bec6c74480ee0b","period":3,"genesis_time":1727521075,"genesis_seed":"cd7ad2f0e0cce5d8c288f2dd016ffe7bc8dc88dbb229b3da2b6ad736490dfed6","chain_hash":"04f1e9062b8a81f848fded9c12306733282b2727ecced50032187751166ec8c3","scheme":"bls-bn254-unchained-on-g1","beacon_id":"evmnet"}`) require.NoError(tt, err) testReader := strings.NewReader(cipher) var plainData bytes.Buffer - err = tlock.New(network).Decrypt(&plainData, testReader) + err = tlock.New(network).Strict().Decrypt(&plainData, testReader) require.ErrorIs(tt, err, tlock.ErrWrongChainhash) }) t.Run("With quicknet-t invalid network", func(tt *testing.T) { - network, err := http.NewNetwork(testnetHost, testnetQuicknetT) + network, err := fixed.FromInfo(`{"public_key":"b15b65b46fb29104f6a4b5d1e11a8da6344463973d423661bb0804846a0ecd1ef93c25057f1c0baab2ac53e56c662b66072f6d84ee791a3382bfb055afab1e6a375538d8ffc451104ac971d2dc9b168e2d3246b0be2015969cbaac298f6502da","period":3,"genesis_time":1689232296,"genesis_seed":"40d49d910472d4adb1d67f65db8332f11b4284eecf05c05c5eacd5eef7d40e2d","chain_hash":"cc9c398442737cbd141526600919edd69f1d6f9b4adb67e4d912fbc64341a9a5","scheme":"bls-unchained-g1-rfc9380","beacon_id":"quicknet-t"}`) require.NoError(tt, err) testReader := strings.NewReader(cipher) var plainData bytes.Buffer - err = tlock.New(network).Decrypt(&plainData, testReader) + err = tlock.New(network).Strict().Decrypt(&plainData, testReader) require.ErrorIs(tt, err, tlock.ErrWrongChainhash) }) }