Skip to content
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

Update Contract Address Derivation #410

Closed
ethanfrey opened this issue Feb 16, 2021 · 6 comments · Fixed by #565
Closed

Update Contract Address Derivation #410

ethanfrey opened this issue Feb 16, 2021 · 6 comments · Fixed by #565
Milestone

Comments

@ethanfrey
Copy link
Member

ethanfrey commented Feb 16, 2021

Back in 2019, I devised a custom scheme to provide a unique address to each contract.

Basically: sha256('c' | code_id | contract_counter)[:20]

With cosmos/cosmos-sdk#8415 they have now defined a standard way to derive module accounts. It looks something like:

func Module(moduleName string, key []byte) []byte{
	return Hash("module", []byte(moduleName) + 0 + key)
}

Since the 0.16 release will be breaking with many CosmWasm changes, let's take advantage of that to future-proof our derivation to be more consistent with the sdk.

I would propose something like: addr := Hash("cosmwasm", code_id | countract_counter), which is pretty similar to the old code, but the standard derivation.

We can also revisit how we create these unique key (code | contract) for each contract, although it does seem to work and our genesis import/export support this well.

@ethanfrey ethanfrey added this to the v0.16.0 milestone Feb 16, 2021
@ethanfrey
Copy link
Member Author

Maybe the new standard uses 32 byte addresses that are not fully supported until cosmos sdk 0.42. We could do this in v0.17?

@ethanfrey ethanfrey modified the milestones: v0.16.0, v0.17.0 Mar 1, 2021
@ethanfrey ethanfrey modified the milestones: v0.17.0, v1.0.0 May 7, 2021
@ethanfrey
Copy link
Member Author

This was actually implemented in cosmos/cosmos-sdk#9088

We are unlikely to import the upstream code in wasmd 1.0 (which will most likely be v0.42.x based), but we can ensure our derivation is the same as the upstream definition, so we can just swap out implementations later.

Basically, we could copy this code into x/wasm for now: https://github.com/cosmos/cosmos-sdk/pull/9088/files#diff-6cfded83a08be06034f746e83ffa6bbd6c35430cd8ac05015e6bd942c7da1030L21-R70

And use something like Compose("wasm", []Addressable{ codeId, contractCounter})

@robert-zaremba
Copy link

Check this PR: I backported that feature to Regen (which was released with 0.42 as well), and the usage:
https://github.com/regen-network/regen-ledger/pull/313/files#diff-4c9db4a1c1af45a68754c38528ea8894dccb4c75c8fc4a5203ba69cb0f57a80bR36

@ethanfrey
Copy link
Member Author

Thank you for the link (and the tip it was live)

@ethanfrey ethanfrey modified the milestones: v1.0.0, v0.18.0 Jul 27, 2021
@ethanfrey
Copy link
Member Author

If anyone is interested, please review PR #565

@webmaster128
Copy link
Member

In cosmos/cosmjs#857 you find an independent implementation of the ADR-028 spec and how it can be used for our purpose here.

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 a pull request may close this issue.

3 participants