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

Problem: missing high-level docs for x/cronos #183

Merged
merged 3 commits into from
Oct 26, 2021

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Oct 21, 2021

Closes: #64

Solution:

  • write cronos module spec

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

@yihuang yihuang requested a review from a team as a code owner October 21, 2021 09:16
@yihuang yihuang requested review from JayT106 and thomas-nguy and removed request for a team October 21, 2021 09:16
@codecov
Copy link

codecov bot commented Oct 21, 2021

Codecov Report

Merging #183 (2b7dba4) into main (3ea70c5) will increase coverage by 5.21%.
The diff coverage is 55.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #183      +/-   ##
==========================================
+ Coverage   21.51%   26.73%   +5.21%     
==========================================
  Files          27       33       +6     
  Lines        1729     2338     +609     
==========================================
+ Hits          372      625     +253     
- Misses       1324     1666     +342     
- Partials       33       47      +14     
Impacted Files Coverage Δ
app/prefix.go 0.00% <0.00%> (ø)
app/test_helpers.go 0.00% <0.00%> (ø)
x/cronos/keeper/grpc_query.go 0.00% <0.00%> (ø)
x/cronos/keeper/msg_server.go 4.76% <0.00%> (-1.69%) ⬇️
x/cronos/module.go 59.64% <0.00%> (-2.17%) ⬇️
x/cronos/types/codec.go 0.00% <0.00%> (ø)
x/cronos/types/events.go 0.00% <ø> (ø)
x/cronos/types/messages.go 20.22% <ø> (+20.22%) ⬆️
x/cronos/types/params.go 57.35% <ø> (+3.78%) ⬆️
x/cronos/types/proposal.go 11.11% <ø> (ø)
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9253a2d...2b7dba4. Read the comment docs.

@thomas-nguy
Copy link
Collaborator

should we include @lezzokafka and @aw126 to do proofreading

@yihuang yihuang requested a review from tomtau October 21, 2021 09:29

## Cronos

Cronos is the name of Crypto.org EVM Chain, also the module that glue multiple components together.
Copy link
Collaborator

@thomas-nguy thomas-nguy Oct 21, 2021

Choose a reason for hiding this comment

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

Cronos is an EVM chain in Crypto.org ecosystem. It allows users to deploy and interact with smart contracts. Powered by Ethermint, it is built using cosmos SDK which allows to leverage to full capability of the cosmos ecosystem. It is also connected to the ethereum network with the gravity bridge integration (WIP).

Bridging asset from cosmos or ethereum are automatically converted to a CRC20 asset when moved to Cronos which make it extremely easy to integrate with existing web3 tools.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

looks great, added.


# State Transitions

<!-- define state transitions for accounts and storage -->
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this should define the token mapping management / hooks?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added sth about the CRUD of token mapping.


## Cronos

Cronos is the name of Crypto.org EVM Chain, also the name of the main module that glues multiple components together for Cronos chain.
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe briefly describe which components have been used in Cronos

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

- When transferring CRO to Cronos chain, the decimal places of the amount are expanded to 18.
- When transferring CRO from Cronos chain, the amount is truncated to 8 decimals, the remaining part is left in Cronos, so the total value is preserved.

## Native Token
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe introduce the Token system prior to Gas Token, move Gas Token under this section.

Copy link
Collaborator

Choose a reason for hiding this comment

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

or separate the token system to an independent spec?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By token system, do you mean the difference between cosmos native tokens and evm tokens?

Copy link
Collaborator

Choose a reason for hiding this comment

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

the native token you described after line 28. then move the gas token section (line 13) under Native token

- When a `TokenMappingChangeProposal` gov proposal is executed.
- When the admin account execute a `MsgUpdateTokenMapping` message.

There's no way to delete a token mapping.
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe Highlight this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

is the token mapping part of the solidity contract or just in the store of the Cronos module?

Copy link
Collaborator Author

@yihuang yihuang Oct 21, 2021

Choose a reason for hiding this comment

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

It's in the storage of Cronos module.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

maybe Highlight this?

added a Delete section for it.

order: 0
title: EVM Overview
parent:
title: "evm"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do the titles need to be updated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch, fixed.

x/cronos/spec/01_concepts.md Outdated Show resolved Hide resolved
x/cronos/spec/01_concepts.md Outdated Show resolved Hide resolved
x/cronos/spec/02_state.md Outdated Show resolved Hide resolved
x/cronos/spec/04_messages.md Outdated Show resolved Hide resolved
x/cronos/spec/04_messages.md Outdated Show resolved Hide resolved
x/cronos/spec/05_abci.md Outdated Show resolved Hide resolved
Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

looking good 👍, I'd suggest running the text through some spell or grammar checking software (I skipped a few typos, as I guess it can be captured by https://github.com/tbroadley/spellchecker-cli grammarly etc.), but overall it's good.

two potentially good things to document are the expected upgrade behaviour + the expected Cosmos/Ethereum tooling usage, because I assume one needs to be careful there?


Cronos is an EVM chain in Crypto.org ecosystem. It allows users to deploy and interact with smart contracts. Powered by Ethermint, it is built using cosmos SDK which allows to leverage to full capability of the cosmos ecosystem. It is also connected to the ethereum network with the gravity bridge integration (WIP).

Bridging asset from cosmos or ethereum are automatically converted to a CRC20 asset when moved to Cronos which make it extremely easy to integrate with existing web3 tools.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a link to CRC20 definition?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, it's briefly described below -- but may be good to link the actual crc20 doc describing the interface

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added the link to the contract itself for now, maybe document the crc20 later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

lets create a new repository and add the specification for CRC20 and transferable tokens through bridge

x/cronos/spec/01_concepts.md Outdated Show resolved Hide resolved
x/cronos/spec/01_concepts.md Outdated Show resolved Hide resolved

## Auto-deployed Contract

A contract whose byte code is embedded in Cronos module and deployed by it, and some operations in it are only authorized to Cronos module. These contracts can be trusted by Cronos module directly. Currently, Cronos module support auto-deploy a minimal CRC20 contract to support automatic wrapping native token in EVM.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe linking the contract description or sketching out its code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added the link to the ModuleCRC20.sol.

- `KeyIbcTimeout` The timeout value to use when Cronos module transfer tokens to IBC channels.

- `KeyCronosAdmin` The account that is authorized to manage token mapping through message, empty means no admin, should be a valid bech32 cosmos address if specified.
- `KeyEnableAutoDeployment` specifies if the auto-deployment feature is enabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens when auto-deployment is off and then it's turned on via paramchange proposal? maybe good to add some comments on these parameters whether they are easily "updatable" -- to me, it seems only CronosAdmin can be updated via paramchange... the others look like that they'd need some extra code to be executed for store migrations etc. (so perhaps there should be a warning that they are not easily updatable, but would need some custom upgrade logic?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added comment on the side effects of update at runtime, it seems only IbcCroDenom needs special care to migrate the tokens.
EnableAutoDeployment should be good, because when it's disabled at runtime, only the new contract deployment is disabled, token withdrawn is not.


## MsgUpdateTokenMapping

Update external token mapping, insert if not exists, can only be called by Cronos admin account, which is configured in module parameters.
Copy link
Contributor

Choose a reason for hiding this comment

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

how is the supply managed if there was an existing token mapping, and it was updated to a different one?

Copy link
Contributor

Choose a reason for hiding this comment

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

one other thing: what if one maps several native tokens to one contract?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch, the issue is fixed here: #187
added a failure case in the doc.


## MsgTransferTokens

Transfer IBC tokens away from Cronos chain, will do decimals conversion automatically for CRO.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe some details on what it does -- I assume it'll do the conversion and do some implicit action with ibc-transfer: https://github.com/cosmos/ibc-go/blob/main/proto/ibc/applications/transfer/v1/tx.proto#L20 with some of those fields hardcoded?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it actually calls the TransferKeeper.SendTranser directly:

return k.transferKeeper.SendTransfer(

Added doc about this, and the hardcoded timeout paramters.

- The coin denom is neither IBC nor gravity tokens.
- The mapping does not exist and auto-deployment is not enabled.

## MsgTransferTokens
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the reverse of MsgConvertVouchers or how does one "exit" the EVM contract? what if the contract locks the tokens in some way?

Copy link
Collaborator Author

@yihuang yihuang Oct 25, 2021

Choose a reason for hiding this comment

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

Added comments that these messages are not supposed to be used by end-user normally, end-user can use the smart contract APIs, which might need to be documented at another time.

Currently, MsgTransferTokens only handles IBC tokens, while MsgConvertVouchers can also handle gravity tokens, so they are not the exact reverse.

how does one "exit" the EVM contract?

The message work on native token only, there's not much difference from using ibc-transfer message directly for non-cro tokens, for cro, it also does the decimal conversion.

@@ -0,0 +1,36 @@
<!-- order: 4 -->

# Messages
Copy link
Contributor

Choose a reason for hiding this comment

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

one useful information for MsgConvertVouchers and MsgTransferTokens would be to specify from/to addresses which ecosystem they are expected to come from... I assume address in MsgConvertVouchers would the be used in EVM, so it should come from the Ethereum ecosystem, but when on first transfers in the IBC tokens, they may land on an address that comes from the Cosmos ecosystem?

or would those message check the account types?

Copy link
Collaborator Author

@yihuang yihuang Oct 25, 2021

Choose a reason for hiding this comment

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

done, documented the fields.

or would those message check the account types?

The from addresses is the message signer, so they must be normal accounts. other than that, there seems no other explicit check.

Copy link
Collaborator Author

@yihuang yihuang Oct 25, 2021

Choose a reason for hiding this comment

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

I assume address in MsgConvertVouchers would the be used in EVM

The underlying method of MsgConvertVouchers is called in ibc hooks, to convert the arrived ibc token to crc20.


## Token Mapping

### Create/Update
Copy link
Contributor

Choose a reason for hiding this comment

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

how are the supplies transitioned on updates?

Copy link
Collaborator Author

@yihuang yihuang Oct 25, 2021

Choose a reason for hiding this comment

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

Added a comment on that, I think the contract develop should be able to manage the token migration themselves, on the smart contract level.

Closes: crypto-org-chain#64

Solution:
- write cronos module spec

fix wordings

add state transition

update title

highlight token mapping deletion

Apply suggestions from code review

Co-authored-by: aw126 <78806365+aw126@users.noreply.github.com>

apply suggestions

tmp

Apply suggestions from code review

Co-authored-by: Tomas Tauber <2410580+tomtau@users.noreply.github.com>

remove Key prefix

review suggstions

Revert "remove Key prefix"

This reverts commit 9fa8583a425f4cc7669fb2cb0c1ce29dcb484ea6.

remove Key prefix

review suggestions
@yihuang yihuang requested a review from tomtau October 25, 2021 02:58
Copy link
Collaborator

@thomas-nguy thomas-nguy left a comment

Choose a reason for hiding this comment

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

looks good

@yihuang yihuang merged commit f4dec0d into crypto-org-chain:main Oct 26, 2021
@yihuang yihuang deleted the docs branch October 26, 2021 01:41
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.

Problem: missing high-level docs for x/cronos
5 participants