Skip to content

Commit

Permalink
feat: add da submission data and result query
Browse files Browse the repository at this point in the history
  • Loading branch information
fiamma-builder committed Oct 30, 2024
1 parent b5a72a8 commit 9132c54
Show file tree
Hide file tree
Showing 10 changed files with 3,431 additions and 268 deletions.
2,247 changes: 2,100 additions & 147 deletions api/fiamma/zkpverify/query.pulsar.go

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions api/fiamma/zkpverify/query_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/static/openapi.yml

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions proto/fiamma/zkpverify/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ service Query {
option (google.api.http).get = "/fiamma/zkpverify/bitvm_challenge_data";
}

rpc DaSubmissionData(QueryDaSubmissionDataRequest) returns (QueryDaSubmissionDataResponse) {
option (google.api.http).get = "/fiamma/zkpverify/da_submission_data/{proof_id}";
}

rpc DaSubmissionResult(QueryDaSubmissionResultRequest) returns (QueryDaSubmissionResultResponse) {
option (google.api.http).get = "/fiamma/zkpverify/da_submission_result/{proof_id}";
}

}
// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}
Expand Down Expand Up @@ -161,3 +169,20 @@ message QueryBitVMChallengeDataRequest {
message QueryBitVMChallengeDataResponse {
fiamma.zkpverify.BitVMChallengeData bitvm_challenge_data = 1;
}


message QueryDaSubmissionDataRequest {
string proof_id = 1;
}

message QueryDaSubmissionDataResponse {
fiamma.zkpverify.DASubmissionData da_submission_data = 1;
}

message QueryDaSubmissionResultRequest {
string proof_id = 1;
}

message QueryDaSubmissionResultResponse {
fiamma.zkpverify.DASubmissionResult da_submission_result = 1;
}
31 changes: 31 additions & 0 deletions scripts/cli/query_dasubmission_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -e

: ${CHAIN_ID:="fiamma-testnet-1"}
: ${NODE:="http://127.0.0.1:26657"}
: ${PROOF_FILE:=../../prover_examples/bitvm/proof.bitvm}
: ${PUBLIC_INPUT_FILE:=../../prover_examples/bitvm/public_input.bitvm}
: ${VK_FILE:=../../prover_examples/bitvm/vk.bitvm}
: ${NAMESPACE:="TEST"}
: ${PROOF_SYSTEM:="GROTH16_BN254_BITVM"}
: ${DATA_LOCATION:="FIAMMA"}

NEW_NAMESPACE=$(echo -n $NAMESPACE | xxd -p)

NEW_PROOF_SYSTEM=$(echo -n $PROOF_SYSTEM | xxd -p)

NEW_PROOF=$(xxd -p -c 256 $PROOF_FILE | tr -d '\n')

NEW_PUBLIC_INPUT=$(xxd -p -c 256 $PUBLIC_INPUT_FILE | tr -d '\n')

NEW_VK=$(xxd -p -c 256 $VK_FILE | tr -d '\n')

NEW_DATA_LOCATION=$(echo -n $DATA_LOCATION | xxd -p)

# Concatenate the proof, public input, and vk
allDataHex="${NEW_NAMESPACE}${NEW_PROOF_SYSTEM}${NEW_PROOF}${NEW_PUBLIC_INPUT}${NEW_VK}${NEW_DATA_LOCATION}"

proof_id=$(echo -n "$allDataHex" | xxd -r -p | sha256sum | awk '{print $1}')

fiammad query zkpverify get-da-submission-data $proof_id --node $NODE
31 changes: 31 additions & 0 deletions scripts/cli/query_dasubmission_result.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -e

: ${CHAIN_ID:="fiamma-testnet-1"}
: ${NODE:="http://127.0.0.1:26657"}
: ${PROOF_FILE:=../../prover_examples/bitvm/proof.bitvm}
: ${PUBLIC_INPUT_FILE:=../../prover_examples/bitvm/public_input.bitvm}
: ${VK_FILE:=../../prover_examples/bitvm/vk.bitvm}
: ${NAMESPACE:="TEST"}
: ${PROOF_SYSTEM:="GROTH16_BN254_BITVM"}
: ${DATA_LOCATION:="FIAMMA"}

NEW_NAMESPACE=$(echo -n $NAMESPACE | xxd -p)

NEW_PROOF_SYSTEM=$(echo -n $PROOF_SYSTEM | xxd -p)

NEW_PROOF=$(xxd -p -c 256 $PROOF_FILE | tr -d '\n')

NEW_PUBLIC_INPUT=$(xxd -p -c 256 $PUBLIC_INPUT_FILE | tr -d '\n')

NEW_VK=$(xxd -p -c 256 $VK_FILE | tr -d '\n')

NEW_DATA_LOCATION=$(echo -n $DATA_LOCATION | xxd -p)

# Concatenate the proof, public input, and vk
allDataHex="${NEW_NAMESPACE}${NEW_PROOF_SYSTEM}${NEW_PROOF}${NEW_PUBLIC_INPUT}${NEW_VK}${NEW_DATA_LOCATION}"

proof_id=$(echo -n "$allDataHex" | xxd -r -p | sha256sum | awk '{print $1}')

fiammad query zkpverify get-da-submission-result $proof_id --node $NODE
55 changes: 55 additions & 0 deletions x/zkpverify/keeper/query_da_submission.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package keeper

import (
"context"
"encoding/hex"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/fiamma-chain/fiamma/x/zkpverify/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (k Keeper) DaSubmissionData(goCtx context.Context, req *types.QueryDaSubmissionDataRequest) (*types.QueryDaSubmissionDataResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

proofId, err := hex.DecodeString(req.ProofId)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid proof id")
}

data, found := k.GetDASubmissionData(ctx, proofId)
if !found {
return nil, status.Error(codes.NotFound, "da submission data not found")
}

return &types.QueryDaSubmissionDataResponse{
DaSubmissionData: &data,
}, nil
}

func (k Keeper) DaSubmissionResult(goCtx context.Context, req *types.QueryDaSubmissionResultRequest) (*types.QueryDaSubmissionResultResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

proofId, err := hex.DecodeString(req.ProofId)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid proof id")
}

result, found := k.GetDASubmissionResult(ctx, proofId)
if !found {
return nil, status.Error(codes.NotFound, "da submission result not found")
}

return &types.QueryDaSubmissionResultResponse{
DaSubmissionResult: &result,
}, nil
}
14 changes: 14 additions & 0 deletions x/zkpverify/module/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "proof_id"}},
},

{
RpcMethod: "DaSubmissionData",
Use: "get-da-submission-data [proof_id]",
Short: "Query DA submission data by proof_id",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "proof_id"}},
},

{
RpcMethod: "DaSubmissionResult",
Use: "get-da-submission-result [proof_id]",
Short: "Query DA submission result by proof_id",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "proof_id"}},
},

// this line is used by ignite scaffolding # autocli/query
},
},
Expand Down
Loading

0 comments on commit 9132c54

Please sign in to comment.