Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proof] Relay signature & Merkle proof validation #406

Merged
merged 27 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
61c8dc8
feat: Implement proof's smt and signature validations
red-0ne Mar 1, 2024
6239e74
[Proof] refactor: ring client for on-chain use (#411)
bryanchriswhite Mar 5, 2024
835889e
refactor: make session comparaison more generic
red-0ne Mar 6, 2024
a01cb26
chore: add comments
red-0ne Mar 6, 2024
8a91394
Merge branch 'main' into feat/proof-validation
bryanchriswhite Mar 7, 2024
0b82243
[PubKeyClient] Implement PubKeyClient for on/off-chain usage (#413)
red-0ne Mar 7, 2024
74e7a09
chore: Address review change requests
red-0ne Mar 7, 2024
e4484be
chore: Update keeper query clients in-code documentation
red-0ne Mar 8, 2024
3f277e7
chore: Add godoc comments
red-0ne Mar 8, 2024
2d5af98
fix: test error msg assertion
red-0ne Mar 11, 2024
4bf0b9f
chore: Address review change requests
red-0ne Mar 13, 2024
75db907
chore: Add missing change requests
red-0ne Mar 13, 2024
f7f28bf
Merge remote-tracking branch 'origin/main' into feat/proof-validation
red-0ne Mar 13, 2024
3357fea
chore: Remove pubkey client
red-0ne Mar 14, 2024
f90ca76
chore: Fix unit tests and ring client removal consideration
red-0ne Mar 14, 2024
46c61dd
Offline review of 406
Olshansk Mar 19, 2024
14638bd
fix: Make relay req/res meta a non-pointer
red-0ne Mar 19, 2024
ab43ea7
fix: Restore bank expected keeper
red-0ne Mar 20, 2024
298e7ad
chore: Update SMT dependency
red-0ne Mar 21, 2024
19ae70f
A couple more nits
Olshansk Mar 21, 2024
7be1fe4
Merge branch 'main' into feat/proof-validation
Olshansk Mar 21, 2024
ac91121
Removed accidental period
Olshansk Mar 21, 2024
25295d3
Fixing unit tests
Olshansk Mar 21, 2024
e09e719
Fix impors after debugging
Olshansk Mar 21, 2024
6df5967
Empty commit
Olshansk Mar 21, 2024
b103308
Minor e2e test fix
Olshansk Mar 21, 2024
ce194fa
Merge branch 'main' into feat/proof-validation
Olshansk Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/tests/session.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Session Namespace
# The timeout for when a claim can be submitted on-chain depends on `createClaimWindowStartHeight`, which
# is a function of `SessionGracePeriod`. The higher this value, the higher this timeout needs to be. Since
# this test is not dependant on the grace period, setting it to 0 and having a lower grace period will simplify it.
And the user should wait for "7" seconds
And the user should wait for "10" seconds
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
Then the claim created by supplier "supplier1" for service "svc1" for application "app1" should be persisted on-chain
# TODO_IMPROVE: And an event should be emitted...
And after the supplier submits a proof for the session for service "svc1" for application "app1"
Expand Down
1 change: 1 addition & 0 deletions pkg/appgateserver/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func setupAppGateServerDependencies(
config.NewSupplyAccountQuerierFn(), // leaf
config.NewSupplyApplicationQuerierFn(), // leaf
config.NewSupplySessionQuerierFn(), // leaf
config.NewSupplyPubKeyClientFn(),
config.NewSupplyRingCacheFn(),

config.NewSupplyPOKTRollSDKFn(appGateConfig.SigningKey),
Expand Down
38 changes: 30 additions & 8 deletions pkg/crypto/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,49 @@ package crypto
import (
"context"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/noot/ring-go"

"github.com/pokt-network/poktroll/x/service/types"
)

// RingCache is used to store rings used for signing and verifying relay requests.
// It will cache rings for future use after querying the application module for
// the addresses of the gateways the application is delegated to, and converting
// them into their corresponding public key points on the secp256k1 curve.
type RingCache interface {
RingClient

// GetCachedAddresses returns the addresses of the applications that are
// currently cached in the ring cache.
GetCachedAddresses() []string
// Start starts the ring cache, it takes a cancellable context and, in a
// separate goroutine, listens for on-chain delegation events and invalidates
// the cache if the redelegation event's AppAddress is stored in the cache.
Start(ctx context.Context)
// GetCachedAddresses returns the addresses of the applications that are
// currently cached in the ring cache.
GetCachedAddresses() []string
// GetRingForAddress returns the ring for the given application address if
// it exists. If it does not exist in the cache, it follows a lazy approach
// of querying the on-chain state and creating it just-in-time, caching for
// future retrievals.
GetRingForAddress(ctx context.Context, appAddress string) (*ring.Ring, error)
// Stop stops the ring cache by unsubscribing from on-chain delegation events.
// And clears the cache, so that it no longer contains any rings,
Stop()
}

// RingClient is used to construct rings by querying the application module for
// the addresses of the gateways the application is delegated to, and converting
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
// them into their corresponding public key points on the secp256k1 curve.
type RingClient interface {
// GetRingForAddress returns the ring for the given application address if
// it exists.
GetRingForAddress(ctx context.Context, appAddress string) (*ring.Ring, error)

// VerifyRelayRequestSignature verifies the relay request signature against the
// ring for the application address in the relay request.
VerifyRelayRequestSignature(ctx context.Context, relayRequest *types.RelayRequest) error
}

// PubKeyClient is used to get the public key given an address.
// On-chain and off-chain implementations should take care of retrieving the
// address' account and returning its public key.
type PubKeyClient interface {
// GetPubKeyFromAddress returns the public key of the given account address if
// it exists.
GetPubKeyFromAddress(ctx context.Context, address string) (cryptotypes.PubKey, error)
}
58 changes: 58 additions & 0 deletions pkg/crypto/pubkey_client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package pubkeyclient

import (
"context"

"cosmossdk.io/depinject"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"

"github.com/pokt-network/poktroll/pkg/client"
"github.com/pokt-network/poktroll/pkg/crypto"
)

var _ crypto.PubKeyClient = (*pubKeyClient)(nil)

// pubKeyClient is an implementation of the PubKeyClient that uses an account
// querier to get the public key of an address.
type pubKeyClient struct {
// accountQuerier is the querier for the account module, it is used to get
// the account of an address.
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
accountQuerier client.AccountQueryClient
}

// NewPubKeyClient creates a new PubKeyClient with the given dependencies.
// The querier is injected using depinject and has to be specific to the
// environment in which the pubKeyClient is initialized as on-chain and off-chain
// environments may have different queriers.
//
// Required dependencies:
// - client.AccountQueryClient
func NewPubKeyClient(deps depinject.Config) (crypto.PubKeyClient, error) {
pc := new(pubKeyClient)

if err := depinject.Inject(
deps,
&pc.accountQuerier,
); err != nil {
return nil, err
}

return pc, nil
}

// GetPubKeyFromAddress returns the public key of the given address.
// It uses the accountQuerier to get the account and then returns its public key.
func (pc *pubKeyClient) GetPubKeyFromAddress(ctx context.Context, address string) (cryptotypes.PubKey, error) {
acc, err := pc.accountQuerier.GetAccount(ctx, address)
if err != nil {
return nil, err
}

// If the account's public key is nil, then return an error.
pubKey := acc.GetPubKey()
if pubKey == nil {
return nil, ErrPubKeyClientEmptyPubKey
}

return pubKey, nil
}
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions pkg/crypto/pubkey_client/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pubkeyclient

import sdkerrors "cosmossdk.io/errors"

var (
codespace = "pubkeyclient"
ErrPubKeyClientEmptyPubKey = sdkerrors.Register(codespace, 1, "empty public key")
)
Loading
Loading