Coder Social home page Coder Social logo

Comments (7)

 avatar commented on July 30, 2024

Yeah,
I know that the nonces supposed to be random but if we at least get any controls over this issue, we can handle our nonces locally to finally support vechain.

from thor.

libotony avatar libotony commented on July 30, 2024

For CREATE you can calculate the contract address before sending the tx, take a look at

thor/thor/address.go

Lines 107 to 112 in bee753f

func CreateContractAddress(txID Bytes32, clauseIndex uint32, creationCount uint32) Address {
var b4_1, b4_2 [4]byte
binary.BigEndian.PutUint32(b4_1[:], clauseIndex)
binary.BigEndian.PutUint32(b4_2[:], creationCount)
return BytesToAddress(crypto.Keccak256(txID[:], b4_1[:], b4_2[:]))
}

you need txID, clauseIndex and creationCount. Regarding the creationCount, it's the overall contract creation count for one clause, so if you send a tx with one clause {to: null, data: <creation code>} then it should be 0. Please forgive me, it starts from 0 not 1
To generate the address you wanted, you need to change nonce in the tx then txID is generated and you will get the contract address. Regarding nonce it is a random number in tx which is different from ethereum's account nocne.

from thor.

libotony avatar libotony commented on July 30, 2024

thor/vm/patch.go

Lines 19 to 20 in bee753f

func CreateAddress2(b common.Address, salt [32]byte, inithash []byte) common.Address {
return common.BytesToAddress(crypto.Keccak256([]byte{0xff}, b.Bytes(), salt[:], inithash)[12:])

CREATE2 is also available.

from thor.

aghamir avatar aghamir commented on July 30, 2024

Dear @libotony,

Thanks kindly for your response.

Regarding the creationCount, it's the overall contract creation count for one clause, so if you send a tx with one clause {to: null, data: <creation code>} then it should be 1.

We need to reach the exact same contract address in CREATE due to the fact that we provide exchanges contract wallets for their users(unless the same user address will not accessible in Vechain network and causes fund loss in recovery plans). However, the minimum amount of creationCount is 1 in your solution and our generated mother contract address has nonce on 0.

CREATE2 is OK, however, we must first deploy the same address mother with CREATE in Vechain.

Do you have any solution for nonce 0?

Regards,

from thor.

libotony avatar libotony commented on July 30, 2024

We have a different tx-model than Ethereum. Take a look at the function signature:

// Ethereum
func CreateAddress(caller common.Address, nonce uint64) Address
// VeChain
func CreateContractAddress(txID Bytes32, clauseIndex uint32, creationCount uint32) Address

Regardless of the creationCount, you might not be able to create the same contract address using the same method of Ethereum. Luckily CREATE2 works.

And I took another look into the source code, creationCount starts from 0.

from thor.

aghamir avatar aghamir commented on July 30, 2024

Thanks a lot. I see the differences now. I'm not familiar with evm code and their effect on all nodes. Is it possible you add some other function like CREATELEGECY in your evm which act like ethereum one?

from thor.

libotony avatar libotony commented on July 30, 2024

@aghamir I am afraid this can not be done, sorry for the inconvenience. Closing this issue, feel free to reopen or append comments.

from thor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.