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()) multiBLSPubKey := setupConsensusKeys(hc, nodeconfig.GetDefaultConfig())
reshardingEpoch := genesisShardingConfig.ReshardingEpoch() reshardingEpoch := genesisShardingConfig.ReshardingEpoch()
fmt.Println("len(reshardingEpoch) > 0", len(reshardingEpoch) > 0, reshardingEpoch)
if len(reshardingEpoch) > 0 { if len(reshardingEpoch) > 0 {
for _, epoch := range reshardingEpoch { for _, epoch := range reshardingEpoch {
config := shard.Schedule.InstanceForEpoch(epoch) config := shard.Schedule.InstanceForEpoch(epoch)
@ -624,6 +625,9 @@ func setupStakingNodeAccount(hc harmonyconfig.HarmonyConfig) error {
); err != nil { ); err != nil {
return err return err
} }
fmt.Println("pubKeys", shardID, len(pubKeys))
for _, blsKey := range pubKeys { for _, blsKey := range pubKeys {
initialAccount := &genesis.DeployAccount{} initialAccount := &genesis.DeployAccount{}
initialAccount.ShardID = shardID initialAccount.ShardID = shardID

@ -175,14 +175,14 @@ func (g groth16Verify) Run(input []byte) ([]byte, error) {
panic("implement me") 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 vk gnark.VerifyingKey
var proof gnark.Proof var proof gnark.Proof
switch curve { switch curve {
case ecc.BN254: case ecc.BN254:
bn256vk, err := FromBytesToVerifyingKey(vkBytes) bn256vk, err := FromBytesToVerifyingKey(verifyingKey)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -223,9 +223,29 @@ func Groth16Verify(vkBytes []byte, proofBytes []byte, inputsBytes []byte, curve
return true, nil return true, nil
} }
func FromBytesToVerifyingKey(vkBytes []byte) (gnark.VerifyingKey, error) { func FromBytesToProof(proofBytes []byte) (gnark.Proof, error) {
var vk gnark.VerifyingKey var bproof BellmanProofBn256
return vk, nil 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() { 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