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

Make access event keys eip 6800 compatible #7594

Open
wants to merge 5 commits into
base: verkle
Choose a base branch
from

Conversation

lu-pinto
Copy link
Contributor

@lu-pinto lu-pinto commented Sep 10, 2024

PR description

This PR encodes balance, nonce, version and code size into a single leaf in Verkle, while code hash has its own leaf, as mandated by EIP-6800.
I'm not doing fixes to gas costs for EIP-4762 yet, most changes are just to superficially not charge for the same leaf twice and to make code compile. I will implement EIP-4762 gas costs in a subsequent PR.

Fixed Issue(s)

This is needed for fixing gas costs for EIP-4762

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

@lu-pinto lu-pinto changed the base branch from main to verkle September 10, 2024 10:23
@lu-pinto lu-pinto force-pushed the make-access-event-keys-eip-6800-compatible branch from a12ee48 to 7a26729 Compare September 10, 2024 10:36
@lu-pinto lu-pinto force-pushed the make-access-event-keys-eip-6800-compatible branch from 7a26729 to 755f58c Compare September 16, 2024 15:38
Copy link
Contributor

@matkt matkt left a comment

Choose a reason for hiding this comment

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

I like the proposed modification, I just have some remarks and we must not forget to add the equals method in VerkleAccount.

}
}
if (accountUpdate.isUnchanged()) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

we cannot use if, else if , else if ? I think it will be better

}

private void updateAccountStorageState(
private void generateStorageValue(
Copy link
Contributor

Choose a reason for hiding this comment

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

generateStorageValue-S ?

@@ -40,22 +40,16 @@ public class TrieKeyPreloader {
public TrieKeyPreloader() {
this.hasher = new PedersenHasher();
trieKeyAdapter = new TrieKeyBatchAdapter(hasher);
trieKeyAdapter.versionKey(
Address.ZERO); // TODO REMOVE is just to preload the native library for performance check
}

public List<Bytes32> generateAccountKeyIds() {
Copy link
Contributor

@matkt matkt Sep 17, 2024

Choose a reason for hiding this comment

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

we still need a list for this one ?

@lu-pinto lu-pinto force-pushed the make-access-event-keys-eip-6800-compatible branch from 657a18e to 764ce3a Compare September 17, 2024 14:57
Comment on lines 39 to 40
private Hash storageRoot; // TODO REMOVE AS USELESS
private int hashCode;
Copy link
Contributor

Choose a reason for hiding this comment

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

should we remove storageRoot while we are here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good shout. @matkt mentioned he will remove it in future PR so I didn't want to create conflicts unnecessarily

Copy link
Contributor

@matkt matkt left a comment

Choose a reason for hiding this comment

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

Added comment but approve to unblock

.getStorageKeyValuesForUpdate()
.forEach(
(storageSlotKey, pair) -> {
var storageAccountUpdate = worldStateUpdater.getStorageToUpdate().get(accountKey);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this one is still needed as we already checked here https://github.com/hyperledger/besu/pull/7594/files#diff-a8c0068954d44abe33b85a9a6c2b70309adb959255e417350abe54c858574b62R267 but maybe I missing something ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I understand. So the link you posted is when the key values are generated. Here we commit them to the trie in one go.
On generation we only have the storageSlotKey and corresponding key/value. We don't have the storageUpdate ref where we should save the prior value

final Bytes priorValue =
accountUpdate.getPrior() == null ? null : accountUpdate.getPrior().serializeAccount();
final Bytes accountValue = accountUpdate.getUpdated().serializeAccount();
if (!accountValue.equals(priorValue)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@lu-pinto
Copy link
Contributor Author

I noticed that adding VerkleAccount.equals/hashcode changes the state root in LogRollingTests. I'm going to remove that commit for now and should be investigated next week

 minor change and method renames

Signed-off-by: Luis Pinto <[email protected]>
 use 0.0.3-SNAPSHOT with timestamp

Signed-off-by: Luis Pinto <[email protected]>
@lu-pinto lu-pinto force-pushed the make-access-event-keys-eip-6800-compatible branch from 2d12b65 to 1a07247 Compare September 20, 2024 22:05
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.

3 participants