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

Improve ToyAccount management in BytecodeRunner and ToyExecutionEnvironmentV2 #1590

Open
lorenzogentile404 opened this issue Nov 29, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@lorenzogentile404
Copy link
Collaborator

Currently, when we write tests, we explicitly create accounts in the test itself and then pass them to BytecodeRunner:

public void run(Wei senderBalance, Long gasLimit, List<ToyAccount> additionalAccounts) {
    ...

    List<ToyAccount> accounts = new ArrayList<>();
    accounts.add(senderAccount);
    accounts.add(receiverAccount);
    accounts.addAll(additionalAccounts);

    toyExecutionEnvironmentV2 =
        ToyExecutionEnvironmentV2.builder()
            .transactionProcessingResultValidator(
                TransactionProcessingResultValidator.EMPTY_VALIDATOR)
            .accounts(accounts)
            .zkTracerValidator(zkTracerValidator)
            .transaction(tx)
            .build();
    toyExecutionEnvironmentV2.run();
  }

In this way, the ToyExecutionEnvironment receives the accounts we want to be available and potentially containing some bytecode associated to them.

However, this may be not convenient when the same account is used to send more than one transaction within the same test, as the nonce has to be increased manually in test itself.
Ideally, we want the ToyExecutionEnvironment to take care of it for us. For this reason, we want the test to have the possibility to handle addresses (and potentially bytecode associated to them) only and let the ToyExecutionEnvironment do the rest of the work.

@OlivierBBB
Copy link
Collaborator

OlivierBBB commented Nov 29, 2024

to handle addresses (and potentially bytecode associated to them) only and let the ToyExecutionEnvironment do the rest of the work.

What you really want is to

  • initialize a world using a List<ToyAccount> accounts = List.of(...); with each account defined in terms of an address (or a private key), bytecode, value, nonce etc ... (and why not storage while we're at it ?)
  • when defining the transactions only use Addresses to refer to accounts
  • have the world deal with everything in between (nonce updates, deployments, balance changes, ...)

To be 100% clear: the initial value of world would only serve to initialize the world. And beyond that we (i.e. test writers) shouldn't have to interact with it any longer.

@OlivierBBB OlivierBBB added the enhancement New feature or request label Nov 29, 2024
@lorenzogentile404
Copy link
Collaborator Author

Example of test where the nonce is raised manually:
#1572
test : arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/createTests/failure/Create.java

@amkCha
Copy link
Collaborator

amkCha commented Dec 2, 2024

After digging a bit, we will look to add the nonce update at the GeneralStateReferenceTestTools.java level, after Besu MainnetTransactionProcess has executed the transaction associated. The retrieval of the account can be done at that stage too and the transaction can be instanciated with an address at the test level

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants