Skip to content

Commit

Permalink
feat: create structure to add support for EIP159 & CIP64 without brea…
Browse files Browse the repository at this point in the history
…king tests
  • Loading branch information
keiff3r committed Mar 19, 2024
1 parent c6e7b83 commit 2e805ac
Show file tree
Hide file tree
Showing 6 changed files with 367 additions and 141 deletions.
23 changes: 23 additions & 0 deletions apdu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## ISO/IEC 7816-4 (2005) APDU errors (SW1/SW2)

| Error Code | Error Description |
|------------|---------------------------------------------|
| 0x6700 | wrong length (general error) |
| 0x6900 | command not allowed (general error) |
| 0x6981 | command incompatible with file structure |
| 0x6982 | security status not satisfied |
| 0x6A00 | wrong parameters p1/p2 (general error) |
| 0x6A80 | incorrect parameters in command data field |
| 0x6A81 | function not supported |
| 0x6A82 | file or application not found |
| 0x6A83 | record not found |
| 0x6A84 | not enough memory space in the file |
| 0x6A85 | command length inconsistent with TLV structure |
| 0x6A86 | incorrect parameters p1/p2 |
| 0x6A87 | command length inconsistent with p1/p2 |
| 0x6A88 | referenced data or reference data not found |
| 0x6A89 | file already exists |
| 0x6A8A | file name already exists |
|-------------------Personalized status word ---------------|
| 0x6A8B | error while hashing |
| 0x6A8C | error while deriving path |
1 change: 1 addition & 0 deletions doc/ethapp.asc
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ The following standard Status Words are returned for all APDUs - some specific S
[width="80%"]
|===============================================================================================
| *SW* | *Description*
| 6501 | TransactionType not supported
| 6700 | Incorrect length
| 6982 | Security status not satisfied (Canceled by user)
| 6A80 | Invalid data
Expand Down
4 changes: 3 additions & 1 deletion src/celo.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ static uint32_t splitBinaryParameterPart(char *result, uint8_t *parameter) {
}

customStatus_e customProcessor(txContext_t *context) {
if ((context->currentField == TX_RLP_DATA) &&
if (((context->txType == CELO_LEGACY && context->currentField == CELO_LEGACY_RLP_DATA) ||
(context->txType == CIP64 && context->currentField == CIP64_RLP_DATA) ||
(context->txType == EIP1559 && context->currentField == EIP1559_RLP_DATA)) &&
(context->currentFieldLength != 0)) {
dataPresent = true;
// If handling a new contract rather than a function call, abort immediately
Expand Down
21 changes: 17 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,24 @@ void handleSign(uint8_t p1, uint8_t p2, const uint8_t *workBuffer, uint16_t data
appState = APP_STATE_SIGNING_TX;
dataPresent = false;
provisionType = PROVISION_NONE;
//0x8000003c is the Ethereum path
initTx(&txContext, &sha3, &tmpContent.txContent, customProcessor, NULL);
// Extract and validate the transaction type
uint8_t txType = *workBuffer;
if (txType == EIP1559 || txType == CIP64) {
// Initialize the SHA3 hashing with the transaction type
CX_THROW(cx_hash_no_throw((cx_hash_t *) &sha3, 0, workBuffer, 1, NULL, 0));
// Save the transaction type
txContext.txType = txType;
workBuffer++;
dataLength--;
}
else {
txContext.txType = CELO_LEGACY;
}


}
else
if (p1 != P1_MORE) {
else if (p1 != P1_MORE) {
THROW(0x6B00);
}
if (p2 != 0) {
Expand All @@ -319,7 +332,7 @@ void handleSign(uint8_t p1, uint8_t p2, const uint8_t *workBuffer, uint16_t data
PRINTF("Signature not initialized\n");
THROW(0x6985);
}
if (txContext.currentField == TX_RLP_NONE) {
if (txContext.currentField == RLP_NONE) {
PRINTF("Parser not initialized\n");
THROW(0x6985);
}
Expand Down
Loading

0 comments on commit 2e805ac

Please sign in to comment.