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

Fix/ldg 677 configurebaker boolean flag #65

Merged
merged 7 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .github/workflows/python_client_checks.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ APPNAME = "Concordium"
# Application version
APPVERSION_M = 5
APPVERSION_N = 0
APPVERSION_P = 0
APPVERSION_P = 1
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"

DEFINES += APPVERSION=\"$(APPVERSION)\"
Expand Down
1 change: 1 addition & 0 deletions src/common/ui/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern const ux_flow_step_t *ux_sign_configure_baker_commission[9];

void startConfigureBakerCommissionDisplay(void);
void startConfigureBakerUrlDisplay(bool lastUrlPage);
void startConfigureBakerSuspendedDisplay(void);
void startConfigureBakerDisplay(void);

void startConfigureDelegationDisplay();
Expand Down
38 changes: 36 additions & 2 deletions src/common/ui/display_bagl.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ static signConfigureBaker_t *ctx_conf_baker = &global.signConfigureBaker;
const ux_flow_step_t *ux_sign_configure_baker_first[8];
const ux_flow_step_t *ux_sign_configure_baker_url[6];
const ux_flow_step_t *ux_sign_configure_baker_commission[9];
const ux_flow_step_t *ux_sign_configure_baker_suspended[6];

UX_STEP_NOCB(ux_sign_configure_baker_stop_baking_step, nn, {"Stop", "baking"});

Expand Down Expand Up @@ -171,6 +172,10 @@ UX_STEP_NOCB(ux_sign_configure_baker_commission_finalization_reward_step,
{"Finalization reward",
(char *)global.signConfigureBaker.commissionRates.finalizationRewardCommissionRate});

UX_STEP_NOCB(ux_sign_configure_baker_suspended_step,
bn,
{"Validator status", (char *)global.signConfigureBaker.suspended});

/**
* Dynamically builds and initializes the capital, restake earnings, pool status and
* baker keys display.
Expand Down Expand Up @@ -302,13 +307,42 @@ void startConfigureBakerCommissionDisplay() {
&ux_sign_configure_baker_commission_finalization_reward_step;
}

ux_sign_configure_baker_commission[index++] = &ux_sign_flow_shared_sign;
ux_sign_configure_baker_commission[index++] = &ux_sign_flow_shared_decline;
if (ctx_conf_baker->hasSuspended) {
ux_sign_configure_baker_commission[index++] = &ux_sign_configure_baker_continue;
} else {
ux_sign_configure_baker_commission[index++] = &ux_sign_flow_shared_sign;
ux_sign_configure_baker_commission[index++] = &ux_sign_flow_shared_decline;
}

ux_sign_configure_baker_commission[index++] = FLOW_END_STEP;
ux_flow_init(0, ux_sign_configure_baker_commission, NULL);
}

/**
* Dynamically builds and initializes the suspended display.
* - If the transaction only contains suspended boolean, then it ensures that
* the UI starts with the shared review transaction screens.
* - Only shows the suspended message that have been indicated to be part of the transaction.
* - Shows the signing / decline screens.
*/
void startConfigureBakerSuspendedDisplay() {
uint8_t index = 0;

if (ctx_conf_baker->firstDisplay) {
ux_sign_configure_baker_suspended[index++] = &ux_sign_flow_shared_review;
ux_sign_configure_baker_suspended[index++] = &ux_sign_flow_account_sender_view;
ctx_conf_baker->firstDisplay = false;
}

ux_sign_configure_baker_suspended[index++] = &ux_sign_configure_baker_suspended_step;

ux_sign_configure_baker_suspended[index++] = &ux_sign_flow_shared_sign;
ux_sign_configure_baker_suspended[index++] = &ux_sign_flow_shared_decline;

ux_sign_configure_baker_suspended[index++] = FLOW_END_STEP;
ux_flow_init(0, ux_sign_configure_baker_suspended, NULL);
}

// Delegation

static signConfigureDelegationContext_t *ctx_conf_delegation = &global.signConfigureDelegation;
Expand Down
52 changes: 50 additions & 2 deletions src/common/ui/display_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,61 @@ void startConfigureBakerCommissionDisplay(void) {
content.nbMaxLinesForValue = 0;
content.startIndex = 0;

// Setup the review screen
// to signing screens.
if (ctx->hasSuspended) {
// Setup the review screen
nbgl_useCaseReviewLight(TYPE_OPERATION,
&content,
&C_app_concordium_64px,
"Review Transaction",
NULL, // No subtitle
"Continue with transaction",
sendSuccessNoIdleCallback);
} else {
// Setup the review screen
nbgl_useCaseReview(TYPE_TRANSACTION,
&content,
&C_app_concordium_64px,
"Review Transaction",
NULL, // No subtitle
"Sign transaction",
review_choice_sign);
}
}

