Skip to content

Commit e806ce0

Browse files
committed
Merge branch 'testnet' into archive-sync
2 parents 2981cce + 5fe1526 commit e806ce0

File tree

22 files changed

+704
-228
lines changed

22 files changed

+704
-228
lines changed

crypto/block/block-parse.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ const TickTock t_TickTock;
738738
const RefAnything t_RefCell;
739739

740740
bool StateInit::validate_skip(int* ops, vm::CellSlice& cs, bool weak) const {
741-
return Maybe<UInt>{5}.validate_skip(ops, cs, weak) // split_depth:(Maybe (## 5))
741+
return Maybe<UInt>{5}.validate_skip(ops, cs, weak) // fixed_prefix_length:(Maybe (## 5))
742742
&& Maybe<TickTock>{}.validate_skip(ops, cs, weak) // special:(Maybe TickTock)
743743
&& Maybe<RefAnything>{}.validate_skip(ops, cs, weak) // code:(Maybe ^Cell)
744744
&& Maybe<RefAnything>{}.validate_skip(ops, cs, weak) // data:(Maybe ^Cell)
@@ -1078,7 +1078,7 @@ bool Account::skip_copy_depth_balance(vm::CellBuilder& cb, vm::CellSlice& cs) co
10781078
case account:
10791079
return cs.advance(1) // account$1
10801080
&& t_MsgAddressInt.skip_get_depth(cs, depth) // addr:MsgAddressInt
1081-
&& cb.store_uint_leq(30, depth) // -> store split_depth:(#<= 30)
1081+
&& cb.store_uint_leq(30, depth) // -> store fixed_prefix_length:(#<= 30)
10821082
&& t_StorageInfo.skip(cs) // storage_stat:StorageInfo
10831083
&& t_AccountStorage.skip_copy_balance(cb, cs); // storage:AccountStorage
10841084
}
@@ -1223,13 +1223,14 @@ bool HashmapAugE::extract_extra(vm::CellSlice& cs) const {
12231223
bool DepthBalanceInfo::skip(vm::CellSlice& cs) const {
12241224
return cs.advance(5) &&
12251225
t_CurrencyCollection.skip(
1226-
cs); // depth_balance$_ split_depth:(#<= 30) balance:CurrencyCollection = DepthBalanceInfo;
1226+
cs); // depth_balance$_ fixed_prefix_length:(#<= 30) balance:CurrencyCollection = DepthBalanceInfo;
12271227
}
12281228

12291229
bool DepthBalanceInfo::validate_skip(int* ops, vm::CellSlice& cs, bool weak) const {
12301230
return cs.fetch_ulong(5) <= 30 &&
1231-
t_CurrencyCollection.validate_skip(ops, cs,
1232-
weak); // depth_balance$_ split_depth:(#<= 30) balance:CurrencyCollection
1231+
t_CurrencyCollection.validate_skip(
1232+
ops, cs,
1233+
weak); // depth_balance$_ fixed_prefix_length:(#<= 30) balance:CurrencyCollection
12331234
}
12341235

