Skip to content

Conversation

mariusmihaic
Copy link
Contributor

@mariusmihaic mariusmihaic commented Jul 28, 2021

Added NewAddress function from elrond-go.

  • In elrond-go, NewAddress is a method of BlockChainHookImpl (which will be removed in the future).
  • In elrond-go, NewAddress only uses the length of pubkeyConv (structure member) from BlockChainHookImpl (structure).
  • In here(elrond-go-core) the length of pubkeyConv is 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)

// 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing unit tests.

@iulianpascalau iulianpascalau changed the base branch from development to main September 22, 2021 08:59
@andreibancioiu andreibancioiu requested a review from Copilot August 28, 2025 11:45
Copy link

@Copilot Copilot AI left a 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 NewAddress function 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
Copy link

Copilot AI Aug 28, 2025

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'

Suggested change
// 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

Copilot uses AI. Check for mistakes.

return isOnMetaChainSCAddress
}

// NewAddress creates a new smart contract address from the creators address and nonce
Copy link

Copilot AI Aug 28, 2025

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'

Suggested change
// 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

Copilot uses AI. Check for mistakes.

}

// 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
Copy link

Copilot AI Aug 28, 2025

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'

Suggested change
// 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

Copilot uses AI. Check for mistakes.

buffNonce := make([]byte, 8)
binary.LittleEndian.PutUint64(buffNonce, creatorNonce)
adrAndNonce := append(creatorAddress, buffNonce...)
scAddress := keccak.NewKeccak().Compute(string(adrAndNonce))
Copy link

Copilot AI Aug 28, 2025

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.

Suggested change
scAddress := keccak.NewKeccak().Compute(string(adrAndNonce))
scAddress := keccak.NewKeccak().Compute(adrAndNonce)

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants