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

rc/1.7.next1 #835

Merged
merged 162 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
2449f64
integrate vm-common and core
BeniaminDrasovean Jan 5, 2024
81117be
Merge remote-tracking branch 'origin/rc/v1.7.0' into esdt-improvements
BeniaminDrasovean Jan 30, 2024
bcb98ba
update go mod
BeniaminDrasovean Jan 30, 2024
f672b84
working on new crypto primitives
sasurobert Feb 7, 2024
2b153cf
working on new crypto primitives
sasurobert Feb 9, 2024
077f9f4
working on new crypto primitives
sasurobert Feb 9, 2024
fad823f
working on new crypto primitives
sasurobert Feb 9, 2024
494f4f3
cleanup of activation functions.
sasurobert Feb 9, 2024
21858ac
Merge branch 'rc/v1.7.0' into multiBLS-secpr1-more-crypto
sasurobert Feb 9, 2024
fb65da1
continue implementation
sasurobert Feb 12, 2024
3ad8079
continue implementation
sasurobert Feb 12, 2024
268ed0f
continue implementation
sasurobert Feb 12, 2024
16403ff
fixing tests
sasurobert Feb 12, 2024
73b0f8b
fixing tests
sasurobert Feb 12, 2024
8bf984e
fixing tests
sasurobert Feb 12, 2024
5f9a101
Merge branch 'rc/v1.7.0' into multiBLS-secpr1-more-crypto
sasurobert Feb 12, 2024
bacdedc
VM hooks generator readme
andrei-marinica Feb 12, 2024
cadaeac
VM executor lib update
andrei-marinica Feb 12, 2024
2f739cc
fixing tests
sasurobert Feb 12, 2024
43258e9
Merge remote-tracking branch 'origin/multiBLS-secpr1-more-crypto' int…
sasurobert Feb 12, 2024
46f5dd4
just to see that all tests still work on git
sasurobert Feb 12, 2024
909e7c9
BLS tests
sasurobert Feb 14, 2024
3b7c3fd
all kinds of tests
sasurobert Feb 14, 2024
8885388
implementation of GetRelayer, GetOriginal and Enable Readable User Ac…
sasurobert Feb 15, 2024
329c0fc
Merge branch 'rc/v1.7.0' into esdt-improvements
sasurobert Mar 6, 2024
b623710
Merge pull request #828 from multiversx/small-new-endpoints-rc1.7
sasurobert Mar 6, 2024
a135d99
Merge branch 'rc/v1.7.next1' into multiBLS-secpr1-more-crypto
sasurobert Mar 6, 2024
201547f
new vm-common
sasurobert Mar 6, 2024
56a5c10
Merge remote-tracking branch 'origin/multiBLS-secpr1-more-crypto' int…
sasurobert Mar 6, 2024
f7dd673
new vm-common
sasurobert Mar 6, 2024
628f217
initial implementation for transfer and execute by user.
sasurobert Mar 20, 2024
3e5a88b
updated deps after merge for rc/v1.7.next1
sstanculeanu Mar 21, 2024
22c17d2
Merge pull request #836 from multiversx/merge_rc170_into_rc17next1_20…
sstanculeanu Mar 22, 2024
10c829f
initial implementation for transfer and execute by user.
sasurobert Mar 25, 2024
08876bf
initial implementation for transfer and execute by user.
sasurobert Mar 25, 2024
1ba8e09
Merge branch 'rc/v1.7.next1' into multiBLS-secpr1-more-crypto
sasurobert Mar 26, 2024
ad7b435
merge
sasurobert Mar 26, 2024
cb01c90
Merge branch 'multiBLS-secpr1-more-crypto' into transferAndExecute-by…
sasurobert Mar 26, 2024
62c3721
TransferESDTNFTExecuteByUser tests
laurci Mar 26, 2024
10d3671
TransferESDTNFTExecuteByUser tests
laurci Mar 26, 2024
53b13ef
Merge remote-tracking branch 'origin/rc/v1.7.next1' into esdt-improve…
BeniaminDrasovean Mar 28, 2024
b5f2c7c
update go mod
BeniaminDrasovean Mar 28, 2024
c88a71b
fixing tests.
sasurobert Mar 28, 2024
78e40e3
vmHooks generator alignemnt fix
andrei-marinica Mar 28, 2024
77cba6f
vmHooks - wasmer2 - transfer execute by user
andrei-marinica Mar 28, 2024
e183ffd
Merge pull request #806 from multiversx/esdt-improvements
sasurobert Apr 11, 2024
2c12fd9
use IsAllowedToExecute
sasurobert Apr 11, 2024
6b8168a
Merge remote-tracking branch 'origin/transferAndExecute-by-user' into…
sasurobert Apr 11, 2024
f12b4d0
Merge pull request #837 from multiversx/transferAndExecute-by-user
sasurobert Apr 11, 2024
ee735a7
Merge branch 'rc/v1.7.next1' into multiBLS-secpr1-more-crypto
sasurobert Apr 11, 2024
33d6325
go mod
sasurobert Apr 11, 2024
40ac6e9
libvmexeccapi.h fix
andrei-marinica Apr 11, 2024
6dd39b1
no log trace
sasurobert Apr 12, 2024
a4f1a6b
Remove bad logging and dead test code.
andreibancioiu Apr 12, 2024
d17d20e
Update wasmer2 libraries.
andreibancioiu Apr 12, 2024
c65ec59
linter
sasurobert Apr 12, 2024
462b246
Merge remote-tracking branch 'origin/multiBLS-secpr1-more-crypto' int…
sasurobert Apr 12, 2024
766ae96
Log key when storage unchanged
lcswillems Apr 16, 2024
ab157e0
Merge branch 'rc/v1.7.next1' into lcswillems-patch-1
lcswillems Apr 16, 2024
4958bb2
Merge pull request #843 from multiversx/lcswillems-patch-1
sasurobert Apr 23, 2024
3be96b3
Merge branch 'rc/v1.7.next1' into multiBLS-secpr1-more-crypto
sasurobert Apr 23, 2024
bfe3bf2
fix and new go mod
sasurobert Apr 23, 2024
a970819
fixing used constant
sasurobert Apr 24, 2024
27f4efb
deleting useless code
sasurobert Apr 24, 2024
70dca74
Add timeout parameter to ScenarioVMHostBuilder
lcswillems Apr 28, 2024
02adfee
Merge branch 'rc/v1.7.next1' into lcswillems-patch-2
lcswillems Apr 28, 2024
22e7b7c
Update vmBuilder.go
lcswillems Apr 28, 2024
dd3c70f
Update vmBuilder.go
lcswillems Apr 28, 2024
2d7f3b0
Update vmBuilder.go
lcswillems Apr 28, 2024
31dea4d
rename
sasurobert Apr 29, 2024
06dad35
Macos-latest is now ARM64.
andreibancioiu Apr 30, 2024
59fd4f9
Merge pull request #846 from multiversx/workflow-macos-update
sasurobert Apr 30, 2024
8e89ddb
Merge pull request #825 from multiversx/multiBLS-secpr1-more-crypto
sasurobert May 7, 2024
4a35c41
Merge branch 'rc/v1.7.0' of https://github.com/multiversx/mx-chain-vm…
sstanculeanu May 8, 2024
1abf13a
updated dependencies after merge
sstanculeanu May 8, 2024
8b0eaa8
updated scenario-go + vm-common
sstanculeanu May 9, 2024
7b95ee6
Merge pull request #847 from multiversx/merge_rc170_into_rc17next1_20…
sstanculeanu May 10, 2024
fe307a4
add missing esdt roles for cyrpto opcodes v2
laurci May 20, 2024
967f02c
moving execution to safer place
sasurobert May 20, 2024
eb7022d
Merge pull request #849 from multiversx/fix/missing-crypto-v2-api-roles
laurci May 20, 2024
ca5b441
moving execution to safer place
sasurobert May 20, 2024
df81a70
Merge branch 'rc/v1.7.next1' into fixing-other-vm-exec
sasurobert May 20, 2024
ddaf9fa
adding logs
sasurobert May 20, 2024
29d47c8
Merge remote-tracking branch 'origin/fixing-other-vm-exec' into fixin…
sasurobert May 20, 2024
36ebab5
adding logs
sasurobert May 20, 2024
d546729
cleanup logs
sasurobert May 20, 2024
48f94ef
Merge pull request #850 from multiversx/fixing-other-vm-exec
mariusmihaic May 22, 2024
60819ff
Merge branch 'rc/v1.7.next1' into lcswillems-patch-2
lcswillems Jun 3, 2024
5fbcb08
Update vmBuilder.go
lcswillems Jun 3, 2024
85a951f
IsBuiltinFunctionName vmhook impl
laurci Jun 7, 2024
f6cad3f
update wasmer executor binaries
laurci Jun 7, 2024
d2c138f
rename to IsReservedFunctionName
laurci Jun 10, 2024
574cad9
add IsReservedFunctionName gas value to map
laurci Jun 10, 2024
f86de14
IsReservedFunctionName no variable gas cost
laurci Jun 10, 2024
a7aae94
accept managed buffer handle instead of memory range for IsReservedFu…
laurci Jun 13, 2024
5f1cbb8
Merge pull request #844 from multiversx/lcswillems-patch-2
sasurobert Jun 13, 2024
b206a3f
Merge branch 'rc/v1.7.next1' into is-builtin-function-vmhook
sasurobert Jun 13, 2024
98ab26a
Merge pull request #851 from multiversx/is-builtin-function-vmhook
sasurobert Jun 13, 2024
a98380e
fix and add test
sasurobert Jul 3, 2024
9de107a
Merge pull request #855 from multiversx/fix-check-readable-user-addr
sasurobert Jul 4, 2024
ec175da
update vm-common version
BeniaminDrasovean Jul 15, 2024
c7de865
Merge pull request #856 from multiversx/update-dependencies
BeniaminDrasovean Jul 16, 2024
15718b4
Merge branch 'master' of https://github.com/multiversx/mx-chain-vm-go…
sstanculeanu Jul 25, 2024
3f682a6
updated deps after merge
sstanculeanu Jul 25, 2024
c4890f3
Merge pull request #857 from multiversx/merge_master_into_rc17next1_2…
sstanculeanu Jul 25, 2024
9001fca
adding separate flag
sasurobert Jul 26, 2024
e3e50b6
adding separate flag
sasurobert Jul 26, 2024
1a6d87a
Merge pull request #858 from multiversx/separate-flag-multi-transfer-…
sstanculeanu Jul 29, 2024
ea492b9
updated deps
sstanculeanu Jul 29, 2024
b9c0bc9
Merge pull request #860 from multiversx/update_deps
sstanculeanu Jul 30, 2024
816d654
even newer build
sasurobert Aug 1, 2024
d504893
even newer build
sasurobert Aug 2, 2024
fb3b2b3
Merge pull request #864 from multiversx/wasmer-binaries-1.7.next1
sstanculeanu Aug 6, 2024
f1fbbf1
Merge branch 'master' of https://github.com/multiversx/mx-chain-vm-go…
sstanculeanu Aug 8, 2024
6a660fe
Merge pull request #866 from multiversx/merge_master_into_rc17next1_2…
sstanculeanu Aug 9, 2024
63e7922
update go mod
BeniaminDrasovean Aug 12, 2024
1f3c25b
update go mod
BeniaminDrasovean Aug 12, 2024
80062df
Merge pull request #867 from multiversx/fix-esdt-metaData-in-system-a…
ssd04 Aug 16, 2024
c9deb92
Merge branch 'master' into merge-master-rc1.7.next1-20-08-2024
sasurobert Aug 20, 2024
50984af
fixing after merge
sasurobert Aug 20, 2024
7527911
fixing after merge
sasurobert Aug 20, 2024
6380cfd
update wasmer binaries
laurci Aug 21, 2024
b1c1c71
Merge pull request #870 from multiversx/feat-new-wasmer2-binaries
sasurobert Aug 21, 2024
d0ef01a
Merge branch 'rc/v1.7.next1' into merge-master-rc1.7.next1-20-08-2024
sasurobert Aug 21, 2024
483a1cf
Merge pull request #869 from multiversx/merge-master-rc1.7.next1-20-0…
sasurobert Aug 21, 2024
38b7c6f
update go mod
BeniaminDrasovean Aug 27, 2024
da9374f
Merge pull request #876 from multiversx/save-DynamicNFT-metaData-on-user
BeniaminDrasovean Aug 28, 2024
28231ad
update go mod
BeniaminDrasovean Aug 29, 2024
585b30e
update go mod
BeniaminDrasovean Aug 30, 2024
6c11629
basic features mandos update, incl new crypto functions
andrei-marinica Aug 31, 2024
1ba042b
mandos update - incl crypto func cleanup
andrei-marinica Aug 31, 2024
b2ca609
Merge branch 'rc/v1.7.next1' into new-crypto-mandos
andrei-marinica Sep 2, 2024
2cbc542
Merge pull request #878 from multiversx/new-crypto-mandos
andrei-marinica Sep 2, 2024
71a5013
Merge branch 'rc/v1.7.next1' into dynamic-roles-fix
BeniaminDrasovean Sep 2, 2024
4bf25b4
Merge pull request #877 from multiversx/dynamic-roles-fix
BeniaminDrasovean Sep 2, 2024
ed79085
update vm common version
BeniaminDrasovean Sep 3, 2024
09d768c
Merge pull request #879 from multiversx/esdt-testing-scenarios
BeniaminDrasovean Sep 4, 2024
5cd0677
updated deps to tags
sstanculeanu Sep 9, 2024
d1274b0
Merge pull request #880 from multiversx/new_tags
sstanculeanu Sep 9, 2024
e4a93d0
update go mod
BeniaminDrasovean Sep 12, 2024
e074d8c
Merge pull request #881 from multiversx/keep-metadata-on-zero-liquidi…
BeniaminDrasovean Sep 13, 2024
d4bb784
updated deps to tags
sstanculeanu Sep 17, 2024
b32bde1
Merge pull request #882 from multiversx/new_tags
sstanculeanu Sep 17, 2024
ab0fe3d
errors for invalid signatures in crypto hooks
laurci Sep 17, 2024
ddb140f
fix tests for errors
laurci Sep 17, 2024
18af34a
fix tests for errors
laurci Sep 17, 2024
3d48d5d
Merge pull request #883 from multiversx/crypto-ei-signature-hooks-errors
sstanculeanu Sep 18, 2024
7747153
fix linter
sstanculeanu Sep 18, 2024
75aae18
Merge pull request #884 from multiversx/fix_linter
sstanculeanu Sep 18, 2024
58aebb4
update vm-common version
BeniaminDrasovean Sep 23, 2024
bdba60b
update vm common version
BeniaminDrasovean Sep 23, 2024
38e303b
upgrade wasmer executor version
laurci Sep 23, 2024
d321a4f
Merge pull request #885 from multiversx/zero-nonce-metadata-fix
BeniaminDrasovean Sep 24, 2024
e3cd31d
Merge branch 'rc/v1.7.next1' into upgrade-wasmer-executor-version
sasurobert Sep 24, 2024
94343be
Merge pull request #886 from multiversx/upgrade-wasmer-executor-version
laurci Sep 24, 2024
21115eb
upgrade wasmer executor version
laurci Sep 25, 2024
d10ec7c
upgrade wasmer executor version
laurci Sep 26, 2024
89a2bc3
Merge pull request #889 from multiversx/upgrade-wasmer-executor-versi…
laurci Sep 27, 2024
50cde02
new vm common tags
sstanculeanu Sep 27, 2024
b719e00
Merge pull request #890 from multiversx/new_tags_vm_common
sstanculeanu Sep 27, 2024
0dcfcd7
Merge branch 'master' of https://github.com/multiversx/mx-chain-vm-go…
sstanculeanu Nov 12, 2024
ed43cb5
Merge pull request #893 from multiversx/merge_master_into_rc17next1_2…
sstanculeanu Nov 13, 2024
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
25 changes: 0 additions & 25 deletions .github/workflows/build-test-macos-arm64.yml

This file was deleted.

14 changes: 11 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: |
make test

- name: Test (Linux)
if: runner.os == 'Linux'
run: |
make test

- name: Test (MacOS ARM64)
if: runner.os == 'macOS'
run: |
make test-w2

1 change: 1 addition & 0 deletions config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
DeleteFromReturnData = 10
GetCodeMetadata = 10
IsBuiltinFunction = 10
IsReservedFunctionName = 10

[EthAPICost]
UseGas = 10
Expand Down
38 changes: 21 additions & 17 deletions config/gasCost.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type BaseOpsAPICost struct {
DeleteFromReturnData uint64
GetCodeMetadata uint64
IsBuiltinFunction uint64
IsReservedFunctionName uint64
}

// DynamicStorageLoadCostCoefficients holds the signed coefficients of the func that will compute the gas cost
Expand Down Expand Up @@ -173,23 +174,26 @@ type BigFloatAPICost struct {

// CryptoAPICost defines the crypto operations gas cost config structure
type CryptoAPICost struct {
SHA256 uint64
Keccak256 uint64
Ripemd160 uint64
VerifyBLS uint64
VerifyEd25519 uint64
VerifySecp256k1 uint64
EllipticCurveNew uint64
AddECC uint64
DoubleECC uint64
IsOnCurveECC uint64
ScalarMultECC uint64
MarshalECC uint64
MarshalCompressedECC uint64
UnmarshalECC uint64
UnmarshalCompressedECC uint64
GenerateKeyECC uint64
EncodeDERSig uint64
SHA256 uint64
Keccak256 uint64
Ripemd160 uint64
VerifyBLS uint64
VerifyEd25519 uint64
VerifySecp256k1 uint64
EllipticCurveNew uint64
AddECC uint64
DoubleECC uint64
IsOnCurveECC uint64
ScalarMultECC uint64
MarshalECC uint64
MarshalCompressedECC uint64
UnmarshalECC uint64
UnmarshalCompressedECC uint64
GenerateKeyECC uint64
EncodeDERSig uint64
VerifySecp256r1 uint64
VerifyBLSSignatureShare uint64
VerifyBLSMultiSig uint64
}

// ManagedBufferAPICost defines the managed buffer operations gas cost config structure
Expand Down
9 changes: 9 additions & 0 deletions config/gasSchedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ func FillGasMapBuiltInCosts(value uint64) map[string]uint64 {
gasMap["ESDTNFTAddUri"] = value
gasMap["ESDTNFTUpdateAttributes"] = value
gasMap["ESDTNFTMultiTransfer"] = value
gasMap["ESDTModifyRoyalties"] = value
gasMap["ESDTModifyCreator"] = value
gasMap["ESDTNFTRecreate"] = value
gasMap["ESDTNFTUpdate"] = value
gasMap["ESDTNFTSetNewURIs"] = value
gasMap["SetGuardian"] = value
gasMap["GuardAccount"] = value
gasMap["UnGuardAccount"] = value
Expand Down Expand Up @@ -308,6 +313,7 @@ func FillGasMapBaseOpsAPICosts(value, asyncCallbackGasLock uint64) map[string]ui
gasMap["DeleteFromReturnData"] = value
gasMap["GetCodeMetadata"] = value
gasMap["IsBuiltinFunction"] = value
gasMap["IsReservedFunctionName"] = value

return gasMap
}
Expand Down Expand Up @@ -443,6 +449,9 @@ func FillGasMapCryptoAPICosts(value uint64) map[string]uint64 {
gasMap["UnmarshalCompressedECC"] = value
gasMap["GenerateKeyECC"] = value
gasMap["EncodeDERSig"] = value
gasMap["VerifySecp256r1"] = value
gasMap["VerifyBLSSignatureShare"] = value
gasMap["VerifyBLSMultiSig"] = value

return gasMap
}
Expand Down
26 changes: 18 additions & 8 deletions crypto/factory/cryptovm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ import (
"github.com/multiversx/mx-chain-vm-go/crypto/hashing"
"github.com/multiversx/mx-chain-vm-go/crypto/signing/bls"
"github.com/multiversx/mx-chain-vm-go/crypto/signing/ed25519"
"github.com/multiversx/mx-chain-vm-go/crypto/signing/secp256k1"
"github.com/multiversx/mx-chain-vm-go/crypto/signing/secp256"
)

// NewVMCrypto returns a composite struct containing VMCrypto functionality implementations
func NewVMCrypto() crypto.VMCrypto {
func NewVMCrypto() (crypto.VMCrypto, error) {
blsVerifier, err := bls.NewBLS()
if err != nil {
return nil, err
}

secp, err := secp256.NewSecp256()
if err != nil {
return nil, err
}

return struct {
crypto.Hasher
crypto.Ed25519
crypto.BLS
crypto.Secp256k1
crypto.Secp256
}{
Hasher: hashing.NewHasher(),
Ed25519: ed25519.NewEd25519Signer(),
BLS: bls.NewBLS(),
Secp256k1: secp256k1.NewSecp256k1(),
}
Hasher: hashing.NewHasher(),
Ed25519: ed25519.NewEd25519Signer(),
BLS: blsVerifier,
Secp256: secp,
}, nil
}
9 changes: 6 additions & 3 deletions crypto/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ type Hasher interface {
// BLS defines the functionality of a component able to verify BLS signatures
type BLS interface {
VerifyBLS(key []byte, msg []byte, sig []byte) error
VerifySignatureShare(publicKey []byte, message []byte, sig []byte) error
VerifyAggregatedSig(pubKeysSigners [][]byte, message []byte, aggSig []byte) error
}

// Ed25519 defines the functionality of a component able to verify Ed25519 signatures
type Ed25519 interface {
VerifyEd25519(key []byte, msg []byte, sig []byte) error
}

// Secp256k1 defines the functionality of a component able to verify and encode Secp256k1 signatures
type Secp256k1 interface {
// Secp256 defines the functionality of a component able to verify and encode Secp256 signatures
type Secp256 interface {
VerifySecp256k1(key []byte, msg []byte, sig []byte, hashType uint8) error
EncodeSecp256k1DERSignature(r, s []byte) []byte
VerifySecp256r1(key []byte, msg []byte, sig []byte) error
}

// VMCrypto will provide the interface to the main crypto functionalities of the vm
type VMCrypto interface {
Hasher
Ed25519
BLS
Secp256k1
Secp256
}
21 changes: 19 additions & 2 deletions crypto/signing/bls/bls.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@ import (
"github.com/multiversx/mx-chain-crypto-go"
"github.com/multiversx/mx-chain-crypto-go/signing"
"github.com/multiversx/mx-chain-crypto-go/signing/mcl"
mclMultiSig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/multisig"
"github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig"
"github.com/multiversx/mx-chain-crypto-go/signing/multisig"
)

type bls struct {
keyGenerator crypto.KeyGenerator
signer crypto.SingleSigner

multiSigner crypto.MultiSigner
}

// NewBLS returns the component able to verify BLS signatures
func NewBLS() *bls {
func NewBLS() (*bls, error) {
b := &bls{}
suite := mcl.NewSuiteBLS12()
b.keyGenerator = signing.NewKeyGenerator(suite)
b.signer = singlesig.NewBlsSigner()

return b
var err error
b.multiSigner, err = multisig.NewBLSMultisig(&mclMultiSig.BlsMultiSignerKOSK{}, b.keyGenerator)

return b, err
}

// VerifyBLS verifies a BLS signatures
Expand All @@ -31,3 +38,13 @@ func (b *bls) VerifyBLS(key []byte, msg []byte, sig []byte) error {

return b.signer.Verify(publicKey, msg, sig)
}

// VerifySignatureShare verifies signature share of BLS MultiSig
func (b *bls) VerifySignatureShare(publicKey []byte, message []byte, sig []byte) error {
return b.multiSigner.VerifySignatureShare(publicKey, message, sig)
}

// VerifyAggregatedSig verifies aggregated signature of BLS MultiSig
func (b *bls) VerifyAggregatedSig(pubKeysSigners [][]byte, message []byte, aggSig []byte) error {
return b.multiSigner.VerifyAggregatedSig(pubKeysSigners, message, aggSig)
}
118 changes: 117 additions & 1 deletion crypto/signing/bls/bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,71 @@ package bls

import (
"encoding/hex"
"fmt"
"strings"
"testing"

crypto "github.com/multiversx/mx-chain-crypto-go"
"github.com/multiversx/mx-chain-crypto-go/signing"
"github.com/multiversx/mx-chain-crypto-go/signing/mcl"
llsig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/multisig"
"github.com/multiversx/mx-chain-crypto-go/signing/multisig"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type multiSignerSetup struct {
privKeys [][]byte
pubKeys [][]byte
partialSignatures [][][]byte
messages []string
aggSignatures [][]byte
}

const checkOK = "3e886a4c6e109a151f4105aee65a5192d150ef1fa68d3cd76964a0b086006dbe4324c989deb0e4416c6d6706db1b1910eb2732f08842fb4886067b9ed191109ac2188d76002d2e11da80a3f0ea89fee6b59c834cc478a6bd49cb8a193b1abb16@e96bd0f36b70c5ccc0c4396343bd7d8255b8a526c55fa1e218511fafe6539b8e@04725db195e37aa237cdbbda76270d4a229b6e7a3651104dc58c4349c0388e8546976fe54a04240530b99064e434c90f"
const checkNOK = "2c9a358953f61d34401d7ee4175eec105c476b18baacab371e2f47270035b539d84ad79ba587552b7e38802be00ff7148fc2a9c7a7034ff1e63ee24602ee952235ad14ca7d36e2be617fb2c99ed22a7a2729d86ae9fbb4df06f957ba07fec50e@1e46d9cbb995e30b82485525c29f80ac78aca295a6e88a11c3df8f9a445494bb@be8c460db180d6254c712ead3aa81935bc9be15b919dd45cb152b3dece04762569778c5e70e7af03fa1c66409d4f4711"

func TestBls_VerifyBLS(t *testing.T) {
t.Parallel()

b := NewBLS()
b, _ := NewBLS()
assert.Nil(t, b.VerifyBLS(splitString(t, checkOK)))
assert.NotNil(t, b.VerifyBLS(splitString(t, checkNOK)))
}

func TestBls_VerifyBLSSigShare(t *testing.T) {
t.Parallel()

b, _ := NewBLS()
assert.Nil(t, b.VerifySignatureShare(splitString(t, checkOK)))
assert.NotNil(t, b.VerifySignatureShare(splitString(t, checkNOK)))
}

func TestBls_VerifyBLSMultiSig(t *testing.T) {
t.Parallel()

b, _ := NewBLS()

numMessages := 5
setupKOSK, multiSignerKOSK := createMultiSigSetupKOSK(uint16(numMessages), numMessages)
setupKOSK.aggSignatures = aggregateSignatures(setupKOSK, multiSignerKOSK)

for i := 0; i < len(setupKOSK.pubKeys); i++ {
fmt.Println(hex.EncodeToString(setupKOSK.pubKeys[i]))
}

for i := 0; i < numMessages; i++ {
fmt.Println(setupKOSK.messages[i])
fmt.Println(hex.EncodeToString(setupKOSK.aggSignatures[i]))

assert.Nil(t, b.VerifyAggregatedSig(setupKOSK.pubKeys, []byte(setupKOSK.messages[i]), setupKOSK.aggSignatures[i]))
changedSig := make([]byte, len(setupKOSK.aggSignatures[i]))
copy(changedSig, setupKOSK.aggSignatures[i])
changedSig[0] += 1
assert.NotNil(t, b.VerifyAggregatedSig(setupKOSK.pubKeys, []byte(setupKOSK.messages[i]), changedSig))
}
}

func splitString(t testing.TB, str string) ([]byte, []byte, []byte) {
split := strings.Split(str, "@")
pkBuff, err := hex.DecodeString(split[0])
Expand All @@ -33,3 +80,72 @@ func splitString(t testing.TB, str string) ([]byte, []byte, []byte) {

return pkBuff, msgBuff, sigBuff
}

func createKeysAndMultiSignerBlsKOSK(
grSize uint16,
suite crypto.Suite,
) ([][]byte, [][]byte, crypto.MultiSigner) {

kg, privKeys, pubKeys := createMultiSignerSetup(grSize, suite)
llSigner := &llsig.BlsMultiSignerKOSK{}
multiSigner, _ := multisig.NewBLSMultisig(llSigner, kg)

return privKeys, pubKeys, multiSigner
}

func createMultiSignerSetup(grSize uint16, suite crypto.Suite) (crypto.KeyGenerator, [][]byte, [][]byte) {
kg := signing.NewKeyGenerator(suite)
privKeys := make([][]byte, grSize)
pubKeys := make([][]byte, grSize)

for i := uint16(0); i < grSize; i++ {
sk, pk := kg.GeneratePair()
privKeys[i], _ = sk.ToByteArray()
pubKeys[i], _ = pk.ToByteArray()
}
return kg, privKeys, pubKeys
}

func createSignaturesShares(privKeys [][]byte, multiSigner crypto.MultiSigner, message []byte) [][]byte {
sigShares := make([][]byte, len(privKeys))
for i := uint16(0); i < uint16(len(privKeys)); i++ {
sigShares[i], _ = multiSigner.CreateSignatureShare(privKeys[i], message)
}

return sigShares
}

func createMultiSigSetupKOSK(numSigners uint16, numMessages int) (*multiSignerSetup, crypto.MultiSigner) {
var multiSigner crypto.MultiSigner
setup := &multiSignerSetup{}
suite := mcl.NewSuiteBLS12()
setup.privKeys, setup.pubKeys, multiSigner = createKeysAndMultiSignerBlsKOSK(numSigners, suite)
setup.messages, setup.partialSignatures = createMessagesAndPartialSignatures(numMessages, setup.privKeys, multiSigner)

return setup, multiSigner
}

func createMessagesAndPartialSignatures(numMessages int, privKeys [][]byte, multiSigner crypto.MultiSigner) ([]string, [][][]byte) {
partialSignatures := make([][][]byte, numMessages)
messages := make([]string, numMessages)

for i := 0; i < numMessages; i++ {
messages[i] = fmt.Sprintf("message%d", i)
signatures := createSignaturesShares(privKeys, multiSigner, []byte(messages[i]))
partialSignatures[i] = signatures
}

return messages, partialSignatures
}

func aggregateSignatures(
setup *multiSignerSetup,
multiSigner crypto.MultiSigner,
) [][]byte {
aggSignatures := make([][]byte, len(setup.messages))
for i := 0; i < len(setup.messages); i++ {
aggSignatures[i], _ = multiSigner.AggregateSigs(setup.pubKeys, setup.partialSignatures[i])
}

return aggSignatures
}
Loading
Loading