@@ -669,13 +669,11 @@ static bool layoutToken(const CardanoToken *msg, bool is_mint) {
669669 if (0 == index ) {
670670 oledDrawStringAdapter (0 , 13 , _ ("Asset Fingerprint:" ), FONT_STANDARD );
671671 oledDrawStringAdapter (0 , 13 + 10 , fingerprint , FONT_STANDARD );
672- oledDrawStringAdapter (0 , 13 + 30 , _ ("Token Amount:" ), FONT_STANDARD );
673672 oledDrawBitmap (3 * OLED_WIDTH / 4 - 8 , OLED_HEIGHT - 8 ,
674673 & bmp_bottom_middle_arrow_down );
675674 } else {
676- oledDrawStringAdapter (0 , 13 , fingerprint , FONT_STANDARD );
677- oledDrawStringAdapter (0 , 13 + 20 , _ ("Token Amount:" ), FONT_STANDARD );
678- oledDrawStringAdapter (0 , 13 + 30 , amount , FONT_STANDARD );
675+ oledDrawStringAdapter (0 , 13 , _ ("Token Amount:" ), FONT_STANDARD );
676+ oledDrawStringAdapter (0 , 13 + 10 , amount , FONT_STANDARD );
679677 oledDrawBitmap (OLED_WIDTH / 4 , OLED_HEIGHT - 8 ,
680678 & bmp_bottom_middle_arrow_up );
681679 }
@@ -805,8 +803,16 @@ bool txHashBuilder_addOutput(const CardanoTxOutput *output) {
805803 if (!get_address_bytes (output , address_bytes , & address_bytes_len ))
806804 return false;
807805 bool has_datum_hash = output -> has_datum_hash && output -> datum_hash .size > 0 ;
808-
806+ bool has_inline_datum =
807+ output -> has_inline_datum_size && output -> inline_datum_size > 0 ;
808+ bool has_reference_script =
809+ output -> has_reference_script_size && output -> reference_script_size > 0 ;
810+ ada_signer .output_type = output -> format ;
809811 if (output -> format == CardanoTxOutputSerializationFormat_ARRAY_LEGACY ) {
812+ if (has_inline_datum || has_reference_script ) {
813+ fsm_sendFailure (FailureType_Failure_ProcessError , "Invalid output" );
814+ return false;
815+ }
810816 BUILDER_APPEND_CBOR (CBOR_TYPE_ARRAY , output_items_count );
811817
812818 BUILDER_APPEND_CBOR (CBOR_TYPE_BYTES , address_bytes_len );
@@ -845,25 +851,23 @@ bool txHashBuilder_addOutput(const CardanoTxOutput *output) {
845851 BUILDER_APPEND_DATA (address_bytes , address_bytes_len );
846852
847853 BUILDER_APPEND_CBOR (CBOR_TYPE_UNSIGNED , BABBAGE_OUTPUT_KEY_AMOUNT );
848- bool has_inline_datum =
849- output -> has_inline_datum_size && output -> inline_datum_size > 0 ;
850- bool has_reference_script =
851- output -> has_reference_script_size && output -> reference_script_size > 0 ;
854+
852855 if (output -> asset_groups_count == 0 ) {
853856 BUILDER_APPEND_CBOR (CBOR_TYPE_UNSIGNED , output -> amount );
854- if (has_datum_hash || has_inline_datum ) {
857+ if (has_datum_hash ) {
855858 BUILDER_APPEND_CBOR (CBOR_TYPE_UNSIGNED ,
856859 BABBAGE_OUTPUT_KEY_DATUM_OPTION );
857860 BUILDER_APPEND_CBOR (CBOR_TYPE_ARRAY , 2 );
858- }
859- if (has_datum_hash ) {
860861 BUILDER_APPEND_CBOR (CBOR_TYPE_UNSIGNED , BABBAGE_OUTPUT_KEY_DATUM_HASH );
861862 BUILDER_APPEND_CBOR (CBOR_TYPE_BYTES , output -> datum_hash .size );
862863 BUILDER_APPEND_DATA (output -> datum_hash .bytes , output -> datum_hash .size );
863864 ada_signer .datum_hash_size = 0 ;
864865 ada_signer .inline_datum_size = 0 ;
865866 ada_signer .remainingInlineDatumChunksCount = 0 ;
866867 } else if (has_inline_datum ) {
868+ BUILDER_APPEND_CBOR (CBOR_TYPE_UNSIGNED ,
869+ BABBAGE_OUTPUT_KEY_DATUM_OPTION );
870+ BUILDER_APPEND_CBOR (CBOR_TYPE_ARRAY , 2 );
867871 BUILDER_APPEND_CBOR (CBOR_TYPE_UNSIGNED ,
868872 BABBAGE_OUTPUT_KEY_INLINE_DATUM );
869873 BUILDER_APPEND_CBOR (CBOR_TYPE_TAG , CBOR_TAG_EMBEDDED_CBOR_BYTE_STRING );
@@ -879,19 +883,15 @@ bool txHashBuilder_addOutput(const CardanoTxOutput *output) {
879883 ada_signer .datum_hash_size = 0 ;
880884 }
881885 if (has_reference_script ) {
882- if (!has_datum_hash ) {
883- BUILDER_APPEND_CBOR (CBOR_TYPE_UNSIGNED ,
884- BABBAGE_OUTPUT_KEY_REFERENCE_SCRIPT );
885- BUILDER_APPEND_CBOR (CBOR_TYPE_TAG ,
886- CBOR_TAG_EMBEDDED_CBOR_BYTE_STRING );
887- BUILDER_APPEND_CBOR (CBOR_TYPE_BYTES , output -> reference_script_size );
888- ada_signer .outputState = STATE_OUTPUT_REFERENCE_SCRIPT_CHUNKS ;
889- } else {
886+ if (!has_inline_datum ) {
890887 ada_signer .outputState = STATE_OUTPUT_REFERENCE_SCRIPT ;
891888 }
892889 ada_signer .reference_script_size = output -> reference_script_size ;
893890 ada_signer .remainingReferenceScriptChunksCount =
894891 DIV_ROUND_UP (output -> reference_script_size , MAX_CHUNK_SIZE );
892+ } else {
893+ ada_signer .remainingReferenceScriptChunksCount = 0 ;
894+ ada_signer .reference_script_size = 0 ;
895895 }
896896 if (ada_signer .remainingOutputs == 0 && !has_inline_datum &&
897897 !has_reference_script ) {
@@ -1008,19 +1008,27 @@ bool txHashBuilder_addToken(const CardanoToken *msg) {
10081008 if (is_output_state ) {
10091009 if ((ada_signer .remainingOutputAssetTokensCount == 0 ) &&
10101010 (ada_signer .remainingOutputAssetGroupsCount == 0 )) {
1011- if (ada_signer .datum_hash_size > 0 || ada_signer .inline_datum_size > 0 ) {
1012- BUILDER_APPEND_CBOR (CBOR_TYPE_UNSIGNED ,
1013- BABBAGE_OUTPUT_KEY_DATUM_OPTION );
1014- BUILDER_APPEND_CBOR (CBOR_TYPE_ARRAY , 2 );
1015- }
10161011 if (ada_signer .datum_hash_size > 0 ) {
1012+ if (ada_signer .output_type ==
1013+ CardanoTxOutputSerializationFormat_MAP_BABBAGE ) {
1014+ BUILDER_APPEND_CBOR (CBOR_TYPE_UNSIGNED ,
1015+ BABBAGE_OUTPUT_KEY_DATUM_OPTION );
1016+ BUILDER_APPEND_CBOR (CBOR_TYPE_ARRAY , 2 );
1017+ BUILDER_APPEND_CBOR (CBOR_TYPE_UNSIGNED ,
1018+ BABBAGE_OUTPUT_KEY_DATUM_HASH );
1019+ ada_signer .outputState =
1020+ ada_signer .remainingReferenceScriptChunksCount > 0
1021+ ? STATE_OUTPUT_REFERENCE_SCRIPT
1022+ : STATE_OUTPUT_FINISHED ;
1023+ } else {
1024+ ada_signer .outputState = STATE_OUTPUT_FINISHED ;
1025+ }
10171026 BUILDER_APPEND_CBOR (CBOR_TYPE_BYTES , ada_signer .datum_hash_size );
10181027 BUILDER_APPEND_DATA (ada_signer .datum_hash , ada_signer .datum_hash_size );
1019- ada_signer .outputState =
1020- ada_signer .remainingReferenceScriptChunksCount > 0
1021- ? STATE_OUTPUT_REFERENCE_SCRIPT
1022- : STATE_OUTPUT_FINISHED ;
10231028 } else if (ada_signer .inline_datum_size > 0 ) {
1029+ BUILDER_APPEND_CBOR (CBOR_TYPE_UNSIGNED ,
1030+ BABBAGE_OUTPUT_KEY_DATUM_OPTION );
1031+ BUILDER_APPEND_CBOR (CBOR_TYPE_ARRAY , 2 );
10241032 BUILDER_APPEND_CBOR (CBOR_TYPE_UNSIGNED ,
10251033 BABBAGE_OUTPUT_KEY_INLINE_DATUM );
10261034 BUILDER_APPEND_CBOR (CBOR_TYPE_TAG , CBOR_TAG_EMBEDDED_CBOR_BYTE_STRING );
0 commit comments