-
Notifications
You must be signed in to change notification settings - Fork 8
Add NewAddress public function #9
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
base: main
Are you sure you want to change the base?
Conversation
| // The address is created by applied keccak256 on the appended value off creator address and nonce | ||
| // Prefix mask is applied for first 8 bytes 0, and for bytes 9-10 - VM type | ||
| // Suffix mask is applied - last 2 bytes are for the shard ID - mask is applied as suffix mask | ||
| func NewAddress(creatorAddress []byte, addressLength int, creatorNonce uint64, vmType []byte) ([]byte, error) { |
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.
Missing unit tests.
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.
Pull Request Overview
This PR introduces the NewAddress public function to create smart contract addresses, migrating functionality from elrond-go's BlockChainHookImpl to elrond-go-core with modified parameter signature.
- Adds
NewAddressfunction that creates smart contract addresses using creator address, nonce, and VM type - Introduces supporting error definitions for address and VM type validation
- Implements helper functions for address generation using keccak256 hashing
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| core/errors.go | Adds error definitions for address length and VM type validation |
| core/address.go | Implements the main NewAddress function with supporting helper functions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| // NewAddress creates a new smart contract address from the creators address and nonce | ||
| // The address is created by applied keccak256 on the appended value off creator address and nonce | ||
| // Prefix mask is applied for first 8 bytes 0, and for bytes 9-10 - VM type |
Copilot
AI
Aug 28, 2025
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.
The comment has grammatical errors. It should read: 'Prefix mask is applied for the first 8 bytes as 0, and for bytes 9-10 as VM type'
| // Prefix mask is applied for first 8 bytes 0, and for bytes 9-10 - VM type | |
| // Prefix mask is applied for the first 8 bytes as 0, and for bytes 9-10 as VM type |
| return isOnMetaChainSCAddress | ||
| } | ||
|
|
||
| // NewAddress creates a new smart contract address from the creators address and nonce |
Copilot
AI
Aug 28, 2025
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.
There's a grammatical error in the comment. It should be 'from the creator's address' (with an apostrophe) instead of 'from the creators address'
| // NewAddress creates a new smart contract address from the creators address and nonce | |
| // NewAddress creates a new smart contract address from the creator's address and nonce |
| } | ||
|
|
||
| // NewAddress creates a new smart contract address from the creators address and nonce | ||
| // The address is created by applied keccak256 on the appended value off creator address and nonce |
Copilot
AI
Aug 28, 2025
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.
The comment contains grammatical errors. It should read: 'The address is created by applying keccak256 on the appended value of creator address and nonce'
| // The address is created by applied keccak256 on the appended value off creator address and nonce | |
| // The address is created by applying keccak256 on the appended value of creator address and nonce |
| buffNonce := make([]byte, 8) | ||
| binary.LittleEndian.PutUint64(buffNonce, creatorNonce) | ||
| adrAndNonce := append(creatorAddress, buffNonce...) | ||
| scAddress := keccak.NewKeccak().Compute(string(adrAndNonce)) |
Copilot
AI
Aug 28, 2025
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.
Converting byte slice to string and back to bytes is inefficient. The keccak.Compute method likely accepts []byte directly, or you should use a method that accepts byte slices to avoid unnecessary conversion.
| scAddress := keccak.NewKeccak().Compute(string(adrAndNonce)) | |
| scAddress := keccak.NewKeccak().Compute(adrAndNonce) |
Added
NewAddressfunction from elrond-go.NewAddressis a method ofBlockChainHookImpl(which will be removed in the future).NewAddressonly uses the length ofpubkeyConv(structure member) fromBlockChainHookImpl(structure).pubkeyConvis used as an input parameter.Function signature in elrond-go:
-> func (bh *BlockChainHookImpl) NewAddress(creatorAddress []byte, creatorNonce uint64, vmType []byte) ([]byte, error)
Function signature in here(elrond-go-core):
-> func NewAddress(creatorAddress []byte, addressLength int, creatorNonce uint64, vmType []byte) ([]byte, error)