feature/groth16
frozen 11 months ago
parent bfd424db13
commit 81c8204427
No known key found for this signature in database
GPG Key ID: 5391C63E79B03EDE
  1. 4
      cmd/harmony/main.go
  2. 30
      core/vm/contracts.go
  3. 17
      crypto/groth16/bn254/lib.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

@ -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() {

@ -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
}
Loading…
Cancel
Save