Skip to content

Commit

Permalink
more fix
Browse files Browse the repository at this point in the history
more fix

more fix

more fix

more fix

more fix
  • Loading branch information
0xmountaintop committed Aug 1, 2023
1 parent 9ee198b commit 8ed7966
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 18 deletions.
2 changes: 2 additions & 0 deletions common/types/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,12 @@ type TaskMsg struct {
ChunkTaskDetail *ChunkTaskDetail `json:"chunk_task_detail,omitempty"`
}

// ChunkTaskDetail is a type containing ChunkTask detail.
type ChunkTaskDetail struct {
BlockHashes []common.Hash `json:"block_hashes"`
}

// BatchTaskDetail is a type containing BatchTask detail.
type BatchTaskDetail struct {
ChunkInfos []*ChunkInfo `json:"chunk_infos"`
SubProofs []*ChunkProof `json:"sub_proofs"`
Expand Down
26 changes: 16 additions & 10 deletions common/types/message/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ func TestProofMessageSignVerifyPublicKey(t *testing.T) {
Type: ProofTypeChunk,
Status: StatusOk,
ChunkProof: &ChunkProof{
Proof: []byte("testProof"),
Instance: []byte("testInstance"),
Vk: []byte("testVk"),
StorageTrace: []byte("testStorageTrace"),
Protocol: []byte("testProtocol"),
Proof: []byte("testProof"),
Instances: []byte("testInstance"),
Vk: []byte("testVk"),
},
Error: "testError",
},
Expand All @@ -94,15 +96,17 @@ func TestProofDetailHash(t *testing.T) {
Type: ProofTypeChunk,
Status: StatusOk,
ChunkProof: &ChunkProof{
Proof: []byte("testProof"),
Instance: []byte("testInstance"),
Vk: []byte("testVk"),
StorageTrace: []byte("testStorageTrace"),
Protocol: []byte("testProtocol"),
Proof: []byte("testProof"),
Instances: []byte("testInstance"),
Vk: []byte("testVk"),
},
Error: "testError",
}
hash, err := proofDetail.Hash()
assert.NoError(t, err)
expectedHash := "f7c02bb8b9ff58a5ba61bb76a8b1fb76a023df9da2982d073d20e67f5e72df47"
expectedHash := "4165f5ab3399001002a5b8e4062914249a2deb72f6133d647b586f53e236802d"
assert.Equal(t, expectedHash, hex.EncodeToString(hash))
}

Expand All @@ -127,9 +131,11 @@ func TestProofMsgPublicKey(t *testing.T) {
Type: ProofTypeChunk,
Status: StatusOk,
ChunkProof: &ChunkProof{
Proof: []byte("testProof"),
Instance: []byte("testInstance"),
Vk: []byte("testVk"),
StorageTrace: []byte("testStorageTrace"),
Protocol: []byte("testProtocol"),
Proof: []byte("testProof"),
Instances: []byte("testInstance"),
Vk: []byte("testVk"),
},
Error: "testError",
},
Expand Down
4 changes: 2 additions & 2 deletions coordinator/internal/controller/api/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ func TestProver_SubmitProof(t *testing.T) {
var tmpVerifier *verifier.Verifier
convey.Convey("verifier proof failure", t, func() {
targetErr := errors.New("verify proof failure")
patchGuard.ApplyMethodFunc(tmpVerifier, "VerifyProof", func(proof *message.BatchProof) (bool, error) {
patchGuard.ApplyMethodFunc(tmpVerifier, "VerifyChunkProof", func(proof *message.BatchProof) (bool, error) {
return false, targetErr
})
err1 := proverController.SubmitProof(tmpProof)
assert.Nil(t, err1)
})

patchGuard.ApplyMethodFunc(tmpVerifier, "VerifyProof", func(proof *message.BatchProof) (bool, error) {
patchGuard.ApplyMethodFunc(tmpVerifier, "VerifyChunkProof", func(proof *message.BatchProof) (bool, error) {
return true, nil
})

Expand Down
10 changes: 8 additions & 2 deletions coordinator/internal/logic/proof/proof_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ func (m *ZKProofReceiver) HandleZkProof(ctx context.Context, proofMsg *message.P

coordinatorProofsReceivedTotalCounter.Inc(1)

// TODO: add switch case for ChunkProof & BatchProof
success, verifyErr := m.verifier.VerifyProof(proofMsg.BatchProof)
var success bool
var verifyErr error
if proofMsg.Type == message.ProofTypeChunk {
success, verifyErr = m.verifier.VerifyChunkProof(proofMsg.ChunkProof)
} else if proofMsg.Type == message.ProofTypeBatch {
success, verifyErr = m.verifier.VerifyBatchProof(proofMsg.BatchProof)
}

if verifyErr != nil || !success {
if verifyErr != nil {
// TODO: this is only a temp workaround for testnet, we should return err in real cases
Expand Down
12 changes: 10 additions & 2 deletions coordinator/internal/logic/verifier/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ func NewVerifier(_ *config.VerifierConfig) (*Verifier, error) {
return &Verifier{}, nil
}

// VerifyProof always return true
func (v *Verifier) VerifyProof(proof *message.BatchProof) (bool, error) {
// VerifyChunkProof return a mock verification result for a ChunkProof.
func (v *Verifier) VerifyChunkProof(proof *message.ChunkProof) (bool, error) {
if string(proof.Proof) == InvalidTestProof {
return false, nil
}
return true, nil
}

// VerifyBatchProof return a mock verification result for a BatchProof.
func (v *Verifier) VerifyBatchProof(proof *message.BatchProof) (bool, error) {
if string(proof.Proof) == InvalidTestProof {
return false, nil
}
Expand Down
2 changes: 1 addition & 1 deletion coordinator/internal/logic/verifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (v *Verifier) VerifyBatchProof(proof *message.BatchProof) (bool, error) {
func (v *Verifier) VerifyChunkProof(proof *message.ChunkProof) (bool, error) {
if v.cfg.MockMode {
log.Info("Mock mode, verifier disabled")
if string(proof.ChunkProofInner.Proof) == InvalidTestProof {
if string(proof.Proof) == InvalidTestProof {
return false, nil
}
return true, nil
Expand Down
2 changes: 1 addition & 1 deletion coordinator/test/mock_prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (r *mockProver) loop(t *testing.T, client *client2.Client, proofTime time.D
if proofStatus == generatedFailed {
proof.Status = message.StatusProofError
} else if proofStatus == verifiedFailed {
proof.ProofDetail.ChunkProof.ChunkProofInner.Proof = []byte(verifier.InvalidTestProof)
proof.ProofDetail.ChunkProof.Proof = []byte(verifier.InvalidTestProof)
proof.ProofDetail.BatchProof.Proof = []byte(verifier.InvalidTestProof)
}
assert.NoError(t, proof.Sign(r.privKey))
Expand Down

0 comments on commit 8ed7966

Please sign in to comment.