void startConfigureBakerSuspendedDisplay(void) {
// Get context from global state
signConfigureBaker_t *ctx = &global.signConfigureBaker;
// Create tag-value pairs for the content
uint8_t pairIndex = 0;

if (ctx->firstDisplay) {
// Add sender address
pairs[pairIndex].item = "Sender";
pairs[pairIndex].value = (char *)global_account_sender.sender;
pairIndex++;
ctx->firstDisplay = false;
}

pairs[pairIndex].item = "Validator status";
pairs[pairIndex].value = (char *)global.signConfigureBaker.suspended;
pairIndex++;

// Create the page content
nbgl_contentTagValueList_t content;
content.nbPairs = pairIndex;
content.pairs = pairs;
content.smallCaseForValue = false;
content.nbMaxLinesForValue = 0;
content.startIndex = 0;

// to signing screens.
nbgl_useCaseReview(TYPE_TRANSACTION,
&content,
&C_app_concordium_64px,
"Review Transaction",
NULL, // No subtitle
"Sign Transaction",
"Sign transaction",
review_choice_sign);
}

Expand Down
46 changes: 40 additions & 6 deletions src/signConfigureBaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bool hasCommissionRate() {
#define P1_URL_LENGTH 0x03
#define P1_URL 0x04
#define P1_COMMISSION_RATES 0x05
#define P1_SUSPENDED 0x06

void handleCommissionRates(uint8_t *cdata, uint8_t dataLength) {
if (ctx_conf_baker->hasTransactionFeeCommission) {
Expand Down Expand Up @@ -49,8 +50,13 @@ void handleCommissionRates(uint8_t *cdata, uint8_t dataLength) {
dataLength -= 4;
}

if (dataLength != 0) {
THROW(ERROR_INVALID_TRANSACTION);
if (ctx_conf_baker->hasSuspended) {
ctx_conf_baker->state = CONFIGURE_BAKER_SUSPENDED;
} else {
if (dataLength != 0) {
THROW(ERROR_INVALID_TRANSACTION);
}
ctx_conf_baker->state = CONFIGURE_BAKER_END;
}

startConfigureBakerCommissionDisplay();
Expand All @@ -71,10 +77,9 @@ void handleSignConfigureBaker(uint8_t *cdata,
updateHash((cx_hash_t *)&tx_state->hash, cdata, 2);
uint16_t bitmap = U2BE(cdata, 0);

// An empty transaction with none of the optionals available is invalid,
// or any transaction with a bit set after the 10th bits place (as there are 10
// optionals).
if (bitmap == 0 || bitmap > 1023) {
// A transaction with a bit set after the 9th bits place (as there are 9
// optionals) is invalid.
if (bitmap > 511) {
THROW(ERROR_INVALID_TRANSACTION);
}

Expand All @@ -86,6 +91,7 @@ void handleSignConfigureBaker(uint8_t *cdata,
ctx_conf_baker->hasTransactionFeeCommission = (bitmap >> 5) & 1;
ctx_conf_baker->hasBakingRewardCommission = (bitmap >> 6) & 1;
ctx_conf_baker->hasFinalizationRewardCommission = (bitmap >> 7) & 1;
ctx_conf_baker->hasSuspended = (bitmap >> 8) & 1;

if (ctx_conf_baker->hasCapital || ctx_conf_baker->hasRestakeEarnings ||
ctx_conf_baker->hasOpenForDelegation || ctx_conf_baker->hasKeys) {
Expand All @@ -94,6 +100,8 @@ void handleSignConfigureBaker(uint8_t *cdata,
ctx_conf_baker->state = CONFIGURE_BAKER_URL_LENGTH;
} else if (hasCommissionRate()) {
ctx_conf_baker->state = CONFIGURE_BAKER_COMMISSION_RATES;
} else if (ctx_conf_baker->hasSuspended) {
ctx_conf_baker->state = CONFIGURE_BAKER_SUSPENDED;
}

sendSuccessNoIdle();
Expand Down Expand Up @@ -189,6 +197,8 @@ void handleSignConfigureBaker(uint8_t *cdata,
ctx_conf_baker->state = CONFIGURE_BAKER_URL_LENGTH;
} else if (hasCommissionRate()) {
ctx_conf_baker->state = CONFIGURE_BAKER_COMMISSION_RATES;
} else if (ctx_conf_baker->hasSuspended) {
ctx_conf_baker->state = CONFIGURE_BAKER_SUSPENDED;
} else {
ctx_conf_baker->state = CONFIGURE_BAKER_END;
}
Expand All @@ -213,6 +223,8 @@ void handleSignConfigureBaker(uint8_t *cdata,
ctx_conf_baker->state = CONFIGURE_BAKER_URL_LENGTH;
} else if (hasCommissionRate()) {
ctx_conf_baker->state = CONFIGURE_BAKER_COMMISSION_RATES;
} else if (ctx_conf_baker->hasSuspended) {
ctx_conf_baker->state = CONFIGURE_BAKER_SUSPENDED;
} else {
ctx_conf_baker->state = CONFIGURE_BAKER_END;
}
Expand All @@ -235,6 +247,8 @@ void handleSignConfigureBaker(uint8_t *cdata,
// If the url has length zero, we don't wait for the url bytes.
if (hasCommissionRate()) {
ctx_conf_baker->state = CONFIGURE_BAKER_COMMISSION_RATES;
} else if (ctx_conf_baker->hasSuspended) {
ctx_conf_baker->state = CONFIGURE_BAKER_SUSPENDED;
} else {
ctx_conf_baker->state = CONFIGURE_BAKER_END;
}
Expand All @@ -259,6 +273,8 @@ void handleSignConfigureBaker(uint8_t *cdata,

if (hasCommissionRate()) {
ctx_conf_baker->state = CONFIGURE_BAKER_COMMISSION_RATES;
} else if (ctx_conf_baker->hasSuspended) {
ctx_conf_baker->state = CONFIGURE_BAKER_SUSPENDED;
} else {
ctx_conf_baker->state = CONFIGURE_BAKER_END;
}
Expand All @@ -272,6 +288,24 @@ void handleSignConfigureBaker(uint8_t *cdata,
ctx_conf_baker->state == CONFIGURE_BAKER_COMMISSION_RATES) {
handleCommissionRates(cdata, dataLength);
*flags |= IO_ASYNCH_REPLY;
} else if (P1_SUSPENDED == p1 && ctx_conf_baker->state == CONFIGURE_BAKER_SUSPENDED) {
uint8_t suspended = cdata[0];
updateHash((cx_hash_t *)&tx_state->hash, cdata, 1);
dataLength -= 1;

if (dataLength != 0) {
THROW(ERROR_INVALID_TRANSACTION);
}

if (suspended == 0) {
memmove(ctx_conf_baker->suspended, "Resume validator", 17);
} else if (suspended == 1) {
memmove(ctx_conf_baker->suspended, "Suspend validator", 18);
} else {
THROW(ERROR_INVALID_TRANSACTION);
}
startConfigureBakerSuspendedDisplay();
*flags |= IO_ASYNCH_REPLY;
} else {
THROW(ERROR_INVALID_STATE);
}
Expand Down
5 changes: 4 additions & 1 deletion src/signConfigureBaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ typedef enum {
CONFIGURE_BAKER_URL_LENGTH = 63,
CONFIGURE_BAKER_URL = 64,
CONFIGURE_BAKER_COMMISSION_RATES = 65,
CONFIGURE_BAKER_END = 66
CONFIGURE_BAKER_SUSPENDED = 66,
CONFIGURE_BAKER_END = 67
} configureBakerState_t;

typedef struct {
Expand Down Expand Up @@ -48,12 +49,14 @@ typedef struct {
bool hasTransactionFeeCommission;
bool hasBakingRewardCommission;
bool hasFinalizationRewardCommission;
bool hasSuspended;
bool firstDisplay;

union {
configureBakerCapitalRestakeOpenForDelegationBlob_t capitalRestakeDelegation;
configureBakerUrl_t url;
configureBakerCommisionRates_t commissionRates;
uint8_t suspended[18];
};

configureBakerState_t state;
Expand Down
26 changes: 26 additions & 0 deletions tests/application_client/boilerplate_command_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,32 @@ def sign_configure_baker_commission_rate(
) as response:
yield response

@contextmanager
def sign_configure_baker_suspended(
self,
bitmap: bytes,
suspended: bool = False,
is_called_first: bool = True,
) -> Generator[None, None, None]:
serialized_suspended_status = b""

if is_called_first:
self._configure_baker_part_0(bitmap)

if suspended:
serialized_suspended_status += bytes.fromhex("01")
else:
serialized_suspended_status += bytes.fromhex("00")

with self.backend.exchange_async(
cla=CLA,
ins=InsType.CONFIGURE_BAKER,
p1=0x06, # Special P1 value for commission rates
p2=P2.P2_NONE,
data=serialized_suspended_status,
) as response:
yield response

def _configure_baker_part_0(
self,
bitmap: bytes,
Expand Down
Binary file modified tests/snapshots/flex/test_app_mainmenu/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 not shown.
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.
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/snapshots/nanosp/test_app_mainmenu/00001.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.
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 modified tests/snapshots/nanox/test_app_mainmenu/00001.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.
Binary file modified tests/snapshots/stax/test_app_mainmenu/00001.png
Diff not rendered.
Loading
Loading