Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
abenso committed Sep 3, 2024
1 parent 0129b90 commit 7298f0b
Show file tree
Hide file tree
Showing 98 changed files with 97 additions and 29 deletions.
9 changes: 3 additions & 6 deletions app/src/apdu_handler_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,11 @@ void legacy_handleSignTransferTx(volatile uint32_t *flags, volatile uint32_t *tx
tx_type = tx_type_transaction;
CHECK_APP_CANARY()
if (error_msg != NULL) {
const int error_msg_length = strnlen(error_msg, sizeof(G_io_apdu_buffer));
memcpy(G_io_apdu_buffer, error_msg, error_msg_length);
*tx += (error_msg_length);
THROW(APDU_CODE_DATA_INVALID);
tx_reset();
*tx = 0;
THROW(APDU_CODE_LEGACY_PARSER_ERROR);
}

THROW(APDU_CODE_OK);

view_review_init(tx_getItem, tx_getNumItems, legacy_app_sign);
view_review_show(REVIEW_TXN);
*flags |= IO_ASYNCH_REPLY;
Expand Down
Binary file added tests_zemu/snapshots/sp-sign_hash_1/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-sign_hash_1/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-sign_hash_1/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-sign_hash_1/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-sign_hash_1/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-sign_hash_1/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-sign_hash_1/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-sign_hash_1/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-sign_hash_2/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-sign_hash_2/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-sign_hash_2/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-sign_hash_2/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-sign_hash_2/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-sign_hash_2/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-sign_hash_2/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-sign_hash_2/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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-sign_simple_transfer/00013.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00000.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00001.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00002.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00003.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00004.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00005.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00006.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00007.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00008.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00009.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00010.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00011.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00012.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00013.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00014.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00015.png
Binary file added tests_zemu/snapshots/sp-sign_transfer_1/00016.png
Binary file added tests_zemu/snapshots/x-sign_hash_1/00000.png
Binary file added tests_zemu/snapshots/x-sign_hash_1/00001.png
Binary file added tests_zemu/snapshots/x-sign_hash_1/00002.png
Binary file added tests_zemu/snapshots/x-sign_hash_1/00003.png
Binary file added tests_zemu/snapshots/x-sign_hash_1/00004.png
Binary file added tests_zemu/snapshots/x-sign_hash_1/00005.png
Binary file added tests_zemu/snapshots/x-sign_hash_1/00006.png
Binary file added tests_zemu/snapshots/x-sign_hash_1/00007.png
Binary file added tests_zemu/snapshots/x-sign_hash_1/00008.png
38 changes: 15 additions & 23 deletions tests_zemu/tests/legacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { blake2bFinal, blake2bInit, blake2bUpdate } from 'blakejs'

import { JSON_TEST_CASES } from './testscases/json'
import { HASH_TEST_CASES } from './testscases/hash'
import { TRANSACTIONS_TEST_CASES } from './testscases/transactions'
import { TRANSACTIONS_LEGACY_TEST_CASES } from './testscases/transactions'
import { APDU_TEST_CASES } from './testscases/legacy_apdu'
// @ts-expect-error
import ed25519 from 'ed25519-supercop'
Expand Down Expand Up @@ -181,37 +181,29 @@ describe.each(HASH_TEST_CASES)('Hash transactions', function (data) {
})
})

