Skip to content

Commit

Permalink
improve delay in review transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
abenso committed Feb 3, 2025
1 parent 051a052 commit 5d45452
Show file tree
Hide file tree
Showing 30 changed files with 128 additions and 145 deletions.
67 changes: 19 additions & 48 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@ endif

MY_DIR := $(dir $(lastword $(MAKEFILE_LIST)))

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.installer_script

include $(BOLOS_SDK)/Makefile.defines

# Set the default value for PRODUCTION_BUILD to 0 if not already defined
PRODUCTION_BUILD ?= 1

$(info ************ PENUMBRA_NAME = [$(TARGET_NAME)])

# Display whether this is a production build or for internal use
ifeq ($(PRODUCTION_BUILD), 1)
$(info ************ PRODUCTION_BUILD = [PRODUCTION BUILD])
Expand All @@ -39,9 +33,8 @@ else
endif

# Display whether swap functionality is enabled or not
ifdef HAVE_SWAP
ifeq ($(ENABLE_SWAP), 1)
$(info ************ HAVE_SWAP = [ENABLED])
DEFINES += HAVE_SWAP=$(HAVE_SWAP)
else
$(info ************ HAVE_SWAP = [DISABLED])
endif
Expand All @@ -55,6 +48,9 @@ ifndef COIN
COIN=UM
endif

VARIANT_PARAM=COIN
VARIANT_VALUES=$(COIN)

include $(CURDIR)/Makefile.version

$(info COIN = [$(COIN)])
Expand All @@ -78,12 +74,7 @@ $(info PATHS LIST = $(APPPATH))

APP_LOAD_PARAMS = --curve secp256k1 $(COMMON_LOAD_PARAMS) --path $(APPPATH)
INCLUDES_PATH += $(CURDIR)/src/protobuf

ifeq ($(TARGET_NAME),TARGET_NANOS)
APP_STACK_MIN_SIZE := 1600
else
APP_STACK_MIN_SIZE := 1752
endif
INCLUDES_PATH += $(CURDIR)/src/common

# Flag to compile all Penumbra actions
FULL_APP ?= 0
Expand All @@ -92,45 +83,30 @@ DEFINES += FULL_APP
$(info ************ FULL APP ENABLED ************)
endif

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices

$(info TARGET_NAME = [$(TARGET_NAME)])
$(info ICONNAME = [$(ICONNAME)])

ifndef ICONNAME
$(error ICONNAME is not set)
endif

ifeq ($(TARGET_NAME),TARGET_NANOS)
RUST_TARGET:=thumbv6m-none-eabi
endif

ifeq ($(TARGET_NAME),TARGET_NANOX)
RUST_TARGET:=thumbv6m-none-eabi
endif

ifeq ($(TARGET_NAME),TARGET_NANOS2)
#RUST_TARGET:=thumbv8m.main-none-eabi
RUST_TARGET:=thumbv6m-none-eabi
endif

ifeq ($(TARGET_NAME),TARGET_STAX)
RUST_TARGET:=thumbv6m-none-eabi
endif
$(info ************ RUST_TARGET = [$(RUST_TARGET)])

ifeq ($(TARGET_NAME),TARGET_FLEX)
RUST_TARGET:=thumbv6m-none-eabi
endif
include $(BOLOS_SDK)/Makefile.target

$(info ************ RUST_TARGET = [$(RUST_TARGET)])
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.platform

APP_SOURCE_PATH += $(CURDIR)/rust/include
CFLAGS += -Wvla
LDFLAGS += -z muldefs
LDLIBS += -lm -lgcc -lc
LDLIBS += -L$(MY_DIR)rust/target/$(RUST_TARGET)/release -lrslib

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.installer_script

$(info TARGET_NAME = [$(TARGET_NAME)])
$(info ICONNAME = [$(ICONNAME)])

ifndef ICONNAME
$(error ICONNAME is not set)
endif

