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

Use Address type #919

Merged
merged 3 commits into from
Oct 21, 2020
Merged

Use Address type #919

merged 3 commits into from
Oct 21, 2020

Conversation

ryanio
Copy link
Contributor

@ryanio ryanio commented Oct 20, 2020

This PR updates the vm to use the Address type internally and externally to improve clarity and provide strict byte length validation.

@codecov
Copy link

codecov bot commented Oct 20, 2020

Codecov Report

Merging #919 into master will decrease coverage by 0.10%.
The diff coverage is 91.30%.

Impacted file tree graph

Flag Coverage Δ
#block 75.79% <ø> (-0.22%) ⬇️
#blockchain 80.33% <ø> (-0.39%) ⬇️
#common 92.03% <ø> (ø)
#ethash 82.08% <ø> (ø)
#tx 88.18% <ø> (-0.19%) ⬇️
#vm 86.96% <91.30%> (+0.07%) ⬆️

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

} else {
const acc = await this._state.getAccount(message.caller)
const newNonce = acc.nonce.subn(1)
addr = generateAddress(message.caller, newNonce.toArrayLike(Buffer))
addr = generateAddress(message.caller.buf, newNonce.toArrayLike(Buffer))
Copy link
Member

Choose a reason for hiding this comment

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

Can we make generateAddress and generateAddress2 also take Address as input type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unfortunately those have been in ethereumjs-util for a while so we'd have to make breaking changes there. it would be nice if they output an Address as well.

another thing I noticed is it would be better if it accepted nonce as a BN instead of Buffer.

Copy link
Member

Choose a reason for hiding this comment

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

Ah woops, thought these were defined inside EVM

const result = await vm.runCall({
caller: Buffer.from('0000000000000000000000000000000000000000', 'hex'),
caller: Address.zero(),
Copy link
Member

Choose a reason for hiding this comment

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

😍

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.

Few nitpick comments, but looks good in general, I do have two main points though:

  1. Any semi-exposed functions which use a Buffer as input where an Address is expected should be changed to functions which take Address as input (seems like only a few of those remain). This makes these changes consistent. Only use the Address.buf if you really need it.
  2. I am not entirely convinced yet that the VM cannot internally hit assert(buf.length === 20, 'Invalid address length') (constructor of Address). If we safely convert BNs to Buffer via addressToBuffer this should be fine.

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.

Thanks Ryan, this looks wonderful! 🎉

Will merge this in, the suggestions from @jochem-brouwer can be done after the dev release since not life-threatening, I actually expect at least 2-3 rounds of dev releases with all the changes we've done.

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.

3 participants