describe.each(TRANSACTIONS_TEST_CASES)('Tx transactions', function (data) {
describe.each(TRANSACTIONS_LEGACY_TEST_CASES)('Tx transactions', function (data) {
test.only.each(models)('sign', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = new Kda(sim.getTransport());

const responseAddr = await app.getPublicKey(data.txParams.path)
const pubKey = responseAddr.publicKey
console.log(pubKey)
const { publicKey } = await app.getPublicKey(data.txParams.path);


// do not wait here... we need to navigate
let signatureRequest = await app["signTransferTx"](data.txParams);
let signatureRequest = app["signTransferTx"](data.txParams);

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

// const signatureResponse = await signatureRequest
// console.log(signatureResponse)

// const rawHash =
// typeof data.hash == 'string'
// ? data.hash.length == 64
// ? Buffer.from(data.hash, 'hex')
// : Buffer.from(data.hash, 'base64')
// : Buffer.from(data.hash)
// // Now verify the signature
// const valid = ed25519.verify(signatureResponse.signature, rawHash, pubKey)
// expect(valid).toEqual(true)
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_${data.name}_legacy`)

// Wait until we are not in the main menu
const signatureResponse = await signatureRequest
console.log("Pubkey: ", publicKey.toString('hex'))
console.log("Signature: ", signatureResponse.signature)

// Now verify the signature
const valid = ed25519.verify(signatureResponse.signature, signatureResponse.hash, publicKey)
expect(valid).toEqual(true)
} finally {
await sim.close()
}
Expand Down
79 changes: 79 additions & 0 deletions tests_zemu/tests/testscases/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,82 @@ export const TRANSACTIONS_TEST_CASES = [
recipient_chainId: 2,
},
]

export const TRANSACTIONS_LEGACY_TEST_CASES = [
{
name: 'transfer_1',
type: TransferTxType.TRANSFER,
txParams: {
path: PATH,
recipient: '83934c0f9b005f378ba3520f9dea952fb0a90e5aa36f1b5ff837d9b30c471790',
amount: "1.23",
network: "testnet04",
chainId: 0,
gasPrice: "1.0e-6",
gasLimit: "2300",
creationTime: 1665647810,
ttl: "600",
nonce: "2022-10-13 07:56:50.893257 UTC",
},
},

// {
// name: 'transfer_test_handler_legacy_len_287',
// type: TransferTxType.TRANSFER,
// txParams: {
// path: PATH,
// recipient: '83934c0f9b005f378ba3520f9dea952fb0a90e5aa36f1b5ff837d9b30c471790',
// amount: "1.233333333333333333333333333333",
// network: "testnet040000000",
// chainId: 0,
// gasPrice: "1.011111111111111e-6",
// gasLimit: "0123456789",
// creationTime: 9876543210,
// ttl: "600000000000000000001",
// nonce: "2022-10-13 07:56:50.893257 UTC",
// namespace: "testnamespace012",
// module: "testmoduletestmoduletestmodule01"
// },
// blob : '{"networkId":"testnet04","payload":{"exec":{"data":{},"code":"(coin.transfer \\"k:de12b5e16b93fe81ca4d70656bee4334f2e40f9f28b9796e792d28f2cead74ad\\" \\"k:83934c0f9b005f378ba3520f9dea952fb0a90e5aa36f1b5ff837d9b30c471790\\" 1.23)"}},"signers":[{"pubKey":"de12b5e16b93fe81ca4d70656bee4334f2e40f9f28b9796e792d28f2cead74ad","clist":[{"args":["k:de12b5e16b93fe81ca4d70656bee4334f2e40f9f28b9796e792d28f2cead74ad","k:83934c0f9b005f378ba3520f9dea952fb0a90e5aa36f1b5ff837d9b30c471790",1.23],"name":"coin.TRANSFER"},{"args":[],"name":"coin.GAS"}]}],"meta":{"creationTime":1665647810,"ttl":600,"gasLimit":2300,"chainId":"0","gasPrice":1.0e-6,"sender":"k:de12b5e16b93fe81ca4d70656bee4334f2e40f9f28b9796e792d28f2cead74ad"},"nonce":"2022-10-13 07:56:50.893257 UTC"}',
// },

// {
// name: 'transfer_test_handler_legacy_len_285',
// type: TransferTxType.TRANSFER,
// txParams: {
// path: PATH,
// recipient: '83934c0f9b005f378ba3520f9dea952fb0a90e5aa36f1b5ff837d9b30c471790',
// amount: "1.233333333333333333333333333333",
// network: "testnet040000000",
// chainId: 0,
// gasPrice: "1.011111111111111e-6",
// gasLimit: "01234567",
// creationTime: 9876543210,
// ttl: "600000000000000000001",
// nonce: "2022-10-13 07:56:50.893257 UTC",
// namespace: "testnamespace012",
// module: "testmoduletestmoduletestmodule01"
// },
// blob : '{"networkId":"testnet04","payload":{"exec":{"data":{},"code":"(coin.transfer \\"k:de12b5e16b93fe81ca4d70656bee4334f2e40f9f28b9796e792d28f2cead74ad\\" \\"k:83934c0f9b005f378ba3520f9dea952fb0a90e5aa36f1b5ff837d9b30c471790\\" 1.23)"}},"signers":[{"pubKey":"de12b5e16b93fe81ca4d70656bee4334f2e40f9f28b9796e792d28f2cead74ad","clist":[{"args":["k:de12b5e16b93fe81ca4d70656bee4334f2e40f9f28b9796e792d28f2cead74ad","k:83934c0f9b005f378ba3520f9dea952fb0a90e5aa36f1b5ff837d9b30c471790",1.23],"name":"coin.TRANSFER"},{"args":[],"name":"coin.GAS"}]}],"meta":{"creationTime":1665647810,"ttl":600,"gasLimit":2300,"chainId":"0","gasPrice":1.0e-6,"sender":"k:de12b5e16b93fe81ca4d70656bee4334f2e40f9f28b9796e792d28f2cead74ad"},"nonce":"2022-10-13 07:56:50.893257 UTC"}',
// },

// {
// name: 'transfer_test_handler_legacy_len_284',
// type: TransferTxType.TRANSFER,
// txParams: {
// path: PATH,
// recipient: '83934c0f9b005f378ba3520f9dea952fb0a90e5aa36f1b5ff837d9b30c471790',
// amount: "1.233333333333333333333333333333",
// network: "testnet040000000",
// chainId: 0,
// gasPrice: "1.011111111111111e-6",
// gasLimit: "0123456",
// creationTime: 9876543210,
// ttl: "600000000000000000001",
// nonce: "2022-10-13 07:56:50.893257 UTC",
// namespace: "testnamespace012",
// module: "testmoduletestmoduletestmodule01"
// },
// blob : '{"networkId":"testnet04","payload":{"exec":{"data":{},"code":"(coin.transfer \\"k:de12b5e16b93fe81ca4d70656bee4334f2e40f9f28b9796e792d28f2cead74ad\\" \\"k:83934c0f9b005f378ba3520f9dea952fb0a90e5aa36f1b5ff837d9b30c471790\\" 1.23)"}},"signers":[{"pubKey":"de12b5e16b93fe81ca4d70656bee4334f2e40f9f28b9796e792d28f2cead74ad","clist":[{"args":["k:de12b5e16b93fe81ca4d70656bee4334f2e40f9f28b9796e792d28f2cead74ad","k:83934c0f9b005f378ba3520f9dea952fb0a90e5aa36f1b5ff837d9b30c471790",1.23],"name":"coin.TRANSFER"},{"args":[],"name":"coin.GAS"}]}],"meta":{"creationTime":1665647810,"ttl":600,"gasLimit":2300,"chainId":"0","gasPrice":1.0e-6,"sender":"k:de12b5e16b93fe81ca4d70656bee4334f2e40f9f28b9796e792d28f2cead74ad"},"nonce":"2022-10-13 07:56:50.893257 UTC"}',
// },
]

1 comment on commit 7298f0b

@github-actions
Copy link

Choose a reason for hiding this comment

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

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format reports: 1 file(s) not formatted
  • app/src/apdu_handler_legacy.c

Have any feedback or feature suggestions? Share it here.

Please sign in to comment.