Skip to content

Commit a5e5906

Browse files
committed
fix proof
1 parent 9a0c8f6 commit a5e5906

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

code/go/0chain.net/blobbercore/challenge/protocol.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
2222
"github.com/0chain/blobber/code/go/0chain.net/core/transaction"
2323
"github.com/0chain/blobber/code/go/0chain.net/core/util"
24+
"github.com/0chain/common/core/util/wmpt"
2425
sdkUtil "github.com/0chain/gosdk/core/util"
2526
"github.com/remeh/sizedwaitgroup"
2627
"gorm.io/gorm"
@@ -339,21 +340,22 @@ func (cr *ChallengeEntity) SaveChallengeResult(ctx context.Context, t *transacti
339340

340341
func (cr *ChallengeEntity) getPostDataV2(ctx context.Context, allocationObj *allocation.Allocation) (map[string]any, error) {
341342
trie := allocationObj.GetTrie()
343+
copyTrie := wmpt.New(trie.CopyRoot(filestore.COLLAPSE_DEPTH), datastore.GetBlockStore())
344+
342345
var (
343346
blockNum = int64(0)
344347
postData = make(map[string]interface{})
345348
ref *reference.Ref
346349
objectSize int64
347350
proofGenTime int64 = -1
348351
)
349-
if trie.Weight() > 0 {
352+
if copyTrie.Weight() > 0 {
350353
r := rand.New(rand.NewSource(cr.RandomNumber))
351-
blockNum = r.Int63n(int64(trie.Weight()))
354+
blockNum = r.Int63n(int64(copyTrie.Weight()))
352355
blockNum++
353356
cr.BlockNum = blockNum
354-
355357
logging.Logger.Info("[challenge]rand: ", zap.Uint64("trie.NumBlocks", trie.Weight()), zap.Any("blockNum", blockNum), zap.Any("challenge_id", cr.ChallengeID), zap.Any("random_seed", cr.RandomNumber))
356-
key, objectProof, err := trie.GetBlockProof(uint64(blockNum))
358+
key, objectProof, err := copyTrie.GetBlockProof(uint64(blockNum))
357359
if err != nil {
358360
return nil, err
359361
}
@@ -367,6 +369,12 @@ func (cr *ChallengeEntity) getPostDataV2(ctx context.Context, allocationObj *all
367369
}
368370
cr.RefID = ref.ID
369371
postData["object_proof"] = objectProof
372+
fileMetaRootBytes := copyTrie.Root()
373+
fileMetaRoot := hex.EncodeToString(fileMetaRootBytes)
374+
if fileMetaRoot != allocationObj.FileMetaRoot {
375+
logging.Logger.Error("root_mismatch", zap.Any("file_meta_root", allocationObj.FileMetaRoot), zap.Any("file_meta_root", fileMetaRoot))
376+
return nil, common.NewError("root_mismatch", "File meta root mismatch")
377+
}
370378
}
371379
cr.RespondedAllocationRoot = allocationObj.AllocationRoot
372380
if blockNum > 0 {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ require (
9999
)
100100

101101
require (
102-
github.com/0chain/common v1.13.1-0.20240926135437-61b88d39bbbd
102+
github.com/0chain/common v1.13.1-0.20241001175315-40440b0c9713
103103
github.com/Luzifer/go-openssl/v3 v3.1.0 // indirect
104104
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
105105
github.com/btcsuite/btcd v0.23.4 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
3636
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
3737
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
3838
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
39-
github.com/0chain/common v1.13.1-0.20240926135437-61b88d39bbbd h1:PDnzyJJA4rF2LBW+0OQJ5y9vIwsPYYjbbFwImvgiDdY=
40-
github.com/0chain/common v1.13.1-0.20240926135437-61b88d39bbbd/go.mod h1:vHK9Q0/nz28PxmKsLSMLzEs5iK6QVgl1LxdDQdR7y6s=
39+
github.com/0chain/common v1.13.1-0.20241001175315-40440b0c9713 h1:Syx2RVTEQYC94TRVRqrnb6mrqdXzgG9ipexLKyGs/0w=
40+
github.com/0chain/common v1.13.1-0.20241001175315-40440b0c9713/go.mod h1:vHK9Q0/nz28PxmKsLSMLzEs5iK6QVgl1LxdDQdR7y6s=
4141
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
4242
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
4343
github.com/0chain/gosdk v1.17.0-RC6 h1:NB4pfu0VbVWfQQEfnFqn5inaiQuyhSaUW7VwgH3LW8U=

0 commit comments

Comments
 (0)