Skip to content

Commit 85a700a

Browse files
committed
Change param IDs to 48 - 59, change leaf response to 3 bytes
Those changes make our SPHINCS+ quantum resistant lock compatible with a multisig design for any possible digital signature algorithms.
1 parent 83f4744 commit 85a700a

File tree

18 files changed

+242
-236
lines changed

18 files changed

+242
-236
lines changed

contracts/c-sphincs-all-in-one-lock/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ $(CUR_BUILD)/leaf.complete: $(DETECTING_SOURCES) $(HEADERS) ckb-sphincsplus-leaf
110110
@set -eu; \
111111
param_ids=$$(cat $(CUR_BUILD)/params.txt | cut -d" " -f1); \
112112
for param_id in $${param_ids}; do \
113-
param=$$(head -n $${param_id} $(CUR_BUILD)/params.txt | tail -1 | cut -d" " -f2); \
113+
param=$$(grep ^$${param_id} $(CUR_BUILD)/params.txt | head -1 | cut -d" " -f2); \
114114
if echo "$${param}" | grep "shake" - > /dev/null; then \
115115
srcs="$(COMPILING_COMMON_SOURCES) $(COMPILING_SHAKE_SOURCES)"; \
116116
elif echo "$${param}" | grep "sha2" - > /dev/null; then \
@@ -138,7 +138,7 @@ $(CUR_BUILD)/aggregated-params.h: tools/extract-sphincs-params.c $(HEADERS) $(CU
138138
@set -eu; \
139139
param_ids=$$(cat $(CUR_BUILD)/params.txt | cut -d" " -f1); \
140140
for param_id in $${param_ids}; do \
141-
param=$$(head -n $${param_id} $(CUR_BUILD)/params.txt | tail -1 | cut -d" " -f2); \
141+
param=$$(grep ^$${param_id} $(CUR_BUILD)/params.txt | head -1 | cut -d" " -f2); \
142142
set -x; \
143143
$(CLANG) -g -O3 $< -o $(CUR_BUILD)/extract-params_$${param} \
144144
-DPARAMS_ID=$${param_id} -DPARAMS=$${param} \

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
#define SCRIPT_SIZE ONE_BATCH_SIZE
1212

1313
#define MULTISIG_RESERVED_FIELD_VALUE 0x80
14-
#define MULTISIG_PARAMS_ID_MASK 0x7F
15-
#define MULTISIG_SIG_MASK (1 << 7)
14+
#define MULTISIG_HAS_SIGNATURE(flag) ((flag & 1) != 0)
15+
#define MULTISIG_SIGN_FLAG(flag) (flag & 0xFE)
16+
#define MULTISIG_FLAG_TO_PARAM_ID(flag) (flag >> 1)
17+
#define MULTISIG_PARAM_ID_TO_INDEX(id) (id - CKB_SPHINCS_MIN_PARAM_ID)
18+
#define MULTISIG_FLAG_TO_PARAM_INDEX(flag) \
19+
MULTISIG_PARAM_ID_TO_INDEX(MULTISIG_FLAG_TO_PARAM_ID(flag))
1620

1721
#ifndef MOL2_EXIT
1822
#define MOL2_EXIT ckb_exit

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ int verify(const uint8_t *message, size_t message_length,
4141
int err = CKB_SUCCESS;
4242

4343
while (data_cursor.size > 0) {
44-
uint8_t param_id;
45-
CHECK(mol2_read_and_advance(&data_cursor, &param_id, 1));
44+
uint8_t flag;
45+
CHECK(mol2_read_and_advance(&data_cursor, &flag, 1));
4646

47-
CHECK2((param_id & MULTISIG_PARAMS_ID_MASK) == PARAMS_ID,
47+
CHECK2(MULTISIG_FLAG_TO_PARAM_ID(flag) == PARAMS_ID,
4848
ERROR_SPHINCSPLUS_PARAMS);
4949

50-
if ((param_id & MULTISIG_SIG_MASK) != 0) {
50+
if (MULTISIG_HAS_SIGNATURE(flag)) {
5151
/* Validate a signature when we see one */
5252
CHECK2(data_cursor.size >= SPHINCS_PLUS_PK_SIZE + SPHINCS_PLUS_SIGN_SIZE,
5353
ERROR_SPHINCSPLUS_WITNESS);
@@ -174,14 +174,14 @@ int handle_spawn(const uint8_t *command, size_t command_length) {
174174
* 2. Both fds are closed
175175
* 3. Current script terminates with non-zero exit code
176176
*/
177-
uint8_t failure_response = 1;
178-
CHECK(_write_all(leaf_to_root_fd, &failure_response, 1));
177+
uint8_t failure_response[3] = {0, 1, 0};
178+
CHECK(_write_all(leaf_to_root_fd, failure_response, 3));
179179
CHECK(ckb_close(root_to_leaf_fd));
180180
CHECK(ckb_close(leaf_to_root_fd));
181181
return verify_err;
182182
} else {
183-
uint8_t success_response = 0;
184-
CHECK(_write_all(leaf_to_root_fd, &success_response, 1));
183+
uint8_t success_response[3] = {0, 0, 0};
184+
CHECK(_write_all(leaf_to_root_fd, success_response, 3));
185185
}
186186
}
187187

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

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@ static int write_to_blake2b(const uint8_t *data, size_t length, void *context) {
109109

110110
int fetch_params(uint8_t id, const CkbSphincsParams **params) {
111111
int err = CKB_SUCCESS;
112-
id &= MULTISIG_PARAMS_ID_MASK;
113-
/* id uses offset by 1 */
114-
CHECK2(id >= 1 && id <= CKB_SPHINCS_SUPPORTED_PARAMS_COUNT,
112+
uint8_t index = MULTISIG_PARAM_ID_TO_INDEX(id);
113+
CHECK2(index >= 0 && index < CKB_SPHINCS_SUPPORTED_PARAMS_COUNT,
115114
ERROR_SPHINCSPLUS_WITNESS);
116-
*params = &ckb_sphincs_supported_params[id - 1];
115+
*params = &ckb_sphincs_supported_params[index];
117116

118117
exit:
119118
return err;
@@ -160,10 +159,11 @@ int multisig_preliminary_check(WitnessArgsType *witness_args,
160159
int last_param_id = 0;
161160

162161
for (uint8_t i = 0; i < pubkeys; i++) {
163-
uint8_t id;
164-
CHECK(mol2_read_and_advance(&lock_bytes, &id, 1));
165-
uint8_t param_id = id & MULTISIG_PARAMS_ID_MASK;
166-
blake2b_update(&s, &param_id, 1);
162+
uint8_t flag;
163+
CHECK(mol2_read_and_advance(&lock_bytes, &flag, 1));
164+
uint8_t param_id = MULTISIG_FLAG_TO_PARAM_ID(flag);
165+
uint8_t sign_flag = MULTISIG_SIGN_FLAG(flag);
166+
blake2b_update(&s, &sign_flag, 1);
167167

168168
const CkbSphincsParams *params = NULL;
169169
CHECK(fetch_params(param_id, &params));
@@ -172,7 +172,7 @@ int multisig_preliminary_check(WitnessArgsType *witness_args,
172172
CHECK(mol2_read_and_advance(&lock_bytes, pubkey, params->pk_bytes));
173173
blake2b_update(&s, pubkey, params->pk_bytes);
174174

175-
if ((id & MULTISIG_SIG_MASK) != 0) {
175+
if (MULTISIG_HAS_SIGNATURE(flag)) {
176176
mol2_advance(&lock_bytes, params->sign_bytes);
177177

178178
CHECK2(threshold > 0, ERROR_SPHINCSPLUS_WITNESS);
@@ -288,27 +288,28 @@ int main(int argc, char *argv[]) {
288288
* Iterate over lock data again to verify each signature.
289289
*/
290290
while (signatures.size > 0) {
291-
uint8_t header;
292-
CHECK(mol2_read_and_advance(&signatures, &header, 1));
291+
uint8_t flag;
292+
CHECK(mol2_read_and_advance(&signatures, &flag, 1));
293293

294-
uint8_t param_id = header & MULTISIG_PARAMS_ID_MASK;
295-
if (all_params[param_id] == NULL) {
296-
CHECK(fetch_params(param_id, &all_params[param_id]));
294+
uint8_t param_index = MULTISIG_FLAG_TO_PARAM_INDEX(flag);
295+
if (all_params[param_index] == NULL) {
296+
CHECK(fetch_params(MULTISIG_FLAG_TO_PARAM_ID(flag),
297+
&all_params[param_index]));
297298
}
298-
uint32_t pk_size = all_params[param_id]->pk_bytes;
299-
uint32_t sign_size = all_params[param_id]->sign_bytes;
299+
uint32_t pk_size = all_params[param_index]->pk_bytes;
300+
uint32_t sign_size = all_params[param_index]->sign_bytes;
300301
CHECK2(pk_size + sign_size + 1 == (size_t)pk_size + (size_t)sign_size + 1,
301302
ERROR_SPHINCSPLUS_WITNESS;);
302303

303-
if ((header & MULTISIG_SIG_MASK) != 0) {
304+
if (MULTISIG_HAS_SIGNATURE(flag)) {
304305
/*
305306
* Spawns a leaf process if needed, and use it to validate
306307
* the signature
307308
*/
308309
CHECK2(signatures.size >= pk_size + sign_size,
309310
ERROR_SPHINCSPLUS_WITNESS);
310311
/* Spawn a new proces if needed */
311-
if (spawned_processes[param_id] == 0) {
312+
if (spawned_processes[param_index] == 0) {
312313
uint64_t root_to_leaf_fds[2];
313314
CHECK(ckb_pipe(root_to_leaf_fds));
314315
uint64_t leaf_to_root_fds[2];
@@ -320,17 +321,18 @@ int main(int argc, char *argv[]) {
320321
*/
321322
uint64_t inherited_fds[3] = {root_to_leaf_fds[0], leaf_to_root_fds[1],
322323
0};
323-
fds[param_id][0] = root_to_leaf_fds[1];
324-
fds[param_id][1] = leaf_to_root_fds[0];
324+
fds[param_index][0] = root_to_leaf_fds[1];
325+
fds[param_index][1] = leaf_to_root_fds[0];
325326

326327
const char *argv[] = {(const char *)escaped};
327-
spawn_args_t spawn_args = {.argc = 1,
328-
.argv = (const char **)argv,
329-
.process_id = &spawned_processes[param_id],
330-
.inherited_fds = inherited_fds};
331-
CHECK(ckb_spawn_cell(code_hash, hash_type,
332-
*all_params[param_id]->offset_ptr,
333-
*all_params[param_id]->length_ptr, &spawn_args));
328+
spawn_args_t spawn_args = {
329+
.argc = 1,
330+
.argv = (const char **)argv,
331+
.process_id = &spawned_processes[param_index],
332+
.inherited_fds = inherited_fds};
333+
CHECK(ckb_spawn_cell(
334+
code_hash, hash_type, *all_params[param_index]->offset_ptr,
335+
*all_params[param_index]->length_ptr, &spawn_args));
334336
}
335337
/* Sends data location to the leaf process */
336338
{
@@ -344,13 +346,14 @@ int main(int argc, char *argv[]) {
344346
*((uint32_t *)&data[3 + 8 + 4]) = signatures.offset - 1;
345347
*((uint32_t *)&data[3 + 8 + 4 + 4]) = 1 + pk_size + sign_size;
346348

347-
CHECK(_write_all(fds[param_id][0], data, sizeof(data)));
349+
CHECK(_write_all(fds[param_index][0], data, sizeof(data)));
348350
}
349351
/* Waits for leaf process to respond */
350352
{
351-
uint8_t response;
352-
CHECK(_read_all(fds[param_id][1], &response, 1));
353-
CHECK2(response == 0, ERROR_SPHINCSPLUS_LEAF_VERIFY);
353+
uint8_t response[3];
354+
CHECK(_read_all(fds[param_index][1], response, 3));
355+
CHECK2(response[0] == 0 && response[1] == 0 && response[2] == 0,
356+
ERROR_SPHINCSPLUS_LEAF_VERIFY);
354357
}
355358
/* Advance to the next signature if all the above succeeds */
356359
mol2_advance(&signatures, pk_size + sign_size);

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@
4040

4141
int fetch_params(uint8_t id, const CkbSphincsParams **params) {
4242
int err = CKB_SUCCESS;
43-
id &= MULTISIG_PARAMS_ID_MASK;
44-
/* id uses offset by 1 */
45-
CHECK2(id >= 1 && id <= CKB_SPHINCS_SUPPORTED_PARAMS_COUNT,
43+
uint8_t index = MULTISIG_PARAM_ID_TO_INDEX(id);
44+
CHECK2(index >= 0 && index < CKB_SPHINCS_SUPPORTED_PARAMS_COUNT,
4645
ERROR_SPHINCSPLUS_WITNESS);
47-
*params = &ckb_sphincs_supported_params[id - 1];
46+
*params = &ckb_sphincs_supported_params[index];
4847

4948
exit:
5049
return err;
@@ -89,8 +88,8 @@ int main() {
8988
ERROR_SPHINCSPLUS_ENCODING);
9089

9190
const CkbSphincsParams *params = NULL;
92-
CHECK(
93-
fetch_params(second_witness_data[0] & MULTISIG_PARAMS_ID_MASK, &params));
91+
uint8_t param_id = MULTISIG_FLAG_TO_PARAM_ID(second_witness_data[0]);
92+
CHECK(fetch_params(param_id, &params));
9493

9594
uint8_t script_data[MAX_SCRIPT_SIZE];
9695
size_t script_len = MAX_SCRIPT_SIZE;

contracts/hybrid-sphincs-all-in-one-lock/src/generated/params.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,35 @@ pub const PARAM_IDS_COUNT: usize = 12;
66

77
pub fn lengths(param_id: ParamId) -> (usize, usize) {
88
match param_id {
9-
ParamId::Sha2128F => (CKB_SPHINCS_PARAM1_PK_BYTES, CKB_SPHINCS_PARAM1_SIGN_BYTES),
10-
ParamId::Sha2128S => (CKB_SPHINCS_PARAM2_PK_BYTES, CKB_SPHINCS_PARAM2_SIGN_BYTES),
11-
ParamId::Sha2192F => (CKB_SPHINCS_PARAM3_PK_BYTES, CKB_SPHINCS_PARAM3_SIGN_BYTES),
12-
ParamId::Sha2192S => (CKB_SPHINCS_PARAM4_PK_BYTES, CKB_SPHINCS_PARAM4_SIGN_BYTES),
13-
ParamId::Sha2256F => (CKB_SPHINCS_PARAM5_PK_BYTES, CKB_SPHINCS_PARAM5_SIGN_BYTES),
14-
ParamId::Sha2256S => (CKB_SPHINCS_PARAM6_PK_BYTES, CKB_SPHINCS_PARAM6_SIGN_BYTES),
15-
ParamId::Shake128F => (CKB_SPHINCS_PARAM7_PK_BYTES, CKB_SPHINCS_PARAM7_SIGN_BYTES),
16-
ParamId::Shake128S => (CKB_SPHINCS_PARAM8_PK_BYTES, CKB_SPHINCS_PARAM8_SIGN_BYTES),
17-
ParamId::Shake192F => (CKB_SPHINCS_PARAM9_PK_BYTES, CKB_SPHINCS_PARAM9_SIGN_BYTES),
18-
ParamId::Shake192S => (CKB_SPHINCS_PARAM10_PK_BYTES, CKB_SPHINCS_PARAM10_SIGN_BYTES),
19-
ParamId::Shake256F => (CKB_SPHINCS_PARAM11_PK_BYTES, CKB_SPHINCS_PARAM11_SIGN_BYTES),
20-
ParamId::Shake256S => (CKB_SPHINCS_PARAM12_PK_BYTES, CKB_SPHINCS_PARAM12_SIGN_BYTES),
9+
ParamId::Sha2128F => (CKB_SPHINCS_PARAM48_PK_BYTES, CKB_SPHINCS_PARAM48_SIGN_BYTES),
10+
ParamId::Sha2128S => (CKB_SPHINCS_PARAM49_PK_BYTES, CKB_SPHINCS_PARAM49_SIGN_BYTES),
11+
ParamId::Sha2192F => (CKB_SPHINCS_PARAM50_PK_BYTES, CKB_SPHINCS_PARAM50_SIGN_BYTES),
12+
ParamId::Sha2192S => (CKB_SPHINCS_PARAM51_PK_BYTES, CKB_SPHINCS_PARAM51_SIGN_BYTES),
13+
ParamId::Sha2256F => (CKB_SPHINCS_PARAM52_PK_BYTES, CKB_SPHINCS_PARAM52_SIGN_BYTES),
14+
ParamId::Sha2256S => (CKB_SPHINCS_PARAM53_PK_BYTES, CKB_SPHINCS_PARAM53_SIGN_BYTES),
15+
ParamId::Shake128F => (CKB_SPHINCS_PARAM54_PK_BYTES, CKB_SPHINCS_PARAM54_SIGN_BYTES),
16+
ParamId::Shake128S => (CKB_SPHINCS_PARAM55_PK_BYTES, CKB_SPHINCS_PARAM55_SIGN_BYTES),
17+
ParamId::Shake192F => (CKB_SPHINCS_PARAM56_PK_BYTES, CKB_SPHINCS_PARAM56_SIGN_BYTES),
18+
ParamId::Shake192S => (CKB_SPHINCS_PARAM57_PK_BYTES, CKB_SPHINCS_PARAM57_SIGN_BYTES),
19+
ParamId::Shake256F => (CKB_SPHINCS_PARAM58_PK_BYTES, CKB_SPHINCS_PARAM58_SIGN_BYTES),
20+
ParamId::Shake256S => (CKB_SPHINCS_PARAM59_PK_BYTES, CKB_SPHINCS_PARAM59_SIGN_BYTES),
21+
}
22+
}
23+
24+
pub fn indices(param_id: ParamId) -> usize {
25+
match param_id {
26+
ParamId::Sha2128F => 0,
27+
ParamId::Sha2128S => 1,
28+
ParamId::Sha2192F => 2,
29+
ParamId::Sha2192S => 3,
30+
ParamId::Sha2256F => 4,
31+
ParamId::Sha2256S => 5,
32+
ParamId::Shake128F => 6,
33+
ParamId::Shake128S => 7,
34+
ParamId::Shake192F => 8,
35+
ParamId::Shake192S => 9,
36+
ParamId::Shake256F => 10,
37+
ParamId::Shake256S => 11,
2138
}
2239
}
2340

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
pub const CKB_SPHINCS_PARAM1_PK_BYTES: usize = 32;
2-
pub const CKB_SPHINCS_PARAM1_SIGN_BYTES: usize = 17088;
3-
pub const CKB_SPHINCS_PARAM2_PK_BYTES: usize = 32;
4-
pub const CKB_SPHINCS_PARAM2_SIGN_BYTES: usize = 7856;
5-
pub const CKB_SPHINCS_PARAM3_PK_BYTES: usize = 48;
6-
pub const CKB_SPHINCS_PARAM3_SIGN_BYTES: usize = 35664;
7-
pub const CKB_SPHINCS_PARAM4_PK_BYTES: usize = 48;
8-
pub const CKB_SPHINCS_PARAM4_SIGN_BYTES: usize = 16224;
9-
pub const CKB_SPHINCS_PARAM5_PK_BYTES: usize = 64;
10-
pub const CKB_SPHINCS_PARAM5_SIGN_BYTES: usize = 49856;
11-
pub const CKB_SPHINCS_PARAM6_PK_BYTES: usize = 64;
12-
pub const CKB_SPHINCS_PARAM6_SIGN_BYTES: usize = 29792;
13-
pub const CKB_SPHINCS_PARAM7_PK_BYTES: usize = 32;
14-
pub const CKB_SPHINCS_PARAM7_SIGN_BYTES: usize = 17088;
15-
pub const CKB_SPHINCS_PARAM8_PK_BYTES: usize = 32;
16-
pub const CKB_SPHINCS_PARAM8_SIGN_BYTES: usize = 7856;
17-
pub const CKB_SPHINCS_PARAM9_PK_BYTES: usize = 48;
18-
pub const CKB_SPHINCS_PARAM9_SIGN_BYTES: usize = 35664;
19-
pub const CKB_SPHINCS_PARAM10_PK_BYTES: usize = 48;
20-
pub const CKB_SPHINCS_PARAM10_SIGN_BYTES: usize = 16224;
21-
pub const CKB_SPHINCS_PARAM11_PK_BYTES: usize = 64;
22-
pub const CKB_SPHINCS_PARAM11_SIGN_BYTES: usize = 49856;
23-
pub const CKB_SPHINCS_PARAM12_PK_BYTES: usize = 64;
24-
pub const CKB_SPHINCS_PARAM12_SIGN_BYTES: usize = 29792;
1+
pub const CKB_SPHINCS_PARAM48_PK_BYTES: usize = 32;
2+
pub const CKB_SPHINCS_PARAM48_SIGN_BYTES: usize = 17088;
3+
pub const CKB_SPHINCS_PARAM49_PK_BYTES: usize = 32;
4+
pub const CKB_SPHINCS_PARAM49_SIGN_BYTES: usize = 7856;
5+
pub const CKB_SPHINCS_PARAM50_PK_BYTES: usize = 48;
6+
pub const CKB_SPHINCS_PARAM50_SIGN_BYTES: usize = 35664;
7+
pub const CKB_SPHINCS_PARAM51_PK_BYTES: usize = 48;
8+
pub const CKB_SPHINCS_PARAM51_SIGN_BYTES: usize = 16224;
9+
pub const CKB_SPHINCS_PARAM52_PK_BYTES: usize = 64;
10+
pub const CKB_SPHINCS_PARAM52_SIGN_BYTES: usize = 49856;
11+
pub const CKB_SPHINCS_PARAM53_PK_BYTES: usize = 64;
12+
pub const CKB_SPHINCS_PARAM53_SIGN_BYTES: usize = 29792;
13+
pub const CKB_SPHINCS_PARAM54_PK_BYTES: usize = 32;
14+
pub const CKB_SPHINCS_PARAM54_SIGN_BYTES: usize = 17088;
15+
pub const CKB_SPHINCS_PARAM55_PK_BYTES: usize = 32;
16+
pub const CKB_SPHINCS_PARAM55_SIGN_BYTES: usize = 7856;
17+
pub const CKB_SPHINCS_PARAM56_PK_BYTES: usize = 48;
18+
pub const CKB_SPHINCS_PARAM56_SIGN_BYTES: usize = 35664;
19+
pub const CKB_SPHINCS_PARAM57_PK_BYTES: usize = 48;
20+
pub const CKB_SPHINCS_PARAM57_SIGN_BYTES: usize = 16224;
21+
pub const CKB_SPHINCS_PARAM58_PK_BYTES: usize = 64;
22+
pub const CKB_SPHINCS_PARAM58_SIGN_BYTES: usize = 49856;
23+
pub const CKB_SPHINCS_PARAM59_PK_BYTES: usize = 64;
24+
pub const CKB_SPHINCS_PARAM59_SIGN_BYTES: usize = 29792;

contracts/hybrid-sphincs-all-in-one-lock/src/main.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ckb_std::default_alloc!(16384, 1258306, 64);
1717

1818
mod generated;
1919

20-
use crate::generated::params::{lengths, PARAM_IDS_COUNT};
20+
use crate::generated::params::{indices, lengths, PARAM_IDS_COUNT};
2121
use ckb_fips205_utils::{
2222
ckb_tx_message_all_in_ckb_vm::generate_ckb_tx_message_all_with_witness,
2323
iterate_public_key_with_optional_signature, Hasher, ParamId,
@@ -55,8 +55,8 @@ pub fn program_entry() -> i8 {
5555

5656
iterate_public_key_with_optional_signature(
5757
lock,
58-
|_i, param_id, public_key, _signature| {
59-
script_args_hasher.update(&[param_id.into()]);
58+
|_i, param_id, sign_flag, public_key, _signature| {
59+
script_args_hasher.update(&[sign_flag]);
6060
script_args_hasher.update(public_key);
6161

6262
match parsed_param_id {
@@ -141,9 +141,9 @@ pub fn program_entry() -> i8 {
141141

142142
iterate_public_key_with_optional_signature(
143143
lock,
144-
|_i, param_id, public_key, signature| {
144+
|_i, param_id, _sign_flag, public_key, signature| {
145145
if let Some(signature) = signature {
146-
let param_index = u8::from(param_id) as usize;
146+
let param_index = indices(param_id);
147147
if spawned_vms[param_index].is_none() {
148148
// Spawns a new VM for a param ID
149149
let (binary_offset, binary_length) = load_binary_infos(param_id);
@@ -209,7 +209,7 @@ pub fn program_entry() -> i8 {
209209
}
210210
// Reads reasponse from child VM
211211
{
212-
let mut response = [0u8; 1];
212+
let mut response = [0u8; 3];
213213

214214
let mut read = 0;
215215
while read < response.len() {
@@ -220,6 +220,8 @@ pub fn program_entry() -> i8 {
220220
}
221221

222222
assert_eq!(response[0], 0);
223+
assert_eq!(response[1], 0);
224+
assert_eq!(response[2], 0);
223225
}
224226
}
225227
},

contracts/sphincs-all-in-one-lock/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ pub fn program_entry() -> i8 {
4545

4646
iterate_public_key_with_optional_signature(
4747
lock,
48-
|_i, param_id, public_key, signature| {
49-
script_args_hasher.update(&[param_id.into()]);
48+
|_i, param_id, sign_flag, public_key, signature| {
49+
script_args_hasher.update(&[sign_flag]);
5050
script_args_hasher.update(public_key);
5151

5252
if let Some(signature) = signature {

0 commit comments

Comments
 (0)