-
Notifications
You must be signed in to change notification settings - Fork 56
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
Adversary #492
Conversation
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.
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" |
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.
We should call build-adversary
inside the adversary-test
so that we don't have people run the test against "outdated" adversaries
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.
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); |
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.
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?
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.
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.
ah ok - so errorIndex
is always zero because we are not doing the random thing for now
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
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
andtest/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 cleanerNote
The nightfall adversary code is written such that it picks bad block or bad transaction type in the order as defined in
database.mjs
andblock.mjs
files. This order avoids the adversary from randomly pickingDuplicateNullifier
when there are no spent transactions whose nullifiers can be duplicatedDuplicateTransaction
when there are no transactions to duplicateIncorrectLeafCount
when there is no prior blockIncorrectTreeRoot
when there are no 2 prior blocksThis 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