diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index ec05e2419..c517f1158 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -586,6 +586,7 @@ func setupLegacyNodeAccount(hc harmonyconfig.HarmonyConfig) error { multiBLSPubKey := setupConsensusKeys(hc, nodeconfig.GetDefaultConfig()) reshardingEpoch := genesisShardingConfig.ReshardingEpoch() + fmt.Println("len(reshardingEpoch) > 0", len(reshardingEpoch) > 0, reshardingEpoch) if len(reshardingEpoch) > 0 { for _, epoch := range reshardingEpoch { config := shard.Schedule.InstanceForEpoch(epoch) @@ -624,6 +625,9 @@ func setupStakingNodeAccount(hc harmonyconfig.HarmonyConfig) error { ); err != nil { return err } + + fmt.Println("pubKeys", shardID, len(pubKeys)) + for _, blsKey := range pubKeys { initialAccount := &genesis.DeployAccount{} initialAccount.ShardID = shardID diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 24a3895a3..f5c33eb03 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -175,14 +175,14 @@ func (g groth16Verify) Run(input []byte) ([]byte, error) { panic("implement me") } -func Groth16Verify(vkBytes []byte, proofBytes []byte, inputsBytes []byte, curve ecc.ID) (bool, error) { +func Groth16Verify(verifyingKey []byte, proofBytes []byte, inputsBytes []byte, curve ecc.ID) (bool, error) { var vk gnark.VerifyingKey var proof gnark.Proof switch curve { case ecc.BN254: - bn256vk, err := FromBytesToVerifyingKey(vkBytes) + bn256vk, err := FromBytesToVerifyingKey(verifyingKey) if err != nil { return false, err } @@ -223,9 +223,29 @@ func Groth16Verify(vkBytes []byte, proofBytes []byte, inputsBytes []byte, curve return true, nil } -func FromBytesToVerifyingKey(vkBytes []byte) (gnark.VerifyingKey, error) { - var vk gnark.VerifyingKey - return vk, nil +func FromBytesToProof(proofBytes []byte) (gnark.Proof, error) { + var bproof BellmanProofBn256 + proofBytes, err := changeFlagsInProofToGnarkType(proofBytes) + if err != nil { + return nil, err + } + _, err = bproof.ReadFrom(bytes.NewReader(proofBytes)) + if err != nil { + return nil, err + } + + var b bytes.Buffer + _, err = bproof.WriteTo(&b) + if err != nil { + return nil, err + } + + proof := gnark.NewProof(ecc.BN254) + _, err = proof.ReadFrom(bytes.NewReader(b.Bytes())) + if err != nil { + return nil, err + } + return proof, nil } func init() { diff --git a/crypto/groth16/bn254/lib.go b/crypto/groth16/bn254/lib.go new file mode 100644 index 000000000..f11cff356 --- /dev/null +++ b/crypto/groth16/bn254/lib.go @@ -0,0 +1,17 @@ +package bn254 + +import ( + "bytes" + + "github.com/consensys/gnark-crypto/ecc" + gnark "github.com/consensys/gnark/backend/groth16" +) + +func FromBytesToVerifyingKey(verifyingKey []byte) (gnark.VerifyingKey, error) { + vk := gnark.NewVerifyingKey(ecc.BN254) + _, err := vk.ReadFrom(bytes.NewReader(verifyingKey)) + if err != nil { + return nil, err + } + return vk, nil +}