Skip to content

Commit

Permalink
fix(legacy): fix the display issue in conflux transactions where data… (
Browse files Browse the repository at this point in the history
#575)

* fix(legacy): fix the display issue in conflux transactions where data is nonempty and transfer value is nonzero

* ci: pin the nix version to avoid some issue
  • Loading branch information
somebodyLi authored Aug 5, 2024
1 parent 9f411d0 commit f3b0717
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/prebuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
- uses: cachix/install-nix-action@v13
with:
nix_path: nixpkgs=channel:nixos-unstable
install_url: 'https://releases.nixos.org/nix/nix-2.23.3/install'
name: "Run style check"
- run: nix-shell --run "poetry install"
- run: nix-shell --run "poetry run make style_check"
Expand All @@ -26,6 +27,7 @@ jobs:
- uses: cachix/install-nix-action@v13
with:
nix_path: nixpkgs=channel:nixos-unstable
install_url: 'https://releases.nixos.org/nix/nix-2.23.3/install'
name: "Run defs check"
- run: nix-shell --run "poetry install"
- run: nix-shell --run "poetry run make defs_check"
Expand All @@ -41,6 +43,7 @@ jobs:
- uses: cachix/install-nix-action@v13
with:
nix_path: nixpkgs=channel:nixos-unstable
install_url: 'https://releases.nixos.org/nix/nix-2.23.3/install'
name: "Run gen check"
- run: nix-shell --run "poetry install"
- run: nix-shell --run "poetry run make gen_check"
Expand Down
53 changes: 18 additions & 35 deletions legacy/firmware/conflux.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ static bool layoutConfluxConfirmTx(
uint8_t *to, uint32_t to_len, const char *signer, const uint8_t *value,
uint32_t value_len, const ConfluxTokenType *token, uint32_t chain_ids,
const uint8_t *gas_price, uint32_t gas_price_len, const uint8_t *gas_limit,
uint32_t gas_limit_len, bool has_data) {
uint32_t gas_limit_len, const uint8_t *data, uint32_t data_len) {
bignum256 val = {0}, gas = {0};
uint8_t pad_val[32] = {0};
char gas_value[32] = {0};
Expand All @@ -414,17 +414,12 @@ static bool layoutConfluxConfirmTx(
} else {
strlcpy(to_str, _("to new contract?"), sizeof(to_str));
}
confluxFormatAmount(&val, token, amount, sizeof(amount));
if (token == NULL) {
if (bn_is_zero(&val) && has_data) {
strcpy(amount, _("message")); // contract
} else {
confluxFormatAmount(&val, NULL, amount, sizeof(amount));
return layoutTransactionSign(
"Conflux", 0, false, amount, to_str, signer, NULL, NULL, NULL, 0,
_("Maximum Fee:"), gas_value, NULL, NULL, NULL, NULL, NULL, NULL);
}
return layoutTransactionSign("Conflux", 0, false, amount, to_str, signer,
NULL, NULL, data, data_len, _("Maximum Fee:"),
gas_value, NULL, NULL, NULL, NULL, NULL, NULL);
} else {
confluxFormatAmount(&val, token, amount, sizeof(amount));
return layoutTransactionSign("Conflux", 0, true, amount, to_str, signer,
NULL, NULL, NULL, 0, _("Maximum Fee"),
gas_value, NULL, NULL, NULL, NULL, NULL, NULL);
Expand Down Expand Up @@ -565,36 +560,24 @@ void conflux_signing_init(ConfluxSignTx *msg, const HDNode *node) {
}

if (token != NULL) {
if (!layoutConfluxConfirmTx(
msg->data_initial_chunk.bytes + 16, 20, signer,
msg->data_initial_chunk.bytes + 36, 32, token, msg->chain_id,
msg->gas_price.bytes, msg->gas_price.size, msg->gas_limit.bytes,
msg->gas_limit.size, data_total > 0 ? true : false)) {
if (!layoutConfluxConfirmTx(msg->data_initial_chunk.bytes + 16, 20, signer,
msg->data_initial_chunk.bytes + 36, 32, token,
msg->chain_id, msg->gas_price.bytes,
msg->gas_price.size, msg->gas_limit.bytes,
msg->gas_limit.size, NULL, 0)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
conflux_signing_abort();
return;
}
} else {
if (toset) {
if (!layoutConfluxConfirmTx(pubkeyhash, 20, signer, msg->value.bytes,
msg->value.size, NULL, msg->chain_id,
msg->gas_price.bytes, msg->gas_price.size,
msg->gas_limit.bytes, msg->gas_limit.size,
data_total > 0 ? true : false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
conflux_signing_abort();
return;
}
} else {
if (!layoutConfluxConfirmTx(pubkeyhash, 0, signer, msg->value.bytes,
msg->value.size, NULL, msg->chain_id,
msg->gas_price.bytes, msg->gas_price.size,
msg->gas_limit.bytes, msg->gas_limit.size,
data_total > 0 ? true : false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
conflux_signing_abort();
return;
}
if (!layoutConfluxConfirmTx(
pubkeyhash, toset ? 20 : 0, signer, msg->value.bytes,
msg->value.size, NULL, msg->chain_id, msg->gas_price.bytes,
msg->gas_price.size, msg->gas_limit.bytes, msg->gas_limit.size,
msg->data_initial_chunk.bytes, msg->data_initial_chunk.size)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
conflux_signing_abort();
return;
}
}

Expand Down

0 comments on commit f3b0717

Please sign in to comment.