@@ -45,6 +45,9 @@ library DCAPValidator {
45
45
46
46
/**
47
47
* @notice The output of the quote verification
48
+ * @dev This struct corresponds to `QuoteVerificationOutput` in the dcap-quote-verifier library.
49
+ * Note that some fields from the original output are omitted or parsed in greater detail in Solidity for our use case.
50
+ * ref. https://github.com/datachainlab/zkdcap/blob/9616d7976a84e97a128fa02175ec994b95e3c137/crates/quote-verifier/src/verifier.rs#L19
48
51
*/
49
52
struct Output {
50
53
string tcbStatus;
@@ -91,20 +94,23 @@ library DCAPValidator {
91
94
* @return The string representation of the TCB status
92
95
*/
93
96
function tcbStatusToString (uint8 tcbStatus ) internal pure returns (string memory ) {
97
+ // The if-else chain is ordered based on the expected frequency of allowed TCB statuses
98
+ // (most common statuses first), rather than the order of the enum definition.
99
+ // This ordering may result in minor gas savings by reducing the average number of comparisons in common cases.
94
100
if (tcbStatus == TCB_STATUS_UP_TO_DATE) {
95
101
return TCB_STATUS_UP_TO_DATE_STRING;
96
- } else if (tcbStatus == TCB_STATUS_OUT_OF_DATE) {
97
- return TCB_STATUS_OUT_OF_DATE_STRING;
98
- } else if (tcbStatus == TCB_STATUS_REVOKED) {
99
- return TCB_STATUS_REVOKED_STRING;
100
- } else if (tcbStatus == TCB_STATUS_CONFIGURATION_NEEDED) {
101
- return TCB_STATUS_CONFIGURATION_NEEDED_STRING;
102
- } else if (tcbStatus == TCB_STATUS_OUT_OF_DATE_CONFIGURATION_NEEDED) {
103
- return TCB_STATUS_OUT_OF_DATE_CONFIGURATION_NEEDED_STRING;
104
102
} else if (tcbStatus == TCB_STATUS_SW_HARDENING_NEEDED) {
105
103
return TCB_STATUS_SW_HARDENING_NEEDED_STRING;
104
+ } else if (tcbStatus == TCB_STATUS_CONFIGURATION_NEEDED) {
105
+ return TCB_STATUS_CONFIGURATION_NEEDED_STRING;
106
106
} else if (tcbStatus == TCB_STATUS_CONFIGURATION_AND_SW_HARDENING_NEEDED) {
107
107
return TCB_STATUS_CONFIGURATION_AND_SW_HARDENING_NEEDED_STRING;
108
+ } else if (tcbStatus == TCB_STATUS_OUT_OF_DATE_CONFIGURATION_NEEDED) {
109
+ return TCB_STATUS_OUT_OF_DATE_CONFIGURATION_NEEDED_STRING;
110
+ } else if (tcbStatus == TCB_STATUS_OUT_OF_DATE) {
111
+ return TCB_STATUS_OUT_OF_DATE_STRING;
112
+ } else if (tcbStatus == TCB_STATUS_REVOKED) {
113
+ return TCB_STATUS_REVOKED_STRING;
108
114
} else {
109
115
revert ("unexpected TCB status " );
110
116
}
0 commit comments