Skip to content

Commit

Permalink
feat: wrap ShareProof in a ResultShareProof (#1351)
Browse files Browse the repository at this point in the history
## Description

Contributes to #1306

---------

Co-authored-by: Rootul P <rootulp@gmail.com>
  • Loading branch information
rach-id and rootulp authored May 9, 2024
1 parent 873ee77 commit 52f84ef
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 0 deletions.
13 changes: 13 additions & 0 deletions light/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ func (c *Client) Tx(ctx context.Context, hash []byte, prove bool) (*ctypes.Resul
// ProveShares calls rpcclient#ProveShares method and returns an NMT proof for a set
// of shares, defined by `startShare` and `endShare`, to the corresponding rows.
// Then, a binary merkle inclusion proof from the latter rows to the data root.
// Deprecated: Use ProveSharesV2 instead.
func (c *Client) ProveShares(
ctx context.Context,
height uint64,
Expand All @@ -591,6 +592,18 @@ func (c *Client) ProveShares(
return res, err
}

// ProveSharesV2 returns a proof of inclusion for a share range to the data root.
// Note: this proof is composed of multiple proofs.
func (c *Client) ProveSharesV2(
ctx context.Context,
height uint64,
startShare uint64,
endShare uint64,
) (*ctypes.ResultShareProof, error) {
res, err := c.next.ProveSharesV2(ctx, height, startShare, endShare)
return res, err
}

func (c *Client) TxSearch(
ctx context.Context,
query string,
Expand Down
21 changes: 21 additions & 0 deletions rpc/client/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ func (c *baseRPCClient) Tx(ctx context.Context, hash []byte, prove bool) (*ctype
return result, nil
}

// ProveShares
// Deprecated: Use ProveSharesV2 instead.
func (c *baseRPCClient) ProveShares(
ctx context.Context,
height uint64,
Expand All @@ -569,6 +571,25 @@ func (c *baseRPCClient) ProveShares(
return *result, nil
}

func (c *baseRPCClient) ProveSharesV2(
ctx context.Context,
height uint64,
startShare uint64,
endShare uint64,
) (*ctypes.ResultShareProof, error) {
result := new(ctypes.ResultShareProof)
params := map[string]interface{}{
"height": height,
"startShare": startShare,
"endShare": endShare,
}
_, err := c.caller.Call(ctx, "prove_shares_v2", params, result)
if err != nil {
return nil, err
}
return result, nil
}

func (c *baseRPCClient) TxSearch(
ctx context.Context,
query string,
Expand Down
3 changes: 3 additions & 0 deletions rpc/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ type SignClient interface {
Validators(ctx context.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error)
Tx(ctx context.Context, hash []byte, prove bool) (*ctypes.ResultTx, error)

// ProveShares
// Deprecated: Use ProveSharesV2 instead.
ProveShares(_ context.Context, height uint64, startShare uint64, endShare uint64) (types.ShareProof, error)
ProveSharesV2(_ context.Context, height uint64, startShare uint64, endShare uint64) (*ctypes.ResultShareProof, error)

// TxSearch defines a method to search for a paginated set of transactions by
// DeliverTx event search criteria.
Expand Down
11 changes: 11 additions & 0 deletions rpc/client/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ func (c *Local) Tx(ctx context.Context, hash []byte, prove bool) (*ctypes.Result
return core.Tx(c.ctx, hash, prove)
}

// ProveShares
// Deprecated: Use ProveSharesV2 instead.
func (c *Local) ProveShares(
ctx context.Context,
height uint64,
Expand All @@ -219,6 +221,15 @@ func (c *Local) ProveShares(
return core.ProveShares(c.ctx, int64(height), startShare, endShare)
}

func (c *Local) ProveSharesV2(
ctx context.Context,
height uint64,
startShare uint64,
endShare uint64,
) (*ctypes.ResultShareProof, error) {
return core.ProveSharesV2(c.ctx, int64(height), startShare, endShare)
}

func (c *Local) TxSearch(
_ context.Context,
query string,
Expand Down
1 change: 1 addition & 0 deletions rpc/core/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var Routes = map[string]*rpc.RPCFunc{
"check_tx": rpc.NewRPCFunc(CheckTx, "tx"),
"tx": rpc.NewRPCFunc(Tx, "hash,prove", rpc.Cacheable()),
"prove_shares": rpc.NewRPCFunc(ProveShares, "height,startShare,endShare"),
"prove_shares_v2": rpc.NewRPCFunc(ProveSharesV2, "height,startShare,endShare"),
"data_root_inclusion_proof": rpc.NewRPCFunc(DataRootInclusionProof, "height,start,end"),
"tx_search": rpc.NewRPCFunc(TxSearchMatchEvents, "query,prove,page,per_page,order_by,match_events"),
"block_search": rpc.NewRPCFunc(BlockSearchMatchEvents, "query,page,per_page,order_by,match_events"),
Expand Down
16 changes: 16 additions & 0 deletions rpc/core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func proveTx(height int64, index uint32) (types.ShareProof, error) {

// ProveShares creates an NMT proof for a set of shares to a set of rows. It is
// end exclusive.
// Deprecated: Use ProveSharesV2 instead.
func ProveShares(
_ *rpctypes.Context,
height int64,
Expand Down Expand Up @@ -212,6 +213,21 @@ func ProveShares(
return shareProof, nil
}

// ProveSharesV2 creates a proof for a set of shares to the data root.
// The range is end exclusive.
func ProveSharesV2(
ctx *rpctypes.Context,
height int64,
startShare uint64,
endShare uint64,
) (*ctypes.ResultShareProof, error) {
shareProof, err := ProveShares(ctx, height, startShare, endShare)
if err != nil {
return nil, err
}
return &ctypes.ResultShareProof{ShareProof: shareProof}, nil
}

func loadRawBlock(bs state.BlockStore, height int64) ([]byte, error) {
var blockMeta = bs.LoadBlockMeta(height)
if blockMeta == nil {
Expand Down
5 changes: 5 additions & 0 deletions rpc/core/types/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,8 @@ type ResultEvent struct {
Data types.TMEventData `json:"data"`
Events map[string][]string `json:"events"`
}

// ResultShareProof is an API response that contains a ShareProof.
type ResultShareProof struct {
ShareProof types.ShareProof `json:"share_proof"`
}
176 changes: 176 additions & 0 deletions rpc/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,92 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
/prove_shares:
get:
summary: Prove shares for a given share range.
description: |
Generates a proof of inclusion for a range of shares to the data root.
Note: shares are referenced by their range: startShare to endShare.
The share range is end exclusive.
Deprecated: Use '/prove_shares_v2' instead.
operationId: prove_shares
tags:
- Info
parameters:
- in: query
name: height
description: The block height
schema:
type: integer
default: 1
example: 1
- in: query
name: startShare
description: The starting share index
schema:
type: integer
default: 0
example: 0
- in: query
name: endShare
description: The end exclusive ending share index
schema:
type: integer
default: 1
example: 1
responses:
'200':
description: Successfully retrieved the share proof
content:
application/json:
schema:
$ref: '#/components/schemas/ShareProof'
'500':
description: Internal server error

/prove_shares_v2:
get:
summary: Prove shares for a given share range.
description: |
Generates a proof of inclusion for a range of shares to the data root.
Note: shares are referenced by their range: startShare to endShare.
The share range is end exclusive.
Replaces '/prove_shares'
operationId: prove_shares_v2
tags:
- Info
parameters:
- in: query
name: height
description: The block height
schema:
type: integer
default: 1
example: 1
- in: query
name: startShare
description: The starting share index
schema:
type: integer
default: 0
example: 0
- in: query
name: endShare
description: The end exclusive ending share index
schema:
type: integer
default: 1
example: 1
responses:
'200':
description: Successfully retrieved the share proof
content:
application/json:
schema:
$ref: '#/components/schemas/ResultShareProof'
'500':
description: Internal server error

/data_commitment:
get:
summary: Generates a data commitment for a range of blocks
Expand Down Expand Up @@ -2581,8 +2667,98 @@ components:
tx:
type: string
example: "5wHwYl3uCkaoo2GaChQmSIu8hxpJxLcCuIi8fiHN4TMwrRIU/Af1cEG7Rcs/6LjTl7YjRSymJfYaFAoFdWF0b20SCzE0OTk5OTk1MDAwEhMKDQoFdWF0b20SBDUwMDAQwJoMGmoKJuta6YchAwswBShaB1wkZBctLIhYqBC3JrAI28XGzxP+rVEticGEEkAc+khTkKL9CDE47aDvjEHvUNt+izJfT4KVF2v2JkC+bmlH9K08q3PqHeMI9Z5up+XMusnTqlP985KF+SI5J3ZOIhhNYWRlIGJ5IENpcmNsZSB3aXRoIGxvdmU="
proof:
type: object
$ref: '#/components/schemas/ShareProof'
nullable: true
description: Optional proof of the transaction, provided only when requested.
type: object

ResultShareProof:
type: object
properties:
share_proof:
$ref: '#/components/schemas/ShareProof'
description: API proof response of a set of shares.
ShareProof:
type: object
properties:
data:
type: array
items:
type: string
format: byte
description: The raw shares that are being proven.
shareProofs:
type: array
items:
$ref: '#/components/schemas/NMTProof'
description: NMT proofs that the shares in Data exist in a set of rows.
namespaceID:
type: string
format: byte
description: The namespace id of the shares being proven.
rowProof:
$ref: '#/components/schemas/RowProof'
namespaceVersion:
type: integer
format: uint32
description: The version of the namespace used for verification.
NMTProof:
type: object
properties:
start:
type: integer
format: int32
end:
type: integer
format: int32
nodes:
type: array
items:
type: string
format: byte
description: Nodes used to verify the proof.
leaf_hash:
type: string
format: byte
description: Leaf hash necessary for proof of absence, if applicable.
RowProof:
type: object
properties:
rowRoots:
type: array
items:
type: string
format: byte
proofs:
type: array
items:
$ref: '#/components/schemas/Proof'
startRow:
type: integer
format: uint32
endRow:
type: integer
format: uint32
Proof:
type: object
description: Binary merkle proof
properties:
total:
type: integer
format: int64
index:
type: integer
format: int64
leafHash:
type: string
format: byte
aunts:
type: array
items:
type: string
format: byte
ABCIInfoResponse:
type: object
required:
Expand Down

0 comments on commit 52f84ef

Please sign in to comment.