-
Notifications
You must be signed in to change notification settings - Fork 2
Extended signing support for Off-chain message signing #8
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
base: compute-budget-rf-v2
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,8 +83,12 @@ | |
| 0x00, 0x00 | ||
|
|
||
| // Sysvars | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove whitespace change |
||
| #define SYSVAR_RENT /* "SysvarRent111111111111111111111111111111111" */ \ | ||
| 0x06, 0xa7, 0xd5, 0x17, 0x19, 0x2c, 0x5c, 0x51, 0x21, 0x8c, 0xc9, 0x4c, 0x3d, 0x4a, 0xf1, \ | ||
| 0x7f, 0x58, 0xda, 0xee, 0x08, 0x9b, 0xa1, 0xfd, 0x44, 0xe3, 0xdb, 0xd9, 0x8a, 0x00, 0x00, \ | ||
| 0x00, 0x00 | ||
|
|
||
| // Domain specifiers | ||
| #define OFFCHAIN_MESSAGE_SIGNING_DOMAIN /* "\xffsolana offchain" */ \ | ||
| 0xff, 0x73, 0x6f, 0x6c, 0x61, 0x6e, 0x61, 0x20, 0x6f, 0x66, 0x66, 0x63, 0x68, 0x61, 0x69, \ | ||
| 0x6e | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #pragma once | ||
| #include <stdint.h> | ||
|
|
||
| #define OFFCHAIN_MESSAGE_SIGNING_DOMAIN_LENGTH 16 | ||
|
|
||
| /** | ||
| * 1. Signing domain (16 bytes) | ||
| * 2. Header version (1 byte) | ||
| * 3. Application domain (32 bytes) | ||
| * 4. Message format (1 byte) | ||
| * 5. Signer count (1 bytes) | ||
| * 6. Signers (signer_count * 32 bytes) - assume that only one signer is present | ||
| * 7. Message length (2 bytes) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you link to the specification? |
||
| */ | ||
| typedef struct OffchainMessageSigningDomain { | ||
| uint8_t data[OFFCHAIN_MESSAGE_SIGNING_DOMAIN_LENGTH]; | ||
| } OffchainMessageSigningDomain; | ||
|
|
||
| extern const OffchainMessageSigningDomain offchain_message_signing_domain; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,16 +59,28 @@ typedef struct MessageHeader { | |
| size_t instructions_length; | ||
| } MessageHeader; | ||
|
|
||
| //@TODO move to offchain message sign .h | ||
|
||
| #define OFFCHAIN_MESSAGE_APPLICATION_DOMAIN_LENGTH 32 | ||
| typedef struct OffchainMessageApplicationDomain { | ||
| uint8_t data[OFFCHAIN_MESSAGE_APPLICATION_DOMAIN_LENGTH]; | ||
| } OffchainMessageApplicationDomain; | ||
|
|
||
| typedef struct OffchainMessageHeader { | ||
| uint8_t version; | ||
| const OffchainMessageApplicationDomain* application_domain; | ||
| uint8_t format; | ||
| size_t signers_length; | ||
| const Pubkey* signers; | ||
| uint16_t length; | ||
| } OffchainMessageHeader; | ||
|
|
||
| static inline int parser_is_empty(Parser* parser) { | ||
| return parser->buffer_length == 0; | ||
| } | ||
|
|
||
| void advance(Parser* parser, size_t num); | ||
| int check_buffer_length(Parser* parser, size_t num); | ||
|
|
||
| int parse_u8(Parser* parser, uint8_t* value); | ||
|
|
||
| int parse_u32(Parser* parser, uint32_t* value); | ||
|
|
@@ -87,13 +99,18 @@ int parse_pubkey(Parser* parser, const Pubkey** pubkey); | |
|
|
||
| int parse_pubkeys_header(Parser* parser, PubkeysHeader* header); | ||
|
|
||
| int parse_pubkeys(Parser* parser, PubkeysHeader* header, const Pubkey** pubkeys); | ||
| int parse_pubkeys(Parser* parser, size_t num_pubkeys, const Pubkey** pubkeys); | ||
|
|
||
| int parse_blockhash(Parser* parser, const Hash** hash); | ||
| #define parse_blockhash parse_hash | ||
|
|
||
| int parse_message_header(Parser* parser, MessageHeader* header); | ||
|
|
||
| int parse_offchain_message_application_domain( | ||
| Parser* parser, | ||
| const OffchainMessageApplicationDomain** app_domain | ||
| ); | ||
|
|
||
| int parse_offchain_message_header(Parser* parser, OffchainMessageHeader* header); | ||
|
|
||
| int parse_instruction(Parser* parser, Instruction* instruction); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #pragma once | ||
| #include <stdint.h> | ||
| #include <string.h> | ||
| #include <stdbool.h> | ||
|
|
||
| bool is_data_utf8(const uint8_t *data, size_t length); | ||
| bool is_data_ascii(const uint8_t *data, size_t length); | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| #include "sol/parser.h" | ||
| #include "sol/printer.h" | ||
| #include "offchain_message_signing.h" | ||
|
|
||
| // TransactionSummary management | ||
| // | ||
|
|
@@ -46,16 +47,24 @@ enum SummaryItemKind { | |
| SummaryItemSizedString, | ||
| SummaryItemString, | ||
| SummaryItemTimestamp, | ||
| SummaryItemOffchainMessageApplicationDomain, | ||
| SummaryItemExtendedString, | ||
| }; | ||
|
|
||
| typedef enum SummaryItemKind SummaryItemKind_t; | ||
|
|
||
| typedef struct SummaryItem SummaryItem; | ||
|
|
||
| extern char G_transaction_summary_title[TITLE_SIZE]; | ||
|
|
||
| // Text buffer needs to be large enough to hold the longest possible message text to sign | ||
| //#define TEXT_BUFFER_LENGTH (OFFCHAIN_MESSAGE_MAXIMUM_MESSAGE_LENGTH - OFFCHAIN_MESSAGE_MINIMAL_HEADER_SIZE) | ||
|
||
| #define TEXT_BUFFER_LENGTH BASE58_PUBKEY_LENGTH | ||
|
|
||
| extern char G_transaction_summary_text[TEXT_BUFFER_LENGTH]; | ||
|
|
||
| extern char* G_transaction_summary_extended_text; | ||
|
|
||
| void transaction_summary_reset(); | ||
| enum DisplayFlags { | ||
| DisplayFlagNone = 0, | ||
|
|
@@ -71,6 +80,12 @@ SummaryItem* transaction_summary_fee_payer_item(); | |
| SummaryItem* transaction_summary_nonce_account_item(); | ||
| SummaryItem* transaction_summary_nonce_authority_item(); | ||
| SummaryItem* transaction_summary_general_item(); | ||
| uint8_t transaction_summary_general_item_count(); | ||
| uint64_t calculate_additional_transaction_fees(); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
@@ -90,4 +105,12 @@ void summary_item_set_pubkey(SummaryItem* item, const char* title, const Pubkey* | |
| void summary_item_set_hash(SummaryItem* item, const char* title, const Hash* value); | ||
| void summary_item_set_sized_string(SummaryItem* item, const char* title, const SizedString* value); | ||
| void summary_item_set_string(SummaryItem* item, const char* title, const char* value); | ||
| void summary_item_safe_set_string(SummaryItem* item, const char* title, const char* value); | ||
| void summary_item_set_timestamp(SummaryItem* item, const char* title, int64_t value); | ||
| void summary_item_set_offchain_message_application_domain( | ||
| SummaryItem* item, | ||
| const char* title, | ||
| const OffchainMessageApplicationDomain* value | ||
| ); | ||
| void summary_item_set_extended_string(SummaryItem* item, const char* title, const char* value); | ||
| void summary_item_safe_set_extended_string(SummaryItem* item, const char* title, const char* value); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #include "sol/offchain_message_signing.h" | ||
| #include "common_byte_strings.h" | ||
|
|
||
| const OffchainMessageSigningDomain offchain_message_signing_domain = | ||
| {{OFFCHAIN_MESSAGE_SIGNING_DOMAIN}}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,12 @@ | ||
| #include "sol/parser.h" | ||
| #include "sol/offchain_message_signing.h" | ||
| #include "util.h" | ||
|
|
||
| #define OFFCHAIN_MESSAGE_SIGNING_DOMAIN \ | ||
| "\xff" \ | ||
| "solana offchain" | ||
|
|
||
| static int check_buffer_length(Parser* parser, size_t num) { | ||
| int check_buffer_length(Parser* parser, size_t num) { | ||
| return parser->buffer_length < num ? 1 : 0; | ||
| } | ||
|
|
||
| static void advance(Parser* parser, size_t num) { | ||
| void advance(Parser* parser, size_t num) { | ||
| parser->buffer += num; | ||
| parser->buffer_length -= num; | ||
| } | ||
|
|
@@ -106,9 +103,8 @@ int parse_pubkeys_header(Parser* parser, PubkeysHeader* header) { | |
| return 0; | ||
| } | ||
|
|
||
| int parse_pubkeys(Parser* parser, PubkeysHeader* header, const Pubkey** pubkeys) { | ||
| BAIL_IF(parse_pubkeys_header(parser, header)); | ||
| size_t pubkeys_size = header->pubkeys_length * PUBKEY_SIZE; | ||
| int parse_pubkeys(Parser* parser, size_t num_pubkeys, const Pubkey** pubkeys) { | ||
| size_t pubkeys_size = num_pubkeys * PUBKEY_SIZE; | ||
| BAIL_IF(check_buffer_length(parser, pubkeys_size)); | ||
| *pubkeys = (const Pubkey*) parser->buffer; | ||
| advance(parser, pubkeys_size); | ||
|
|
@@ -138,24 +134,50 @@ int parse_version(Parser* parser, MessageHeader* header) { | |
|
|
||
| int parse_message_header(Parser* parser, MessageHeader* header) { | ||
| BAIL_IF(parse_version(parser, header)); | ||
| BAIL_IF(parse_pubkeys(parser, &header->pubkeys_header, &header->pubkeys)); | ||
| BAIL_IF(parse_pubkeys_header(parser, &header->pubkeys_header)); | ||
| BAIL_IF(parse_pubkeys(parser, header->pubkeys_header.pubkeys_length, &header->pubkeys)); | ||
| BAIL_IF(parse_blockhash(parser, &header->blockhash)); | ||
| BAIL_IF(parse_length(parser, &header->instructions_length)); | ||
| return 0; | ||
| } | ||
|
|
||
| int parse_offchain_message_application_domain( | ||
| Parser* parser, | ||
| const OffchainMessageApplicationDomain** app_domain | ||
| ) { | ||
| BAIL_IF(check_buffer_length(parser, OFFCHAIN_MESSAGE_APPLICATION_DOMAIN_LENGTH)); | ||
| *app_domain = (const OffchainMessageApplicationDomain*) parser->buffer; | ||
| advance(parser, OFFCHAIN_MESSAGE_APPLICATION_DOMAIN_LENGTH); | ||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * Field Start offset Length (bytes) | ||
| * Signing Domain 0x00 16 | ||
| * Header version 0x10 1 | ||
| * Application domain 0x11 32 | ||
| * Message format 0x31 1 | ||
| * Signer count 0x32 1 | ||
| * Signers 0x33 SIGNER_COUNT * 32 | ||
| * Message length 0x33 + SIGNER_CNT * 32 2 | ||
| */ | ||
|
||
| int parse_offchain_message_header(Parser* parser, OffchainMessageHeader* header) { | ||
| const size_t domain_len = strlen(OFFCHAIN_MESSAGE_SIGNING_DOMAIN); | ||
| const size_t domain_len = OFFCHAIN_MESSAGE_SIGNING_DOMAIN_LENGTH; | ||
| BAIL_IF(check_buffer_length(parser, domain_len)); | ||
| int res; | ||
| if ((res = memcmp(OFFCHAIN_MESSAGE_SIGNING_DOMAIN, parser->buffer, domain_len)) != 0) { | ||
| if ((res = memcmp((const void*)&offchain_message_signing_domain, parser->buffer, domain_len)) != 0) { | ||
| return res; | ||
| } | ||
| advance(parser, domain_len); | ||
|
|
||
| BAIL_IF(parse_u8(parser, &header->version)); | ||
| BAIL_IF(parse_u8(parser, &header->format)); | ||
| BAIL_IF(parse_u16(parser, &header->length)); | ||
| advance(parser, domain_len);//Signing domain - 16 bytes | ||
|
|
||
| BAIL_IF(parse_u8(parser, &header->version));// Header version | ||
| BAIL_IF(parse_offchain_message_application_domain(parser, &header->application_domain)); | ||
| BAIL_IF(parse_u8(parser, &header->format));// Message format | ||
| uint8_t signers_length = 0; | ||
| BAIL_IF(parse_u8(parser, &signers_length));// Signer count | ||
| header->signers_length = signers_length; | ||
| BAIL_IF(parse_pubkeys(parser, header->signers_length, &header->signers)); | ||
| BAIL_IF(parse_u16(parser, &header->length));// Message length | ||
| return 0; | ||
| } | ||
|
|
||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are these changes needed again?