Skip to content

Commit d7f8660

Browse files
author
Naohiro Yoshida
committed
merge GetProof with accountProof and storageProof
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
1 parent de73631 commit d7f8660

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

module/proof.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ func (pr *Prover) getAccountProof(height uint64) ([]byte, common.Hash, error) {
2828
return stateProof.AccountProofRLP, common.BytesToHash(stateProof.StorageHash[:]), nil
2929
}
3030

31-
func (pr *Prover) getStateCommitmentProof(path []byte, height exported.Height) ([]byte, error) {
31+
func (pr *Prover) getStateCommitmentProof(path []byte, height exported.Height) ([]byte, []byte, error) {
3232
// calculate slot for commitment
3333
storageKey := crypto.Keccak256Hash(append(
3434
crypto.Keccak256Hash(path).Bytes(),
3535
IBCCommitmentsSlot.Bytes()...,
3636
))
3737
storageKeyHex, err := storageKey.MarshalText()
3838
if err != nil {
39-
return nil, fmt.Errorf("failed to marshal slot: height = %d, %+v", height.GetRevisionHeight(), err)
39+
return nil, nil, fmt.Errorf("failed to marshal slot: height = %d, %+v", height.GetRevisionHeight(), err)
4040
}
4141

4242
// call eth_getProof
@@ -46,10 +46,10 @@ func (pr *Prover) getStateCommitmentProof(path []byte, height exported.Height) (
4646
big.NewInt(int64(height.GetRevisionHeight())),
4747
)
4848
if err != nil {
49-
return nil, fmt.Errorf("failed to get state commitment proof : address = %s, height = %d, slot = %v, %+v",
49+
return nil, nil, fmt.Errorf("failed to get state commitment proof : address = %s, height = %d, slot = %v, %+v",
5050
pr.chain.IBCAddress(), height.GetRevisionHeight(), storageKeyHex, err)
5151
}
52-
return stateProof.StorageProofRLP[0], nil
52+
return stateProof.AccountProofRLP, stateProof.StorageProofRLP[0], nil
5353
}
5454

5555
func (pr *Prover) GetStorageRoot(header *types.Header) (common.Hash, error) {

module/prover.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,12 @@ func (pr *Prover) SetupHeadersForUpdateByLatestHeight(clientStateLatestHeight ex
142142

143143
func (pr *Prover) ProveState(ctx core.QueryContext, path string, value []byte) ([]byte, clienttypes.Height, error) {
144144
proofHeight := toHeight(ctx.Height())
145-
accountProofRLP, _, err := pr.getAccountProof(proofHeight.RevisionHeight)
146-
if err != nil {
147-
return nil, proofHeight, err
148-
}
149-
150-
commitmentProof, err := pr.getStateCommitmentProof([]byte(path), proofHeight)
145+
accountProof, commitmentProof, err := pr.getStateCommitmentProof([]byte(path), proofHeight)
151146
if err != nil {
152147
return nil, proofHeight, err
153148
}
154149
ret := ProveState{
155-
AccountProof: accountProofRLP,
150+
AccountProof: accountProof,
156151
CommitmentProof: commitmentProof,
157152
}
158153
proof, err := ret.Marshal()

0 commit comments

Comments
 (0)