ifeq ($(DEBUG), 1)
CFLAGS += -O3 -Os -Wno-unknown-pragmas -Wno-unused-parameter -g
Expand All @@ -157,18 +133,13 @@ rust_clean:

clean: rust_clean

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.side_loading

# Import generic rules from the SDK
include $(BOLOS_SDK)/Makefile.rules
# make rust a prerequisite for all object files
$(OBJECT_FILES): rust

#add dependency on custom makefile filename
dep/%.d: %.c Makefile

.PHONY: listvariants
listvariants:
@echo VARIANTS COIN UM

.PHONY: version
version:
@echo "v$(APPVERSION)" > app.version
2 changes: 1 addition & 1 deletion app/rust/src/bolos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl RngCore for Trng {

#[cfg(not(test))]
fn fill_bytes(&mut self, dest: &mut [u8]) {
zlog("fill_bytes\x00".as_ref());
zlog("fill_bytes\x00");

unsafe {
cx_rng(dest.as_mut_ptr(), dest.len() as u32);
Expand Down
1 change: 1 addition & 0 deletions app/rust/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub const MAX_CLUE_SUBKEYS: usize = 10;
pub const MAX_REWARDS: usize = 5;

pub const EFFECT_HASH_LEN: usize = 64;
pub const UI_ADDRESS_LEN: usize = 37;

// Nonces:
pub const NONCE_LEN: usize = 12;
Expand Down
4 changes: 2 additions & 2 deletions app/rust/src/parser/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

use super::memo_plain_text::MemoPlaintextC;
use super::symmetric::{PayloadKey, PayloadKind};
use crate::constants::{MEMO_CIPHERTEXT_LEN_BYTES, MEMO_LEN_BYTES};
use crate::constants::{MEMO_CIPHERTEXT_LEN_BYTES, MEMO_LEN_BYTES, UI_ADDRESS_LEN};
use crate::parser::bytes::BytesC;
use crate::parser::effect_hash::{create_personalized_state, EffectHash};
use crate::utils::protobuf::encode_varint;
use crate::ParserError;

#[repr(C)]
#[derive(Default)]
#[cfg_attr(any(feature = "derive-debug", test), derive(Debug))]
pub struct MemoPlanC {
pub plaintext: MemoPlaintextC,
pub key: BytesC,
pub ui_address: [u8; UI_ADDRESS_LEN],
}

impl MemoPlanC {
Expand Down
4 changes: 3 additions & 1 deletion app/rust/src/parser/plans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub unsafe extern "C" fn rs_output_action_hash(
Ok(body_hash_bytes) => {
let body_hash_array = body_hash_bytes.as_array();
let copy_len: usize = core::cmp::min(output.len(), body_hash_array.len());
output[..copy_len].copy_from_slice(&body_hash_array[..copy_len]);
output[..copy_len].copy_from_slice(&body_hash_array[..copy_len]);
}
Err(err) => return err as u32,
}
Expand Down Expand Up @@ -453,6 +453,7 @@ mod tests {
text: BytesC::default(),
},
key: BytesC::from_slice(&memo_key_bytes),
ui_address: [0u8; 37],
};

// Create dummy DetectionDataPlanC
Expand Down Expand Up @@ -747,6 +748,7 @@ mod tests {
text: BytesC::from_slice(&memo_plaintext),
},
key: BytesC::from_slice(&memo_key_bytes),
ui_address: [0u8; 37],
};

let memo_hash = dummy_memo_plan.effect_hash();
Expand Down
26 changes: 7 additions & 19 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "parser_common.h"
#include "tx.h"
#include "view.h"
#include "view_internal.h"
#include "zxformat.h"
#include "zxmacros.h"

Expand Down Expand Up @@ -110,12 +109,6 @@ __Z_INLINE bool process_chunk(__Z_UNUSED volatile uint32_t *tx, uint32_t rx, boo
__Z_INLINE void handleGetAddr(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
zemu_log("handleGetAddr\n");

// TODO: Check size for nanos
#if defined(TARGET_NANOS)
*tx = 0;
THROW(APDU_CODE_DATA_INVALID);
#endif

extractHDPath(rx, OFFSET_DATA);

const uint8_t requireConfirmation = G_io_apdu_buffer[OFFSET_P1];
Expand Down Expand Up @@ -145,12 +138,6 @@ __Z_INLINE void handleGetAddr(volatile uint32_t *flags, volatile uint32_t *tx, u
__Z_INLINE void handleGetFVK(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
zemu_log("handleGetFVK\n");

// TODO: Check size for nanos
#if defined(TARGET_NANOS)
*tx = 0;
THROW(APDU_CODE_DATA_INVALID);
#endif

extractHDPath(rx, OFFSET_DATA);

zxerr_t zxerr = app_fill_keys();
Expand Down Expand Up @@ -190,6 +177,7 @@ __Z_INLINE void handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint
THROW(APDU_CODE_OK);
}

view_spinner_show("Processing...");
__Z_UNUSED const char *error_msg = tx_parse();
CHECK_APP_CANARY()
if (error_msg != NULL) {
Expand All @@ -211,14 +199,14 @@ __Z_INLINE void handle_getversion(__Z_UNUSED volatile uint32_t *flags, volatile
G_io_apdu_buffer[0] = 0x01;
#endif

G_io_apdu_buffer[1] = (LEDGER_MAJOR_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[2] = (LEDGER_MAJOR_VERSION >> 0) & 0xFF;
G_io_apdu_buffer[1] = (MAJOR_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[2] = (MAJOR_VERSION >> 0) & 0xFF;

G_io_apdu_buffer[3] = (LEDGER_MINOR_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[4] = (LEDGER_MINOR_VERSION >> 0) & 0xFF;
G_io_apdu_buffer[3] = (MINOR_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[4] = (MINOR_VERSION >> 0) & 0xFF;

G_io_apdu_buffer[5] = (LEDGER_PATCH_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[6] = (LEDGER_PATCH_VERSION >> 0) & 0xFF;
G_io_apdu_buffer[5] = (PATCH_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[6] = (PATCH_VERSION >> 0) & 0xFF;

G_io_apdu_buffer[7] = !IS_UX_ALLOWED;

Expand Down
2 changes: 2 additions & 0 deletions app/src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@

#define DEFAULT_CHAIN_ID "penumbra-1"

#define SHORT_ADDRESS_LEN sizeof(ADDR_BECH32_PREFIX) + SHORT_ADDRESS_VISIBLE_CHARS + sizeof(ELLIPSIS)

// Constant to use to allocate a buffer on the stack to hold the formatting of an output action
#define OUTPUT_DISPLAY_MAX_LEN \
(VALUE_DISPLAY_MAX_LEN + SHORT_ADDRESS_VISIBLE_CHARS + sizeof(ELLIPSIS) + sizeof(ADDR_BECH32_PREFIX) + 6) // = 202
Expand Down
5 changes: 1 addition & 4 deletions app/src/memo.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ parser_error_t memo_getItem(const parser_context_t *ctx, uint8_t displayIdx, cha
return err;
}

char short_address[100] = {0};
switch (displayIdx) {
case 0:
if (ctx->tx_obj->plan.has_memo) {
snprintf(outKey, outKeyLen, "Memo Sender Address");
CHECK_ERROR(printTxAddress(&ctx->tx_obj->plan.memo.plaintext.return_address.inner, short_address,
sizeof(short_address)));
pageString(outVal, outValLen, (char *)short_address, pageIdx, pageCount);
pageString(outVal, outValLen, (char *)ctx->tx_obj->plan.memo.ui_address, pageIdx, pageCount);
} else {
snprintf(outKey, outKeyLen, "Memo");
snprintf(outVal, outValLen, "None");
Expand Down
33 changes: 15 additions & 18 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,67 +183,64 @@ parser_error_t parser_getItem(const parser_context_t *ctx, uint8_t displayIdx, c
}
switch (ctx->tx_obj->actions_plan[action_idx].action_type) {
case penumbra_core_transaction_v1_ActionPlan_spend_tag:
CHECK_ERROR(spend_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.spend, action_idx + 1, outKey,
CHECK_ERROR(spend_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.spend, action_idx, outKey,
outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
case penumbra_core_transaction_v1_ActionPlan_output_tag:
CHECK_ERROR(output_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.output, action_idx + 1, outKey,
CHECK_ERROR(output_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.output, action_idx, outKey,
outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
case penumbra_core_transaction_v1_ActionPlan_ics20_withdrawal_tag:
CHECK_ERROR(ics20_withdrawal_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.ics20_withdrawal,
action_idx + 1, outKey, outKeyLen, outVal, outValLen, pageIdx,
pageCount))
action_idx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
#if defined(FULL_APP)
case penumbra_core_transaction_v1_ActionPlan_swap_tag:
CHECK_ERROR(swap_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.swap, action_idx + 1, outKey,
CHECK_ERROR(swap_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.swap, action_idx, outKey,
outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
#endif
case penumbra_core_transaction_v1_ActionPlan_delegate_tag:
CHECK_ERROR(delegate_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.delegate, action_idx + 1,
outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
CHECK_ERROR(delegate_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.delegate, action_idx, outKey,
outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
case penumbra_core_transaction_v1_ActionPlan_undelegate_tag:
CHECK_ERROR(undelegate_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.undelegate, action_idx + 1,
CHECK_ERROR(undelegate_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.undelegate, action_idx,
outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
case penumbra_core_transaction_v1_ActionPlan_undelegate_claim_tag:
CHECK_ERROR(undelegate_claim_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.undelegate_claim,
action_idx + 1, outKey, outKeyLen, outVal, outValLen, pageIdx,
pageCount))
action_idx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
case penumbra_core_transaction_v1_ActionPlan_delegator_vote_tag:
CHECK_ERROR(delegator_vote_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.delegator_vote,
action_idx + 1, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
action_idx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
case penumbra_core_transaction_v1_ActionPlan_position_open_tag:
CHECK_ERROR(position_open_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.position_open,
action_idx + 1, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
action_idx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
case penumbra_core_transaction_v1_ActionPlan_position_close_tag:
CHECK_ERROR(position_close_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.position_close,
action_idx + 1, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
action_idx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
case penumbra_core_transaction_v1_ActionPlan_position_withdraw_tag:
CHECK_ERROR(position_withdraw_getItem(ctx, &ctx->tx_obj->actions_plan[action_idx].action.position_withdraw,
action_idx + 1, outKey, outKeyLen, outVal, outValLen, pageIdx,
pageCount))
action_idx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
case penumbra_core_transaction_v1_ActionPlan_action_dutch_auction_schedule_tag:
CHECK_ERROR(action_dutch_auction_schedule_getItem(
ctx, &ctx->tx_obj->actions_plan[action_idx].action.action_dutch_auction_schedule, action_idx + 1, outKey,
ctx, &ctx->tx_obj->actions_plan[action_idx].action.action_dutch_auction_schedule, action_idx, outKey,
outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
case penumbra_core_transaction_v1_ActionPlan_action_dutch_auction_end_tag:
CHECK_ERROR(action_dutch_auction_end_getItem(
ctx, &ctx->tx_obj->actions_plan[action_idx].action.action_dutch_auction_end, action_idx + 1, outKey,
ctx, &ctx->tx_obj->actions_plan[action_idx].action.action_dutch_auction_end, action_idx, outKey,
outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
case penumbra_core_transaction_v1_ActionPlan_action_dutch_auction_withdraw_tag:
CHECK_ERROR(action_dutch_auction_withdraw_getItem(
ctx, &ctx->tx_obj->actions_plan[action_idx].action.action_dutch_auction_withdraw, action_idx + 1, outKey,
ctx, &ctx->tx_obj->actions_plan[action_idx].action.action_dutch_auction_withdraw, action_idx, outKey,
outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
default:
Expand Down
Loading

0 comments on commit 5d45452

Please sign in to comment.