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

Adversary #492

Merged
merged 28 commits into from
Mar 7, 2022
Merged

Adversary #492

merged 28 commits into from
Mar 7, 2022

Conversation

ChaitanyaKonda
Copy link
Contributor

@ChaitanyaKonda ChaitanyaKonda commented Feb 14, 2022

This PR generates nigthfall adversary. Nightfall adversary is meant to be an adversarial block proposer that creates a combination of good and bad blocks. This is built for testing purposes. It is created using generative metaprogramming by copying nightfall-optimist code and injecting the code that creates bad blocks and bad transactions during block creation and transactions selection respectively. It creates blocks of type

  • ValidBlock
  • ValidTransaction
  • IncorrectTreeRoot
  • IncorrectLeafCount
  • DuplicateTransaction
  • DuplicateNullifier
  • HistoricRootError
  • IncorrectProof

Test
This functionality is tested by adversary-test job in check-PRs github action.

If the test is a success it means that a user has the correct balance considering the blocks proposed and rollbacks from bad blocks that contain their transaction. Bad block types to be generated are defined in files test/adversary/adversary-code/database.mjs and test/adversary/adversary-code/block.mjs. A challenger has spotted these bad blocks and successfully challenged them.

Removed neg-http.mjs because this implements the same functionality a lot cleaner

Note
The nightfall adversary code is written such that it picks bad block or bad transaction type in the order as defined in database.mjs and block.mjs files. This order avoids the adversary from randomly picking

  • DuplicateNullifier when there are no spent transactions whose nullifiers can be duplicated
  • DuplicateTransaction when there are no transactions to duplicate
  • IncorrectLeafCount when there is no prior block
  • IncorrectTreeRoot when there are no 2 prior blocks

This logic will later be replaced such that type of bad block to be generated will be picked automatically and randomly by nightfall adversary. This update depends on having a script that seeds the deployment with the first two L2 blocks and at least two transfers in the second blocks. This is being handled in the issue

Copy link
Contributor

@Westlad Westlad left a comment

Choose a reason for hiding this comment

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

Can you provide a readme please? I don't understand how this works and I would not be able to use it.

"doc:build:sdk": "jsdoc -c jsdoc.json cli/lib/nf3.mjs"
"doc:build:sdk": "jsdoc -c jsdoc.json cli/lib/nf3.mjs",
"build-adversary": "node test/adversary/transpile-adversary.mjs",
"adversary-test": "mocha --timeout 0 --bail --exit test/adversary.test.mjs"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should call build-adversary inside the adversary-test so that we don't have people run the test against "outdated" adversaries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adversary code is required at the stage of ./setup-nightfall and ./start-nightfall. Only after these two are completed do we run the tests. If there is no source code for adversary by ./start-nightfall , it complains (don't remember if it fails, my memory says it does).

We could call build-adversary in the test. It would work if some adversary code already exists during build and start stage and this version of adversary is started. After this, nodemon will create the new code again during test and restart the adversary container.

Considering we won't use nodemon in non dev deployments, I would recommend we get the developers used to calling build-adversary at the beginning of staging and prod deployments. Because they have to remember calling ./start-nightfall with -a, as well as ./setup-nightfall with adversary service too.

PS: We don't push nightfall-adversary to repo. It is part of .gitignore file

async function makeBlock(proposer, number = TRANSACTIONS_PER_BLOCK) {
logger.debug('Block Assembler - about to make a new block');
// pick a random number between 0 to 6 (error length - 1)
const errorIndex = Math.floor(Math.random() * 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what errorIndex does here - it seems to always be 0. count is always 0 as well.

Does this mean that getMostProfitableTransactions always makes valid transactions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a global variable. So it is incremented with each block proposed.
Non valid blocks get created as it increments.
This is a test run from github action
Screenshot 2022-03-07 at 09 27 57

Copy link
Contributor

Choose a reason for hiding this comment

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

ah ok - so errorIndex is always zero because we are not doing the random thing for now

@IlyasRidhuan IlyasRidhuan self-requested a review March 7, 2022 11:38
@Westlad Westlad merged commit 27b1c9b into master Mar 7, 2022
@Westlad Westlad deleted the chait/adversary2 branch March 7, 2022 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants