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.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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)