Skip to content

Commit 48094a0

Browse files
committed
fix: index and proof checking
1 parent de529e6 commit 48094a0

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

contracts/collection_exotic.fc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const int error::not_merkle_proof = 104;
1919
const int error::wrong_hash = 105;
2020
const int error::bad_update = 106;
2121
const int error::invalid_zero_hashes = 107;
22+
const int error::index_too_high = 108;
2223

2324
const int op::claim = "op::claim"c;
2425
const int op::update = "op::update"c;
@@ -130,6 +131,8 @@ cell retrieve_child(cell c, int index, int depth) {
130131
}
131132

132133
() claim(int nft_index, cell proof) impure {
134+
throw_if(error::index_too_high, nft_index >= (1 << storage::merkle_depth));
135+
133136
cell struct = proof.check_merkle_proof(storage::merkle_root);
134137
cell nft_data = struct.retrieve_child(nft_index, storage::merkle_depth);
135138

@@ -151,7 +154,7 @@ cell retrieve_child(cell c, int index, int depth) {
151154
throw_unless(error::bad_update, ty_lvl == 0x0101);
152155

153156
int old_hash = s~load_uint(256);
154-
throw_unless(error::bad_update, old_hash = zero_hash(depth));
157+
throw_unless(error::bad_update, old_hash == zero_hash(depth));
155158
} else {
156159
slice s_old = old.begin_parse();
157160
slice s_new = new.begin_parse();

contracts/collection_exotic_sbt.fc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const int error::not_merkle_proof = 104;
1919
const int error::wrong_hash = 105;
2020
const int error::bad_update = 106;
2121
const int error::invalid_zero_hashes = 107;
22+
const int error::index_too_high = 108;
2223

2324
const int op::claim = "op::claim"c;
2425
const int op::update = "op::update"c;
@@ -130,6 +131,8 @@ cell retrieve_child(cell c, int index, int depth) {
130131
}
131132

132133
() claim(int nft_index, cell proof) impure {
134+
throw_if(error::index_too_high, nft_index >= (1 << storage::merkle_depth));
135+
133136
cell struct = proof.check_merkle_proof(storage::merkle_root);
134137
cell nft_data = struct.retrieve_child(nft_index, storage::merkle_depth);
135138

@@ -151,7 +154,7 @@ cell retrieve_child(cell c, int index, int depth) {
151154
throw_unless(error::bad_update, ty_lvl == 0x0101);
152155

153156
int old_hash = s~load_uint(256);
154-
throw_unless(error::bad_update, old_hash = zero_hash(depth));
157+
throw_unless(error::bad_update, old_hash == zero_hash(depth));
155158
} else {
156159
slice s_old = old.begin_parse();
157160
slice s_new = new.begin_parse();

contracts/collection_new.fc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ global cell storage::api_data;
1414
const int error::not_owner = 100;
1515
const int error::bad_proof = 101;
1616
const int error::value_too_low = 102;
17+
const int error::index_too_high = 103;
1718

1819
const int op::claim = "op::claim"c;
1920
const int op::update = "op::update"c;
@@ -101,6 +102,8 @@ slice calculate_nft_item_address(cell state_init) {
101102
}
102103

103104
() claim(int nft_index, cell nft_data, cell proof) impure {
105+
throw_if(error::index_too_high, nft_index >= (1 << storage::merkle_depth));
106+
104107
throw_unless(error::bad_proof, check_proof(storage::merkle_root, proof, nft_data.cell_hash(), nft_index, storage::merkle_depth));
105108

106109
(slice owner, cell content) = nft_data.parse_nft_data();

0 commit comments

Comments
 (0)