-
Notifications
You must be signed in to change notification settings - Fork 609
refactor: eth address tech debt cleanup #4442
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,29 +33,20 @@ import { SideEffect, SideEffectLinkedToNoteHash } from '../side_effects.js'; | |
| * Note: Not to be confused with `ContractDeploymentData`. | ||
| */ | ||
| export class NewContractData { | ||
| /** | ||
| * Ethereum address of the portal contract on L1. | ||
| */ | ||
| public portalContractAddress: EthAddress; | ||
| constructor( | ||
| /** | ||
| * Aztec address of the contract. | ||
| */ | ||
| public contractAddress: AztecAddress, | ||
| /** | ||
| * Ethereum address of the portal contract on L1. | ||
| * TODO(AD): refactor this later | ||
| * currently there is a kludge with circuits cpp as it emits an AztecAddress | ||
| */ | ||
| portalContractAddress: EthAddress | AztecAddress, | ||
| public portalContractAddress: EthAddress, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting to see here that it could pass an AztecAddress and then directly checking that it was eth address after |
||
| /** | ||
| * Contract class id. | ||
| */ | ||
| public contractClassId: Fr, | ||
| ) { | ||
| // Handle circuits emitting this as an AztecAddress | ||
| this.portalContractAddress = new EthAddress(portalContractAddress.toBuffer()); | ||
| } | ||
| ) {} | ||
|
|
||
| toBuffer() { | ||
| return serializeToBuffer(this.contractAddress, this.portalContractAddress, this.contractClassId); | ||
|
|
@@ -68,11 +59,7 @@ export class NewContractData { | |
| */ | ||
| static fromBuffer(buffer: Buffer | BufferReader): NewContractData { | ||
| const reader = BufferReader.asReader(buffer); | ||
| return new NewContractData( | ||
| reader.readObject(AztecAddress), | ||
| new EthAddress(reader.readBytes(32)), | ||
| Fr.fromBuffer(reader), | ||
| ); | ||
| return new NewContractData(reader.readObject(AztecAddress), reader.readObject(EthAddress), Fr.fromBuffer(reader)); | ||
| } | ||
|
|
||
| static empty() { | ||
|
|
@@ -157,7 +144,7 @@ export class OptionallyRevealedData { | |
| Fr.fromBuffer(reader), | ||
| reader.readObject(FunctionData), | ||
| Fr.fromBuffer(reader), | ||
| new EthAddress(reader.readBytes(32)), | ||
| reader.readObject(EthAddress), | ||
| reader.readBoolean(), | ||
| reader.readBoolean(), | ||
| reader.readBoolean(), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { keccak256String } from '../crypto/keccak/index.js'; | ||
| import { randomBytes } from '../crypto/random/index.js'; | ||
| import { Fr } from '../fields/index.js'; | ||
| import { BufferReader } from '../serialize/index.js'; | ||
| import { BufferReader, FieldReader } from '../serialize/index.js'; | ||
|
|
||
| /** | ||
| * Represents an Ethereum address as a 20-byte buffer and provides various utility methods | ||
|
|
@@ -20,13 +20,7 @@ export class EthAddress { | |
| public static ZERO = new EthAddress(Buffer.alloc(EthAddress.SIZE_IN_BYTES)); | ||
|
|
||
| constructor(private buffer: Buffer) { | ||
| if (buffer.length === 32) { | ||
| if (!buffer.slice(0, 12).equals(Buffer.alloc(12))) { | ||
| throw new Error(`Invalid address buffer: ${buffer.toString('hex')}`); | ||
| } else { | ||
| this.buffer = buffer.slice(12); | ||
| } | ||
| } else if (buffer.length !== EthAddress.SIZE_IN_BYTES) { | ||
| if (buffer.length !== EthAddress.SIZE_IN_BYTES) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| throw new Error(`Expect buffer size to be ${EthAddress.SIZE_IN_BYTES}. Got ${buffer.length}.`); | ||
| } | ||
| } | ||
|
|
@@ -176,21 +170,10 @@ export class EthAddress { | |
| } | ||
|
|
||
| /** | ||
| * Alias for toBuffer32. | ||
| * @returns A 32-byte Buffer containing the padded Ethereum address. | ||
| * Returns a 20-byte buffer representation of the Ethereum address. | ||
| * @returns A 20-byte Buffer containing the Ethereum address. | ||
| */ | ||
| public toBuffer() { | ||
| return this.toBuffer32(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the internal Buffer representation of the Ethereum address. | ||
| * This method is useful when working with raw binary data or when | ||
| * integrating with other modules that require a Buffer as input. | ||
| * | ||
| * @returns A Buffer instance containing the 20-byte Ethereum address. | ||
| */ | ||
| public toBuffer20() { | ||
| return this.buffer; | ||
| } | ||
|
|
||
|
|
@@ -201,6 +184,7 @@ export class EthAddress { | |
| * | ||
| * @returns A 32-byte Buffer containing the padded Ethereum address. | ||
| */ | ||
| // TODO(#3938): nuke this | ||
| public toBuffer32() { | ||
| const buffer = Buffer.alloc(32); | ||
| this.buffer.copy(buffer, 12); | ||
|
|
@@ -225,14 +209,19 @@ export class EthAddress { | |
| return new EthAddress(fr.toBuffer().slice(-EthAddress.SIZE_IN_BYTES)); | ||
| } | ||
|
|
||
| static fromFields(fields: Fr[] | FieldReader) { | ||
| const reader = FieldReader.asReader(fields); | ||
| return EthAddress.fromField(reader.readField()); | ||
| } | ||
|
|
||
| /** | ||
| * Deserializes from a buffer or reader, corresponding to a write in cpp. | ||
| * @param buffer - Buffer to read from. | ||
| * @returns The EthAddress. | ||
| */ | ||
| static fromBuffer(buffer: Buffer | BufferReader): EthAddress { | ||
| const reader = BufferReader.asReader(buffer); | ||
| return new EthAddress(reader.readBytes(32)); | ||
| return new EthAddress(reader.readBytes(EthAddress.SIZE_IN_BYTES)); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

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.
👀