Skip to content

Commit d1a99b4

Browse files
committed
Review fixes
1 parent 5bd4e8f commit d1a99b4

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

contracts/c-sphincs-all-in-one-lock/ckb-sphincsplus-root-lock.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ static int write_to_blake2b(const uint8_t *data, size_t length, void *context) {
115115
int fetch_params(uint8_t id, const CkbSphincsParams **params) {
116116
int err = CKB_SUCCESS;
117117
uint8_t index = MULTISIG_PARAM_ID_TO_INDEX(id);
118-
CHECK2(index >= 0 && index < CKB_SPHINCS_SUPPORTED_PARAMS_COUNT,
119-
ERROR_SPHINCSPLUS_WITNESS);
118+
CHECK2(index < CKB_SPHINCS_SUPPORTED_PARAMS_COUNT, ERROR_SPHINCSPLUS_WITNESS);
120119
*params = &ckb_sphincs_supported_params[index];
121120

122121
exit:

contracts/c-sphincs-all-in-one-lock/ckb-sphincsplus.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum SphincsPlusError {
2525
SphincsPlusError_Params = 200,
2626
SphincsPlusError_Verify,
2727
SphincsPlusError_OutputSignLength,
28+
SphincsPlusError_SignSignature,
2829
};
2930

3031
#ifndef CKB_VM
@@ -47,12 +48,12 @@ int sphincs_plus_sign(const uint8_t *message, uint32_t message_size,
4748
int ret =
4849
crypto_sign_signature(out_sign, &out_sign_len, message, message_size, sk);
4950
if (ret != 0) {
50-
return ret;
51+
return SphincsPlusError_SignSignature;
5152
}
5253
if ((uint32_t)out_sign_len != SPHINCS_PLUS_SIGN_SIZE) {
5354
return SphincsPlusError_OutputSignLength;
5455
}
55-
return ret;
56+
return 0;
5657
}
5758

5859
/* Defined for Rust FFI usage, script code would only require the macros */

contracts/c-sphincs-all-in-one-lock/nist-vector-tester.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
int fetch_params(uint8_t id, const CkbSphincsParams **params) {
4242
int err = CKB_SUCCESS;
4343
uint8_t index = MULTISIG_PARAM_ID_TO_INDEX(id);
44-
CHECK2(index >= 0 && index < CKB_SPHINCS_SUPPORTED_PARAMS_COUNT,
45-
ERROR_SPHINCSPLUS_WITNESS);
44+
CHECK2(index < CKB_SPHINCS_SUPPORTED_PARAMS_COUNT, ERROR_SPHINCSPLUS_WITNESS);
4645
*params = &ckb_sphincs_supported_params[index];
4746

4847
exit:

contracts/c-sphincs-all-in-one-lock/utils/zero_escape_encoding.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifndef CKB_ZERO_ESCAPE_ENCODING_H_
22
#define CKB_ZERO_ESCAPE_ENCODING_H_
33

4+
#ifndef CKB_ZERO_ESCAPE_ERROR_CODE
5+
#define CKB_ZERO_ESCAPE_ERROR_CODE 90
6+
#endif
7+
48
/*
59
* A simple escape encoder that:
610
*
@@ -26,19 +30,19 @@ int zero_escape_encode(const uint8_t *src, size_t src_length, uint8_t *dst,
2630
for (size_t i = 0; i < src_length; i++) {
2731
if (src[i] == '\0' || src[i] == (uint8_t)'\xFE') {
2832
if (wrote + 2 > limit) {
29-
return 90;
33+
return CKB_ZERO_ESCAPE_ERROR_CODE;
3034
}
3135
dst[wrote++] = '\xFE';
3236
dst[wrote++] = src[i] - 1;
3337
} else {
3438
if (wrote + 1 > limit) {
35-
return 90;
39+
return CKB_ZERO_ESCAPE_ERROR_CODE;
3640
}
3741
dst[wrote++] = src[i];
3842
}
3943
}
4044
if (wrote + 1 > limit) {
41-
return 90;
45+
return CKB_ZERO_ESCAPE_ERROR_CODE;
4246
}
4347
dst[wrote++] = '\0';
4448

@@ -53,7 +57,7 @@ int zero_escape_decode_in_place(uint8_t *buffer, size_t *length) {
5357
for (size_t i = 0; i < limit;) {
5458
if (buffer[i] == (uint8_t)'\xFE') {
5559
if (i + 1 >= limit) {
56-
return 90;
60+
return CKB_ZERO_ESCAPE_ERROR_CODE;
5761
}
5862
buffer[wrote++] = buffer[i + 1] + 1;
5963

0 commit comments

Comments
 (0)