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

feat!: Add a block validity rule that all PFB transactions must have valid signatures #1300

Merged
merged 24 commits into from
Jan 31, 2023

Conversation

evan-forbes
Copy link
Member

@evan-forbes evan-forbes commented Jan 26, 2023

Overview

This PR adds a signature check in ProcessProposal for PFB transactions.

blocked by celestiaorg/cosmos-sdk#296

closes #979

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

@evan-forbes evan-forbes added consensus breaking modifies block validity rules in a way that will break consensus unless all nodes update their rules block validity rule labels Jan 26, 2023
@evan-forbes evan-forbes added this to the Incentivized Testnet milestone Jan 26, 2023
@evan-forbes evan-forbes self-assigned this Jan 26, 2023
@evan-forbes evan-forbes requested a review from cmwaters January 26, 2023 06:13
@MSevey MSevey requested review from a team and MSevey and removed request for a team January 26, 2023 06:13
@evan-forbes evan-forbes requested review from rootulp and removed request for MSevey January 26, 2023 06:13
@MSevey MSevey requested a review from a team January 26, 2023 06:59
@evan-forbes evan-forbes added the ABCI modifies an ABCI method label Jan 26, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2023

Codecov Report

Attention: Patch coverage is 0% with 94 lines in your changes missing coverage. Please review.

Project coverage is 48.17%. Comparing base (0b75c9c) to head (7f157b9).
Report is 1155 commits behind head on main.

Files with missing lines Patch % Lines
app/parse_txs.go 0.00% 39 Missing ⚠️
app/process_proposal.go 0.00% 27 Missing ⚠️
app/verify_txs.go 0.00% 16 Missing ⚠️
app/prepare_proposal.go 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1300      +/-   ##
==========================================
- Coverage   49.20%   48.17%   -1.04%     
==========================================
  Files          76       77       +1     
  Lines        4292     4384      +92     
==========================================
  Hits         2112     2112              
- Misses       2004     2096      +92     
  Partials      176      176              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