12351236
bool DepthBalanceInfo::null_value(vm::CellBuilder& cb) const {

crypto/block/block.tlb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ ext_out_msg_info$11 src:MsgAddress dest:MsgAddressExt
141141

142142
tick_tock$_ tick:Bool tock:Bool = TickTock;
143143

144-
_ split_depth:(Maybe (## 5)) special:(Maybe TickTock)
144+
_ fixed_prefix_length:(Maybe (## 5)) special:(Maybe TickTock)
145145
code:(Maybe ^Cell) data:(Maybe ^Cell)
146146
library:(Maybe ^Cell) = StateInit;
147147

148148
// StateInitWithLibs is used to validate sent and received messages
149-
_ split_depth:(Maybe (## 5)) special:(Maybe TickTock)
149+
_ fixed_prefix_length:(Maybe (## 5)) special:(Maybe TickTock)
150150
code:(Maybe ^Cell) data:(Maybe ^Cell)
151151
library:(HashmapE 256 SimpleLib) = StateInitWithLibs;
152152

@@ -272,14 +272,6 @@ acc_state_frozen$01 = AccountStatus;
272272
acc_state_active$10 = AccountStatus;
273273
acc_state_nonexist$11 = AccountStatus;
274274

275-
/* duplicates
276-
tick_tock$_ tick:Bool tock:Bool = TickTock;
277-
278-
_ split_depth:(Maybe (## 5)) special:(Maybe TickTock)
279-
code:(Maybe ^Cell) data:(Maybe ^Cell)
280-
library:(Maybe ^Cell) = StateInit;
281-
*/
282-
283275
account_descr$_ account:^Account last_trans_hash:bits256
284276
last_trans_lt:uint64 = ShardAccount;
285277

@@ -800,7 +792,8 @@ size_limits_config#01 max_msg_bits:uint32 max_msg_cells:uint32 max_library_cells
800792
max_ext_msg_size:uint32 max_ext_msg_depth:uint16 = SizeLimitsConfig;
801793
size_limits_config_v2#02 max_msg_bits:uint32 max_msg_cells:uint32 max_library_cells:uint32 max_vm_data_depth:uint16
802794
max_ext_msg_size:uint32 max_ext_msg_depth:uint16 max_acc_state_cells:uint32 max_acc_state_bits:uint32
803-
max_acc_public_libraries:uint32 defer_out_queue_size_limit:uint32 max_msg_extra_currencies:uint32 = SizeLimitsConfig;
795+
max_acc_public_libraries:uint32 defer_out_queue_size_limit:uint32 max_msg_extra_currencies:uint32
796+
max_acc_fixed_prefix_length:uint8 = SizeLimitsConfig;
804797
_ SizeLimitsConfig = ConfigParam 43;
805798

806799
// key is [ wc:int32 addr:uint256 ]

crypto/block/create-state.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ typedef td::BitArray<256> hash_t;
9494

9595
struct SmcDescr {
9696
hash_t addr;
97-
int split_depth;
97+
int fixed_prefix_length;
9898
bool preinit_only;
9999
td::RefInt256 gram_balance;
100100
Ref<vm::DataCell> state_init; // StateInit
101101
Ref<vm::DataCell> account; // Account
102-
SmcDescr(const hash_t& _addr) : addr(_addr), split_depth(0), preinit_only(false) {
102+
SmcDescr(const hash_t& _addr) : addr(_addr), fixed_prefix_length(0), preinit_only(false) {
103103
}
104104
};
105105

@@ -123,7 +123,7 @@ vm::Dictionary config_dict{32};
123123
ton::UnixTime now;
124124

125125
bool set_config_smc(const SmcDescr& smc) {
126-
if (config_addr_set || smc.preinit_only || workchain_id != wc_master || smc.split_depth) {
126+
if (config_addr_set || smc.preinit_only || workchain_id != wc_master || smc.fixed_prefix_length) {
127127
return false;
128128
}
129129
vm::CellSlice cs = load_cell_slice(smc.state_init);
@@ -221,7 +221,7 @@ bool add_public_library(hash_t lib_addr, hash_t smc_addr, Ref<vm::Cell> lib_root
221221
}
222222

223223
td::RefInt256 create_smartcontract(td::RefInt256 smc_addr, Ref<vm::Cell> code, Ref<vm::Cell> data,
224-
Ref<vm::Cell> library, td::RefInt256 balance, int special, int split_depth,
224+
Ref<vm::Cell> library, td::RefInt256 balance, int special, int fixed_prefix_length,
225225
int mode) {
226226
if (is_empty_cell(code)) {
227227
code.clear();
@@ -238,12 +238,12 @@ td::RefInt256 create_smartcontract(td::RefInt256 smc_addr, Ref<vm::Cell> code, R
238238
THRERR("not a valid library collection");
239239
}
240240
vm::CellBuilder cb;
241-
if (!split_depth) {
241+
if (!fixed_prefix_length) {
242242
PDO(cb.store_long_bool(0, 1));
243243
} else {
244-
PDO(cb.store_long_bool(1, 1) && cb.store_ulong_rchk_bool(split_depth, 5));
244+
PDO(cb.store_long_bool(1, 1) && cb.store_ulong_rchk_bool(fixed_prefix_length, 5));
245245
}
246-
THRERR("invalid split_depth for a smart contract");
246+
THRERR("invalid fixed_prefix_length for a smart contract");
247247
if (!special) {
248248
PDO(cb.store_long_bool(0, 1));
249249
} else {
@@ -287,7 +287,7 @@ td::RefInt256 create_smartcontract(td::RefInt256 smc_addr, Ref<vm::Cell> code, R
287287
auto ins = smart_contracts.emplace(addr, addr);
288288
assert(ins.second);
289289
SmcDescr& smc = ins.first->second;
290-
smc.split_depth = split_depth;
290+
smc.fixed_prefix_length = fixed_prefix_length;
291291
smc.preinit_only = (mode == 1);
292292
smc.gram_balance = balance;
293293
total_smc_balance += balance;
@@ -328,10 +328,10 @@ td::RefInt256 create_smartcontract(td::RefInt256 smc_addr, Ref<vm::Cell> code, R
328328
ctor = 2; // addr_std$10
329329
}
330330
PDO(cb.store_long_bool(ctor, 2)); // addr_std$10 or addr_var$11
331-
if (split_depth) {
331+
if (fixed_prefix_length) {
332332
PDO(cb.store_long_bool(1, 1) // just$1
333-
&& cb.store_ulong_rchk_bool(split_depth, 5) // depth:(## 5)
334-
&& cb.store_bits_bool(addr.cbits(), split_depth)); // rewrite pfx:(depth * Bit)
333+
&& cb.store_ulong_rchk_bool(fixed_prefix_length, 5) // depth:(## 5)
334+
&& cb.store_bits_bool(addr.cbits(), fixed_prefix_length)); // rewrite pfx:(depth * Bit)
335335
} else {
336336
PDO(cb.store_long_bool(0, 1)); // nothing$0
337337
}
@@ -515,7 +515,7 @@ Ref<vm::Cell> create_state() {
515515
// data (cell)
516516
// library (cell)
517517
// balance (int)
518-
// split_depth (int 0..32)
518+
// fixed_prefix_length (int 0..32)
519519
// special (int 0..3, +2 = tick, +1 = tock)
520520
// [ address (uint256) ]
521521
// mode (0 = compute address only, 1 = create uninit, 2 = create complete; +4 = with specified address)
@@ -537,7 +537,7 @@ void interpret_register_smartcontract(vm::Stack& stack) {
537537
if (special && workchain_id != wc_master) {
538538
throw fift::IntError{"cannot create special smartcontracts outside of the masterchain"};
539539
}
540-
int split_depth = stack.pop_smallint_range(32);
540+
int fixed_prefix_length = stack.pop_smallint_range(32);
541541
td::RefInt256 balance = stack.pop_int_finite();
542542
if (sgn(balance) < 0) {
543543
throw fift::IntError{"initial balance of a smartcontract cannot be negative"};
@@ -549,7 +549,7 @@ void interpret_register_smartcontract(vm::Stack& stack) {
549549
Ref<vm::Cell> data = stack.pop_cell();
550550
Ref<vm::Cell> code = stack.pop_cell();
551551
td::RefInt256 addr = create_smartcontract(std::move(spec_addr), std::move(code), std::move(data), std::move(library),
552-
std::move(balance), special, split_depth, mode);
552+
std::move(balance), special, fixed_prefix_length, mode);
553553
if (addr.is_null()) {
554554
throw fift::IntError{"internal error while creating smartcontract"};
555555
}

crypto/block/mc-config.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -576,34 +576,50 @@ td::Result<std::shared_ptr<ValidatorSet>> Config::unpack_validator_set(Ref<vm::C
576576
"maximal index in a validator set dictionary must be one less than the total number of validators");
577577
}
578578
auto ptr = std::make_shared<ValidatorSet>(rec.utime_since, rec.utime_until, rec.total, rec.main);
579-
for (int i = 0; i < rec.total; i++) {
580-
key_buffer.store_ulong(i);
581-
auto descr_cs = dict.lookup(key_buffer.bits(), 16);
582-
if (descr_cs.is_null()) {
583-
return td::Status::Error("indices in a validator set dictionary must be integers 0..total-1");
584-
}
579+
580+
std::vector<bool> seen_keys(rec.total);
581+
td::Status error;
582+
583+
auto validator_set_check_fn = [&](Ref<vm::CellSlice> descr_cs, td::ConstBitPtr key, int n) -> bool {
584+
int i = static_cast<int>(key.get_uint(n));
585+
CHECK(i >= 0 && i < rec.total && !seen_keys[i]);
586+
seen_keys[i] = true;
587+
585588
gen::ValidatorDescr::Record_validator_addr descr;
586589
if (!tlb::csr_unpack(descr_cs, descr)) {
587590
descr.adnl_addr.set_zero();
588591
if (!(gen::t_ValidatorDescr.unpack_validator(descr_cs.write(), descr.public_key, descr.weight) &&
589592
descr_cs->empty_ext())) {
590-
return td::Status::Error(PSLICE() << "validator #" << i
591-
<< " has an invalid ValidatorDescr record in the validator set dictionary");
593+
error = td::Status::Error(PSLICE() << "validator #" << i
594+
<< " has an invalid ValidatorDescr record in the validator set dictionary");
595+
return false;
592596
}
593597
}
594598
gen::SigPubKey::Record sig_pubkey;
595599
if (!tlb::csr_unpack(std::move(descr.public_key), sig_pubkey)) {
596-
return td::Status::Error(PSLICE() << "validator #" << i
597-
<< " has no public key or its public key is in unsupported format");
600+
error = td::Status::Error(PSLICE() << "validator #" << i
601+
<< " has no public key or its public key is in unsupported format");
602+
return false;
598603
}
599604
if (!descr.weight) {
600-
return td::Status::Error(PSLICE() << "validator #" << i << " has zero weight");
605+
error = td::Status::Error(PSLICE() << "validator #" << i << " has zero weight");
606+
return false;
601607
}
602608
if (descr.weight > ~(ptr->total_weight)) {
603-
return td::Status::Error("total weight of all validators in validator set exceeds 2^64");
609+
error = td::Status::Error("total weight of all validators in validator set exceeds 2^64");
610+
return false;
604611
}
605612
ptr->list.emplace_back(sig_pubkey.pubkey, descr.weight, ptr->total_weight, descr.adnl_addr);
606613
ptr->total_weight += descr.weight;
614+
return true;
615+
};
616+
617+
if (!dict.check_for_each(validator_set_check_fn)) {
618+
CHECK(error.is_error());
619+
return error;
620+
}
621+
if (std::find(seen_keys.begin(), seen_keys.end(), false) != seen_keys.end()) {
622+
return td::Status::Error("indices in a validator set dictionary must be integers 0..total-1");
607623
}
608624
if (rec.total_weight && rec.total_weight != ptr->total_weight) {
609625
return td::Status::Error("validator set declares incorrect total weight");
@@ -2024,6 +2040,7 @@ td::Result<SizeLimitsConfig> Config::do_get_size_limits_config(td::Ref<vm::CellS
20242040
limits.max_acc_public_libraries = rec.max_acc_public_libraries;
20252041
limits.defer_out_queue_size_limit = rec.defer_out_queue_size_limit;
20262042
limits.max_msg_extra_currencies = rec.max_msg_extra_currencies;
2043+
limits.max_acc_fixed_prefix_length = rec.max_acc_fixed_prefix_length;
20272044
};
20282045
gen::SizeLimitsConfig::Record_size_limits_config rec_v1;
20292046
gen::SizeLimitsConfig::Record_size_limits_config_v2 rec_v2;

crypto/block/mc-config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ struct SizeLimitsConfig {
402402
td::uint32 max_acc_public_libraries = 256;
403403
td::uint32 defer_out_queue_size_limit = 256;
404404
td::uint32 max_msg_extra_currencies = 2;
405+
td::uint32 max_acc_fixed_prefix_length = 8;
405406
};
406407

407408
struct CatchainValidatorsConfig {

0 commit comments

Comments
 (0)