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

Update rustbn-wasm usage #3304

Merged
merged 16 commits into from
Mar 8, 2024
Merged

Update rustbn-wasm usage #3304

merged 16 commits into from
Mar 8, 2024

Conversation

acolytec3
Copy link
Contributor

@acolytec3 acolytec3 commented Mar 5, 2024

This PR updates the rustbn-wasm verion to use the new API of an async init function, following kzg-wasm.

It also adds a new evm.create async constructor.

Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 87.87879% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 86.92%. Comparing base (a35bf07) to head (18fc5bd).

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 88.43% <ø> (ø)
blockchain 91.61% <ø> (ø)
client 84.89% <ø> (ø)
common 98.43% <ø> (ø)
devp2p 82.12% <ø> (ø)
ethash ∅ <ø> (∅)
evm 74.05% <85.71%> (+0.01%) ⬆️
genesis 99.98% <ø> (ø)
rlp ∅ <ø> (?)
statemanager 77.00% <ø> (ø)
trie 89.28% <ø> (ø)
tx 95.55% <ø> (ø)
util 89.19% <ø> (ø)
vm 79.85% <100.00%> (+0.03%) ⬆️
wallet 88.35% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@acolytec3 acolytec3 marked this pull request as draft March 5, 2024 20:17
@acolytec3 acolytec3 added the dependencies Pull requests that update a dependency file label Mar 5, 2024
@@ -137,9 +137,15 @@ export class EVM implements EVMInterface {

protected readonly _emit: (topic: string, data: any) => Promise<void>

constructor(opts: EVMOpts = {}) {
this.events = new AsyncEventEmitter()
private bn128: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to create a EVM.create method similar to VM.create?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That thought definitely occurred to me while I was doing this. Let me take a look at our current usage of the EVM constructor and see if it makes sense. It would definitely simplify the API

@roninjin10
Copy link
Collaborator

Another benifit of this change is you should see slightly faster startup time because wasm compilation won't block module resolution

Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

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

Preliminary review with some thoughts 😄 👍

Copy link
Member

Choose a reason for hiding this comment

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

The ethereum-tests update is in this PR?


static async create(opts: EVMOpts) {
if (opts.bn128 === undefined) {
opts.bn128 = await initRustBN()
Copy link
Member

Choose a reason for hiding this comment

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

Is it an idea to add something similar like customCrypto for these rustbn-wasm? Then we would treat them at the same foot as the crypto?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that but this isn't really "custom crypto". This is just our existing dependency but since it now requires an async constructor, I'm having to pass it in. In this case, I don't think it makes sense to instantiate it in Common or even attach it there. There isn't an alternative implementation of the crypto anywhere that I'm aware of aside from the one older ASM version we were previously using.

return new EVM(opts)
}
constructor(opts: EVMOpts) {
if (opts.bn128 === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

This is breaking 🤔 Do we want this?

When we still had mcl-wasm I think we added an initPromise to the EVM. Whenever something was called, first this initPromise was awaited. In this case this initPromise would normally consist of the initRustBN in case the bn128 is not provided 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is breaking here? I guess it's not obvious to me why we would want to allow the EVM run without this dep? We've never allowed it before so doesn't make sense to allow it now to my way of thinking.

packages/evm/test/precompiles/06-ecadd.spec.ts Outdated Show resolved Hide resolved
ec_mul: (input_hex: string) => string
}

static async create(opts: EVMOpts) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should make opts optional.

Suggested change
static async create(opts: EVMOpts) {
static async create(opts?: EVMOpts) {

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@roninjin10 FYI: we are now actually planning to do out of schedule breaking releases for EVM/VM on this (which is also an experiment for us).

We would not want to do this too often, but for this very general fix to make and the new EVM.create() constructor it seems justified here.

If you do opinions and/or remarks on this let us know! 🙏 🙂

@holgerd77
Copy link
Member

(so this will slightly postpone the schedule for this release round, pushing this to next week)

@holgerd77 holgerd77 merged commit 5e3cfdd into master Mar 8, 2024
36 checks passed
@holgerd77 holgerd77 deleted the update-rustbn-wasm branch March 8, 2024 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants