Skip to content

Commit

Permalink
Merge pull request #58 from cosmos/dev
Browse files Browse the repository at this point in the history
Increase coin denom max size
  • Loading branch information
ftheirs authored May 5, 2022
2 parents 114e3b1 + 4484d9f commit 78a1a26
Show file tree
Hide file tree
Showing 46 changed files with 155 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=2
# This is the `spec_version` field of `Runtime`
APPVERSION_N=34
# This is the patch version of this release
APPVERSION_P=2
APPVERSION_P=3
5 changes: 4 additions & 1 deletion app/src/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ typedef enum {
#define COIN_DEFAULT_DENOM_FACTOR 6
#define COIN_DEFAULT_DENOM_TRIMMING 6

#define COIN_DENOM_MAXSIZE 50
// Coin denoms may be up to 128 characters long
// https://github.com/cosmos/cosmos-sdk/blob/master/types/coin.go#L780
// https://github.com/cosmos/ibc-go/blob/main/docs/architecture/adr-001-coin-source-tracing.md
#define COIN_DENOM_MAXSIZE 129
#define COIN_AMOUNT_MAXSIZE 50

#define COIN_MAX_CHAINID_LEN 20
Expand Down
61 changes: 61 additions & 0 deletions tests/testcases/manual.json
Original file line number Diff line number Diff line change
Expand Up @@ -1878,5 +1878,66 @@
"5 | Gas : V3"
],
"expert": true
},
{
"name": "ibc_denoms",
"tx": {
"account_number": "0",
"chain_id": "cosmoshub-4",
"fee": {
"amount": [
{
"amount": "5",
"denom": "uatom"
}
],
"gas": "10000"
},
"memo": "testmemo",
"msgs": [
{
"inputs": [
{
"address": "cosmosaccaddr1d9h8qat5e4ehc5",
"coins": [
{
"amount": "10",
"denom": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2"
}
]
}
],
"outputs": [
{
"address": "cosmosaccaddr1da6hgur4wse3jx32",
"coins": [
{
"amount": "10",
"denom": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2"
}
]
}
]
}
],
"sequence": "1"
},
"parsingErr": "No error",
"validationErr": "No error",
"expected": [
"0 | Chain ID : cosmoshub-4",
"1 | Account : 0",
"2 | Sequence : 1",
"3 | Source Address : cosmosaccaddr1d9h8qat5e4ehc5",
"4 | Source Coins [1/2] : 10 ibc/27394FB092D2ECCD56123C74F36E4C1F",
"4 | Source Coins [2/2] : 926001CEADA9CA97EA622B25F41E5EB2",
"5 | Dest Address : cosmosaccaddr1da6hgur4wse3jx32",
"6 | Dest Coins [1/2] : 10 ibc/27394FB092D2ECCD56123C74F36E4C1F",
"6 | Dest Coins [2/2] : 926001CEADA9CA97EA622B25F41E5EB2",
"7 | Memo : testmemo",
"8 | Fee : 5 uatom",
"9 | Gas : 10000"
],
"expert": true
}
]
2 changes: 1 addition & 1 deletion tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"testSR25519": "jest --detectOpenHandles --runInBand tests/sr25519.test.ts"
},
"dependencies": {
"@zondax/zemu": "^0.27.4",
"@zondax/zemu": "^0.29.0",
"ledger-cosmos-js": "^2.1.8"
},
"devDependencies": {
Expand Down
Binary file added tests_zemu/snapshots/s-ibc_denoms/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/s-ibc_denoms/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/s-ibc_denoms/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/s-ibc_denoms/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/s-ibc_denoms/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/s-ibc_denoms/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/s-ibc_denoms/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/s-ibc_denoms/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/s-ibc_denoms/00008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/s-ibc_denoms/00009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/s-ibc_denoms/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/s-ibc_denoms/00011.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sp-ibc_denoms/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sp-ibc_denoms/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sp-ibc_denoms/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sp-ibc_denoms/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sp-ibc_denoms/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sp-ibc_denoms/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sp-ibc_denoms/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sp-ibc_denoms/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sp-ibc_denoms/00008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sp-ibc_denoms/00009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests_zemu/snapshots/sp-ibc_denoms/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-mainmenu/00004.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00010.png
Binary file added tests_zemu/snapshots/x-ibc_denoms/00000.png
Binary file added tests_zemu/snapshots/x-ibc_denoms/00001.png
Binary file added tests_zemu/snapshots/x-ibc_denoms/00002.png
Binary file added tests_zemu/snapshots/x-ibc_denoms/00003.png
Binary file added tests_zemu/snapshots/x-ibc_denoms/00004.png
Binary file added tests_zemu/snapshots/x-ibc_denoms/00005.png
Binary file added tests_zemu/snapshots/x-ibc_denoms/00006.png
Binary file added tests_zemu/snapshots/x-ibc_denoms/00007.png
Binary file added tests_zemu/snapshots/x-ibc_denoms/00008.png
Binary file added tests_zemu/snapshots/x-ibc_denoms/00009.png
Binary file added tests_zemu/snapshots/x-ibc_denoms/00010.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00004.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00010.png
42 changes: 42 additions & 0 deletions tests_zemu/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,45 @@ export const example_tx_str_basic_extra_fields = {
sequence: '106',
unknown_field: 123456
}

export const ibc_denoms = {
account_number: "0",
chain_id: "cosmoshub-4",
fee: {
amount: [
{
"amount": '5',
"denom": 'uatom',
}
],
gas: '10000',
},
memo: "testmemo",
msgs: [
{
inputs: [
{
address: "cosmosaccaddr1d9h8qat5e4ehc5",
coins: [
{
amount: '10',
denom: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2'
}
]
}
],
outputs: [
{
address: 'cosmosaccaddr1da6hgur4wse3jx32',
coins: [
{
amount: '10',
denom: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2'
}
]
}
]
}
],
sequence: '1'
}
47 changes: 46 additions & 1 deletion tests_zemu/tests/standard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Zemu from '@zondax/zemu'
// @ts-ignore
import CosmosApp from 'ledger-cosmos-js'
import { DEFAULT_OPTIONS, DEVICE_MODELS, example_tx_str_basic, example_tx_str_basic2 } from './common'
import { DEFAULT_OPTIONS, DEVICE_MODELS, example_tx_str_basic, example_tx_str_basic2, ibc_denoms } from './common'

// @ts-ignore
import secp256k1 from 'secp256k1/elliptic'
Expand Down Expand Up @@ -311,4 +311,49 @@ describe('Standard', function () {
await sim.close()
}
})

test.each(DEVICE_MODELS)('ibc denoms', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...DEFAULT_OPTIONS, model: m.name })
const app = new CosmosApp(sim.getTransport())

const path = [44, 118, 0, 0, 0]
const tx = JSON.stringify(ibc_denoms)

// get address / publickey
const respPk = await app.getAddressAndPubKey(path, 'cosmos')
expect(respPk.return_code).toEqual(0x9000)
expect(respPk.error_message).toEqual('No errors')
console.log(respPk)

// do not wait here..
const signatureRequest = app.sign(path, tx)

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-ibc_denoms`)

const resp = await signatureRequest
console.log(resp)

expect(resp.return_code).toEqual(0x9000)
expect(resp.error_message).toEqual('No errors')
expect(resp).toHaveProperty('signature')

// Now verify the signature
const hash = crypto.createHash('sha256')
const msgHash = Uint8Array.from(hash.update(tx).digest())

const signatureDER = resp.signature
const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER))

const pk = Uint8Array.from(respPk.compressed_pk)

const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk)
expect(signatureOk).toEqual(true)
} finally {
await sim.close()
}
})
})

0 comments on commit 78a1a26

Please sign in to comment.