app/test/fuzz_abci_test.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
Comment on lines 17 to 20
// RandBlobTxsWithAccounts will create random blob transactions using the
// provided configuration. The account info is queried directly from the
// application. One blob transaction is generated per account provided.
func RandBlobTxsWithAccounts(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding to our testing technical debt a bit by continuing to copy paste minor alterations of this function. #1114

we have to keep this in the testutil pkg instead of blob factory because we're importing the app to query directly, and don't want to cause an import cycle in blobfactory

cmwaters
cmwaters previously approved these changes Jan 26, 2023
Copy link
Contributor

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything here makes sense to me.

Valid signatures don't mean valid PFBs. I'm not sure how important the distinction is for the users that requested this. But just want to make sure that they're aware that although all PFBs have valid signatures they may be missing other things.

@evan-forbes
Copy link
Member Author

Valid signatures don't mean valid PFBs. I'm not sure how important the distinction is for the users that requested this. But just want to make sure that they're aware that although all PFBs have valid signatures they may be missing other things.

yes good point this is definitely true. In this case, we only want to be able to make an honest majority assumption that the signatures are valid, because it dramatically reduces the proving time of some zk proofs.

This is only the minimum to close #979,

In practice this could mean that we only add an additional signature check, but we could also check that there are enough funds to pay gas...

if we want other features such as fee burning, that will essentially require executing the transactions in full before we progress

@cmwaters
Copy link
Contributor

I believe the default implementation of the SDK v0.47 (i.e. with the introduction of PrepareProposal and ProcessProposal) by default calls something similar to CheckTx on all transactions in ProcessProposal

@evan-forbes
Copy link
Member Author

to clarify things a bit, we are also already enforcing the validate basic checks, that only a single MsgPFB is in a PFB transaction, and that the share commitment is valid. Therefore, I believe the only other way an invalid PFB can be introduced is if the account does not have enough funds to pay for gas.

@cmwaters
Copy link
Contributor

Therefore, I believe the only other way an invalid PFB can be introduced is if the account does not have enough funds to pay for gas

Or because of an incorrect nonce

@evan-forbes
Copy link
Member Author

evan-forbes commented Jan 26, 2023

Or because of an incorrect nonce

I believe we are checking for that in this PR since that is required to verify the signature via the SigVerifyAnteDecorator

edit: link to save a search https://github.com/celestiaorg/cosmos-sdk/blob/472f7a7633c16835145381c4effc31dc8c99f738/x/auth/ante/sigverify.go#L267-L273

@cmwaters
Copy link
Contributor

I believe we are checking for that in this PR since that is required to verify the signature via the SigVerifyAnteDecorator

I see, but is the cached state tracked and updated?

Take the following scenarios:

  • A user sends a vote message and a PFB with the same nonce number (5 for example). Upon execution only the first message will be executed. The second will be invalidated by the execution of the first. However both would pass CheckTx.
  • A user sends a vote message and a PFB message with incrementing nonce numbers (i.e. 5 and 6). In that order both should be able to be executed in the same block. But if we check from a snapshot of state, the second message with a nonce of 6 will be invalid.

Copy link
Member Author

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of the changes introduced here are testing related since we added stateful requirements to both prepare and process proposal, and many of the test txs we were using before didn't have valid signatures or nonce usage.

Comment on lines 28 to 42
sdkCtx, err := app.NewProcessProposalQueryContext()
if err != nil {
panic(err)
}

// increment the sequences of the standard cosmos-sdk transactions. Panics
// from the anteHandler are caught and logged.
isHandler := incrementSequenceAnteHandler(&app.AccountKeeper)
normalTxs, sdkCtx = filterStdTxs(app.Logger(), app.txConfig.TxDecoder(), sdkCtx, isHandler, normalTxs)

// check the signatures and increment the sequences of the blob transations,
// and filter out any that fail. Panics from the anteHandler are caught and
// logged.
svHandler := sigVerifyAnteHandler(&app.AccountKeeper, app.txConfig)
blobTxs, _ = filterBlobTxs(app.Logger(), app.txConfig.TxDecoder(), sdkCtx, svHandler, blobTxs)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is where we add stateful checks to prepare proposal. notice that we are incrementing the nonce of the normal txs first before we are checking the signatures of the PFB txs.

Comment on lines -35 to +40
{"many small single share single blob transactions", 10000, 1, 400},
{"many small single share single blob transactions", 1000, 1, 400},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduced the length of this first test because it takes so long that sometimes we don't even run it once. changing this means that, at least in this test, are no longer testing for the weird things that can happen when using a bunch of small PFBs occasionally. We might still want to do that in the future, but I'm less worried now that we are limiting the number of txs to 5000.

Comment on lines +64 to +74
// create 100 send transactions
sendTxs := testutil.SendTxsWithAccounts(
t,
testApp,
encConf.TxConfig.TxEncoder(),
kr,
1000,
accounts[0],
accounts[len(accounts)-100:],
"",
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this refactor was needed cause now we need access to state to query for account info before we can create the txs

Comment on lines -84 to -89
// verify the signatures of the prepared txs
sdata, err := signer.GetSignerData()
require.NoError(t, err)

dec := encoding.IndexWrapperDecoder(encCfg.TxConfig.TxDecoder())
for _, tx := range res.BlockData.Txs {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this portion of this test was leftover from when we were malleating txs for multiple square sizes, so we can remove. It no longer works since this portion of the test only works when we don't need access to state.

Comment on lines +165 to +166
accnts := testfactory.GenerateAccounts(numBlobTxs + numNormalTxs)
testApp, kr := testutil.SetupTestAppWithGenesisValSet(accnts...)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of our prepare/process proposal tests need to sign txs with correct nonces and account numbers, therefore we have to change most of the tests to account for this

@@ -154,59 +270,6 @@ func TestProcessProposal(t *testing.T) {
}
}

func TestProcessProposalWithParityShareNamespace(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this test up to the other test, see comment there to see why we probably don't even need this test unless we have some code that let's us bypass these checks in prepare proposal #233

require.Equal(t, abci.ResponseProcessProposal_REJECT, res.Result)
}

func TestProcessProposalWithTamperedSequenceStart(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consolidated this test in the above test

app/test/process_proposal_test.go Show resolved Hide resolved
Comment on lines +33 to +41
// recoverHandler will simply wrap the caught panic in an error containing the
// stack trace.
func recoverHandler(recoveryObj interface{}) error {
return sdkerrors.Wrap(
sdkerrors.ErrPanic, fmt.Sprintf(
"recovered: %v\nstack:\n%v", recoveryObj, string(debug.Stack()),
),
)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the nonce increment decorator panics if the account isn't present, so we have to add this. It should never get hit if block producers are honest and are running check tx

Comment on lines +19 to +24
// RandBlobTxsWithAccounts will create random blob transactions using the
// provided configuration. The account info is queried directly from the
// application. One blob transaction is generated per account provided.
func RandBlobTxsWithAccounts(
t *testing.T,
capp *app.App,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to sign txs with valid sequences and account numbers, and have to query for those w/o grpc if we want to use the testapp, so I created even more testing functions (that we should consolidate in #1114) to query the app directly

@evan-forbes evan-forbes marked this pull request as ready for review January 29, 2023 02:34
rootulp
rootulp previously approved these changes Jan 29, 2023
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any blocking feedback. I do have a question: IIUC the motivation for this PR was to verify the validity of signatures on PFB transactions so that once a transaction is included in a block, we know that its signature was valid.

Now that prepare proposal and process proposal are verifying the sequence number and signature of PFB transactions, should we consider (at a later date) extending that to apply to all types of transactions?

app/parse_txs.go Outdated Show resolved Hide resolved
app/prepare_proposal.go Outdated Show resolved Hide resolved
app/test/prepare_proposal_test.go Outdated Show resolved Hide resolved
app/test/prepare_proposal_test.go Outdated Show resolved Hide resolved
Co-authored-by: Rootul P <[email protected]>
rootulp
rootulp previously approved these changes Jan 30, 2023
@evan-forbes evan-forbes merged commit a6f6c23 into main Jan 31, 2023
@evan-forbes evan-forbes deleted the evan/pfb-sig-check branch January 31, 2023 22:02
evan-forbes added a commit that referenced this pull request Feb 27, 2023
…valid signatures (#1300)

## Overview

This PR adds a signature check in ProcessProposal for PFB transactions.

blocked by celestiaorg/cosmos-sdk#296

closes #979 

## Checklist

- [x] New and updated code has appropriate documentation
- [x] New and updated code has new and/or updated testing
- [x] Required CI checks are passing
- [x] Visual proof for any user facing features like CLI or
documentation updates
- [x] Linked issues closed with keywords

---------

Co-authored-by: Rootul P <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ABCI modifies an ABCI method consensus breaking modifies block validity rules in a way that will break consensus unless all nodes update their rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Add validity checks for PFB transactions during ProcessProposal
4 participants