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

Relayed v3 support #93

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7ab9495
[auto]: add PR template
sgliner-ledger Nov 29, 2023
2555f87
[auto] Update screenshot
Jan 10, 2024
57eb57c
ledger_app.toml: add manifest
sgliner-ledger Jan 11, 2024
25ef4b0
Merge pull request #40 from LedgerHQ/auto-update-screenshots
sgliner-ledger Jan 11, 2024
104f640
[auto] Update screenshot
Feb 21, 2024
2c40675
Merge pull request #41 from LedgerHQ/auto-update-screenshots
sgliner-ledger Feb 21, 2024
f45c9fa
[auto] Update screenshot
sgliner-ledger Feb 27, 2024
9f5211f
[auto] Update screenshot
Apr 8, 2024
9f8d72b
Merge pull request #42 from LedgerHQ/auto-update-screenshots
sgliner-ledger Apr 9, 2024
4fcdbe5
add relayer support for usertx
AdoAdoAdo Jun 14, 2024
477d0b5
update nanos snapshots - partial
AdoAdoAdo Jun 14, 2024
17071cb
fix indentation
AdoAdoAdo Jun 14, 2024
ff41c92
some more fixes
AdoAdoAdo Jun 14, 2024
0a90850
update raise policy for user rejected tests
AdoAdoAdo Jul 2, 2024
5dac9c1
update nanosp snapshots
AdoAdoAdo Jul 2, 2024
1fd6515
add nanosp snapshots for new tests
AdoAdoAdo Jul 2, 2024
c506dbc
add ledger_app.toml and fix tests
AdoAdoAdo Jul 2, 2024
35a5dbe
update snapshots for nanox new tests
AdoAdoAdo Jul 2, 2024
33d1ddd
update snapshots for stax
AdoAdoAdo Jul 2, 2024
6078d1a
remove flex from supported devices
AdoAdoAdo Jul 3, 2024
a385f71
fix warnings
AdoAdoAdo Jul 3, 2024
d979da4
fix formatting
AdoAdoAdo Jul 3, 2024
dd7ad27
fix thrown exceptions
AdoAdoAdo Jul 4, 2024
536757d
remove unused import
AdoAdoAdo Jul 4, 2024
52b362f
change app version - minor
AdoAdoAdo Jul 5, 2024
b8fe4be
remove variable & add test assertion
AdoAdoAdo Jul 11, 2024
080efea
format
AdoAdoAdo Jul 11, 2024
9e78aa4
regenerate stax golden snapshots
AdoAdoAdo Jul 12, 2024
e26beed
update tests after lib changes
AdoAdoAdo Jul 18, 2024
516cd69
add missing snapshot images for stax
AdoAdoAdo Jul 18, 2024
12955e0
Merge branch 'develop' into relayed-v3-support-app-multiversx
AdoAdoAdo Sep 25, 2024
f9c6cff
update stax golden
AdoAdoAdo Sep 25, 2024
d7b55d7
update clang linter version
AdoAdoAdo Sep 25, 2024
0960858
Merge pull request #94 from multiversx/relayed-v3-support-app-multiversx
AdoAdoAdo Sep 30, 2024
9d423bc
updated snapshots for nanox, nanosp
mradian1 Jan 13, 2025
a19fdad
replaced deprecated functions
mradian1 Jan 14, 2025
d978184
fix lint check error
mradian1 Jan 14, 2025
719365d
fix lint problems
mradian1 Jan 14, 2025
f73a376
usage.md updated
mradian1 Jan 14, 2025
8a348b0
linting fixes
mradian1 Jan 14, 2025
c5eda84
fixes after review
mradian1 Jan 15, 2025
10095ac
lint fix
mradian1 Jan 15, 2025
42e6056
Merge pull request #96 from multiversx/fix-deprecated-fuctions
mradian1 Jan 15, 2025
61cccbb
Adjust MAX_VALUE_LEN.
andreibancioiu Jan 15, 2025
39deb2f
Adjust constants, instead.
andreibancioiu Jan 15, 2025
717e1e0
Fix readme.
andreibancioiu Jan 15, 2025
3488706
Undo change.
andreibancioiu Jan 15, 2025
569c319
Merge pull request #97 from multiversx/stax-limits
andreibancioiu Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

