-
Notifications
You must be signed in to change notification settings - Fork 297
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: create foundation for fraudulent block production #1992
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2e222d3
feat!: add malicious application
evan-forbes 5ea91fd
feat: add the hasher
evan-forbes 693f5f2
feat: add malicious tree
evan-forbes a949d93
chore: add quick test
evan-forbes c6bade0
chore: linter
evan-forbes b056768
fix: options for constructor of blind tree
evan-forbes c261aea
chore: bump to v0.17.0 of nmt
evan-forbes dca34c2
chore: use v0.9.0 rsmt2d
evan-forbes f4f88db
fix: docs and feedback
evan-forbes 1d6b2b0
chore: linter
evan-forbes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package malicious | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/celestiaorg/celestia-app/app" | ||
"github.com/celestiaorg/celestia-app/app/encoding" | ||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
servertypes "github.com/cosmos/cosmos-sdk/server/types" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
"github.com/tendermint/tendermint/libs/log" | ||
dbm "github.com/tendermint/tm-db" | ||
) | ||
|
||
const ( | ||
// PrepareProposalHandlerKey is the key used to retrieve the PrepareProposal handler from the | ||
// app options. | ||
PrepareProposalHandlerKey = "prepare_proposal_handler" | ||
) | ||
|
||
type App struct { | ||
*app.App | ||
preparePropsoalHandler func(req abci.RequestPrepareProposal) abci.ResponsePrepareProposal | ||
} | ||
|
||
func New( | ||
logger log.Logger, | ||
db dbm.DB, | ||
traceStore io.Writer, | ||
loadLatest bool, | ||
skipUpgradeHeights map[int64]bool, | ||
homePath string, | ||
invCheckPeriod uint, | ||
encodingConfig encoding.Config, | ||
appOpts servertypes.AppOptions, | ||
baseAppOptions ...func(*baseapp.BaseApp), | ||
) *App { | ||
goodApp := app.New(logger, db, traceStore, loadLatest, skipUpgradeHeights, homePath, invCheckPeriod, encodingConfig, appOpts, baseAppOptions...) | ||
badApp := &App{App: goodApp} | ||
|
||
// default to using the good app's handlers | ||
badApp.SetPrepareProposalHandler(goodApp.PrepareProposal) | ||
|
||
// override the handler if it is set in the app options | ||
if prepareHander := appOpts.Get(PrepareProposalHandlerKey); prepareHander != nil { | ||
badApp.SetPrepareProposalHandler(prepareHander.(func(req abci.RequestPrepareProposal) abci.ResponsePrepareProposal)) | ||
} | ||
|
||
return badApp | ||
} | ||
|
||
func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePrepareProposal { | ||
return app.preparePropsoalHandler(req) | ||
} | ||
|
||
// SetPrepareProposalHandler sets the PrepareProposal handler. | ||
func (app *App) SetPrepareProposalHandler(handler func(req abci.RequestPrepareProposal) abci.ResponsePrepareProposal) { | ||
app.preparePropsoalHandler = handler | ||
} | ||
|
||
// ProcessProposal overwrites the default app's method to auto accept any | ||
// proposal. | ||
func (app *App) ProcessProposal(_ abci.RequestProcessProposal) (resp abci.ResponseProcessProposal) { | ||
return abci.ResponseProcessProposal{ | ||
Result: abci.ResponseProcessProposal_ACCEPT, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package malicious | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/celestiaorg/celestia-app/pkg/wrapper" | ||
"github.com/celestiaorg/celestia-app/test/util/testfactory" | ||
"github.com/celestiaorg/celestia-app/test/util/testnode" | ||
"github.com/stretchr/testify/require" | ||
tmrand "github.com/tendermint/tendermint/libs/rand" | ||
) | ||
|
||
// TestOutOfOrderNMT tests that the malicious NMT implementation is able to | ||
// generate the same root as the ordered NMT implementation when the leaves are | ||
// added in the same order and can generate roots when leaves are out of | ||
// order. | ||
func TestOutOfOrderNMT(t *testing.T) { | ||
squareSize := uint64(64) | ||
c := NewConstructor(squareSize) | ||
goodConstructor := wrapper.NewConstructor(squareSize) | ||
|
||
orderedTree := goodConstructor(0, 0) | ||
maliciousOrderedTree := c(0, 0) | ||
maliciousUnorderedTree := c(0, 0) | ||
data := testfactory.GenerateRandNamespacedRawData(64) | ||
|
||
// compare the roots generated by pushing ordered data | ||
for _, d := range data { | ||
err := orderedTree.Push(d) | ||
require.NoError(t, err) | ||
err = maliciousOrderedTree.Push(d) | ||
require.NoError(t, err) | ||
} | ||
|
||
goodOrderedRoot, err := orderedTree.Root() | ||
require.NoError(t, err) | ||
malOrderedRoot, err := maliciousOrderedTree.Root() | ||
require.NoError(t, err) | ||
require.Equal(t, goodOrderedRoot, malOrderedRoot) | ||
|
||
// test the new tree with unordered data | ||
for i := range data { | ||
j := tmrand.Intn(len(data)) | ||
data[i], data[j] = data[j], data[i] | ||
} | ||
|
||
for _, d := range data { | ||
err := maliciousUnorderedTree.Push(d) | ||
require.NoError(t, err) | ||
} | ||
|
||
root, err := maliciousUnorderedTree.Root() | ||
require.NoError(t, err) | ||
require.Len(t, root, 90) // two namespaces + 32 bytes of hash = 90 bytes | ||
require.NotEqual(t, goodOrderedRoot, root) // quick sanity check to ensure the roots are different | ||
} | ||
|
||
func TestMaliciousNodeTestNode(t *testing.T) { | ||
// TODO: flesh out this test further | ||
cfg := testnode.DefaultConfig(). | ||
WithAppCreator(NewAppServer) | ||
|
||
cctx, _, _ := testnode.NewNetwork(t, cfg) | ||
|
||
require.NoError(t, cctx.WaitForNextBlock()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd prefer to call this package faulty for capturing general faulty behaviour but YMMV