APPNAME = "MultiversX"
APPVERSION_M = 1
APPVERSION_N = 0
APPVERSION_P = 23
APPVERSION_N = 1
APPVERSION_P = 0
APPVERSION = $(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

ifeq ($(TARGET_NAME),TARGET_NANOS)
Expand Down
8 changes: 8 additions & 0 deletions ledger_app.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[app]
build_directory = "./"
sdk = "C"
devices = ["nanos", "nanox", "nanos+", "stax"]

[tests]
unit_directory = "./unit-tests/"
pytest_directory = "./tests/"
4 changes: 2 additions & 2 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ typedef enum { CONTRACT_DATA_ENABLED = true, CONTRACT_DATA_DISABLED = false } co
#define SHA3_KECCAK_BITS 256
#define PUBLIC_KEY_LEN 32
#define BASE_10 10
#define TX_SIGN_FLOW_SIZE 9
#define ESDT_TRANSFER_FLOW_SIZE 9
#define TX_SIGN_FLOW_SIZE 10
#define ESDT_TRANSFER_FLOW_SIZE 10
#define BASE_64_INVALID_CHAR '?'
#define SC_ARGS_SEPARATOR '@'
#define MAX_ESDT_VALUE_HEX_COUNT 32
Expand Down
17 changes: 17 additions & 0 deletions src/parse_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,19 @@ uint16_t verify_guardian(bool *valid) {
return MSG_OK;
}

uint16_t verify_relayer(bool *valid) {
if (strncmp(tx_hash_context.current_field, RELAYER_FIELD, strlen(RELAYER_FIELD)) == 0) {
if (tx_hash_context.current_value_len >= sizeof(tx_context.relayer)) {
return ERR_INVALID_MESSAGE;
}
memmove(tx_context.relayer,
tx_hash_context.current_value,
tx_hash_context.current_value_len);
*valid = true;
}
return MSG_OK;
}

// verifies if the field and value are valid and stores them
uint16_t process_field(void) {
if (tx_hash_context.current_field_len == 0 || tx_hash_context.current_value_len == 0) {
Expand Down Expand Up @@ -452,6 +465,10 @@ uint16_t process_field(void) {
if (err != MSG_OK) {
return err;
}
err = verify_relayer(&valid_field);
if (err != MSG_OK) {
return err;
}

// verify the rest of the fields that are not displayed
valid_field |= strncmp(tx_hash_context.current_field, NONCE_FIELD, strlen(NONCE_FIELD)) == 0;
Expand Down
1 change: 1 addition & 0 deletions src/parse_tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef struct {
char esdt_value[MAX_ESDT_VALUE_HEX_COUNT + PRETTY_SIZE];
char network[8];
char guardian[FULL_ADDRESS_LENGTH];
char relayer[FULL_ADDRESS_LENGTH];
} tx_context_t;

extern tx_context_t tx_context;
Expand Down
29 changes: 17 additions & 12 deletions src/provide_ESDT_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,28 @@ static bool verify_signature(const uint8_t *data_buffer,
uint8_t hash[HASH_LEN];
cx_sha256_t sha256;
cx_ecfp_public_key_t tokenKey;
int err;

cx_sha256_init(&sha256);
cx_hash_no_throw((cx_hash_t *) &sha256, CX_LAST, data_buffer, required_len, hash, 32);
err = cx_hash_no_throw((cx_hash_t *) &sha256, CX_LAST, data_buffer, required_len, hash, 32);
if (err != CX_OK) {
return false;
}

cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1,
LEDGER_SIGNATURE_PUBLIC_KEY,
sizeof(LEDGER_SIGNATURE_PUBLIC_KEY),
&tokenKey);
err = cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1,
LEDGER_SIGNATURE_PUBLIC_KEY,
sizeof(LEDGER_SIGNATURE_PUBLIC_KEY),
&tokenKey);
if (err != CX_OK) {
return false;
}

int signature_size = data_length - required_len;
return cx_ecdsa_verify(&tokenKey,
CX_LAST,
CX_SHA256,
hash,
32,
data_buffer + required_len,
signature_size);
return cx_ecdsa_verify_no_throw(&tokenKey,
hash,
32,
data_buffer + required_len,
signature_size);
}
#endif

Expand Down
59 changes: 38 additions & 21 deletions src/sign_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ void handle_sign_msg(uint8_t p1,
the message length is computed in the first bulk, while the entire message
can come in multiple bulks
*/
int err;

if (p1 == P1_FIRST) {
char message_length_str[11];

// first 4 bytes from data_buffer should be the message length (big endian
// uint32)
if (data_length < 4) {
Expand All @@ -158,25 +159,34 @@ void handle_sign_msg(uint8_t p1,
data_buffer += 4;
data_length -= 4;
// initialize hash with the constant string to prepend
cx_keccak_init_no_throw(&sha3_context, SHA3_KECCAK_BITS);
cx_hash_no_throw((cx_hash_t *) &sha3_context,
0,
(uint8_t *) PREPEND,
sizeof(PREPEND) - 1,
NULL,
0);
err = cx_keccak_init_no_throw(&sha3_context, SHA3_KECCAK_BITS);
if (err != CX_OK) {
THROW(err);
}
err = cx_hash_no_throw((cx_hash_t *) &sha3_context,
0,
(uint8_t *) PREPEND,
sizeof(PREPEND) - 1,
NULL,
0);
if (err != CX_OK) {
THROW(err);
}

// convert message length to string and store it in the variable
// `message_length_str`
uint32_t_to_char_array(msg_context.len, message_length_str);

// add the message length to the hash
cx_hash_no_throw((cx_hash_t *) &sha3_context,
0,
(uint8_t *) message_length_str,
strlen(message_length_str),
NULL,
0);
err = cx_hash_no_throw((cx_hash_t *) &sha3_context,
0,
(uint8_t *) message_length_str,
strlen(message_length_str),
NULL,
0);
if (err != CX_OK) {
THROW(err);
}
} else {
if (p1 != P1_MORE) {
THROW(ERR_INVALID_P1);
Expand All @@ -190,19 +200,26 @@ void handle_sign_msg(uint8_t p1,
}

// add the received message part to the hash and decrease the remaining length
cx_hash_no_throw((cx_hash_t *) &sha3_context, 0, data_buffer, data_length, NULL, 0);
err = cx_hash_no_throw((cx_hash_t *) &sha3_context, 0, data_buffer, data_length, NULL, 0);
if (err != CX_OK) {
THROW(err);
}
msg_context.len -= data_length;
if (msg_context.len != 0) {
THROW(MSG_OK);
}

// finalize hash, compute it and store it in `msg_context.strhash` for display
cx_hash_no_throw((cx_hash_t *) &sha3_context,
CX_LAST,
data_buffer,
0,
msg_context.hash,
HASH_LEN);
err = cx_hash_no_throw((cx_hash_t *) &sha3_context,
CX_LAST,
data_buffer,
0,
msg_context.hash,
HASH_LEN);
if (err != CX_OK) {
THROW(err);
}

convert_to_hex_str(msg_context.strhash,
sizeof(msg_context.strhash),
msg_context.hash,
Expand Down
73 changes: 47 additions & 26 deletions src/sign_msg_auth_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ void handle_auth_token(uint8_t p1,
the account and address indexes, alongside token length are computed in
the first bulk, while the entire token can come in multiple bulks
*/
int err;

if (p1 == P1_FIRST) {
clean_token_fields();
token_auth_context.token[0] = '\0';
Expand Down Expand Up @@ -336,33 +338,46 @@ void handle_auth_token(uint8_t p1,
update_token_display_data(data_buffer, data_length);

// initialize hash with the constant string to prepend
cx_keccak_init_no_throw(&sha3_context, SHA3_KECCAK_BITS);
cx_hash_no_throw((cx_hash_t *) &sha3_context,
0,
(uint8_t *) PREPEND,
sizeof(PREPEND) - 1,
NULL,
0);
err = cx_keccak_init_no_throw(&sha3_context, SHA3_KECCAK_BITS);
if (err != CX_OK) {
THROW(err);
}

err = cx_hash_no_throw((cx_hash_t *) &sha3_context,
0,
(uint8_t *) PREPEND,
sizeof(PREPEND) - 1,
NULL,
0);
if (err != CX_OK) {
THROW(err);
}

// convert message length to string and store it in the variable `tmp`
uint32_t full_message_len = token_auth_context.len + BECH32_ADDRESS_LEN;
uint32_t_to_char_array(full_message_len, token_length_str);

// add the message length to the hash
cx_hash_no_throw((cx_hash_t *) &sha3_context,
0,
(uint8_t *) token_length_str,
strlen(token_length_str),
NULL,
0);
err = cx_hash_no_throw((cx_hash_t *) &sha3_context,
0,
(uint8_t *) token_length_str,
strlen(token_length_str),
NULL,
0);
if (err != CX_OK) {
THROW(err);
}

// add the message length to the hash
cx_hash_no_throw((cx_hash_t *) &sha3_context,
0,
(uint8_t *) token_auth_context.address,
strlen(token_auth_context.address),
NULL,
0);
err = cx_hash_no_throw((cx_hash_t *) &sha3_context,
0,
(uint8_t *) token_auth_context.address,
strlen(token_auth_context.address),
NULL,
0);
if (err != CX_OK) {
THROW(err);
}
} else {
if (p1 != P1_MORE) {
THROW(ERR_INVALID_P1);
Expand All @@ -376,20 +391,26 @@ void handle_auth_token(uint8_t p1,
}

// add the received message part to the hash and decrease the remaining length
cx_hash_no_throw((cx_hash_t *) &sha3_context, 0, data_buffer, data_length, NULL, 0);
err = cx_hash_no_throw((cx_hash_t *) &sha3_context, 0, data_buffer, data_length, NULL, 0);
if (err != CX_OK) {
THROW(err);
}

token_auth_context.len -= data_length;
if (token_auth_context.len != 0) {
THROW(MSG_OK);
}

// finalize hash and compute it
cx_hash_no_throw((cx_hash_t *) &sha3_context,
CX_LAST,
data_buffer,
0,
token_auth_context.hash,
HASH_LEN);
err = cx_hash_no_throw((cx_hash_t *) &sha3_context,
CX_LAST,
data_buffer,
0,
token_auth_context.hash,
HASH_LEN);
if (err != CX_OK) {
THROW(err);
}

// sign the hash
if (!sign_auth_token()) {
Expand Down
Loading
Loading