Skip to content

Commit 0b7d226

Browse files
committed
Disable anycast address, allow deploying with "fixed prefix length"
1 parent 44e7e09 commit 0b7d226

11 files changed

+242
-157
lines changed

crypto/block/block-parse.cpp

+6-5
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)
@@ -1085,7 +1085,7 @@ bool Account::skip_copy_depth_balance(vm::CellBuilder& cb, vm::CellSlice& cs) co
10851085
case account:
10861086
return cs.advance(1) // account$1
10871087
&& t_MsgAddressInt.skip_get_depth(cs, depth) // addr:MsgAddressInt
1088-
&& cb.store_uint_leq(30, depth) // -> store split_depth:(#<= 30)
1088+
&& cb.store_uint_leq(30, depth) // -> store fixed_prefix_length:(#<= 30)
10891089
&& t_StorageInfo.skip(cs) // storage_stat:StorageInfo
10901090
&& t_AccountStorage.skip_copy_balance(cb, cs); // storage:AccountStorage
10911091
}
@@ -1230,13 +1230,14 @@ bool HashmapAugE::extract_extra(vm::CellSlice& cs) const {
12301230
bool DepthBalanceInfo::skip(vm::CellSlice& cs) const {
12311231
return cs.advance(5) &&
12321232
t_CurrencyCollection.skip(
1233-
cs); // depth_balance$_ split_depth:(#<= 30) balance:CurrencyCollection = DepthBalanceInfo;
1233+
cs); // depth_balance$_ fixed_prefix_length:(#<= 30) balance:CurrencyCollection = DepthBalanceInfo;
12341234
}
12351235

12361236
bool DepthBalanceInfo::validate_skip(int* ops, vm::CellSlice& cs, bool weak) const {
12371237
return cs.fetch_ulong(5) <= 30 &&
1238-
t_CurrencyCollection.validate_skip(ops, cs,
1239-
weak); // depth_balance$_ split_depth:(#<= 30) balance:CurrencyCollection
1238+
t_CurrencyCollection.validate_skip(
1239+
ops, cs,
1240+
weak); // depth_balance$_ fixed_prefix_length:(#<= 30) balance:CurrencyCollection
12401241
}
12411242

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

crypto/block/block.tlb

+4-11
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

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

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

@@ -801,7 +793,8 @@ size_limits_config#01 max_msg_bits:uint32 max_msg_cells:uint32 max_library_cells
801793
max_ext_msg_size:uint32 max_ext_msg_depth:uint16 = SizeLimitsConfig;
802794
size_limits_config_v2#02 max_msg_bits:uint32 max_msg_cells:uint32 max_library_cells:uint32 max_vm_data_depth:uint16
803795
max_ext_msg_size:uint32 max_ext_msg_depth:uint16 max_acc_state_cells:uint32 max_acc_state_bits:uint32
804-
max_acc_public_libraries:uint32 defer_out_queue_size_limit:uint32 max_msg_extra_currencies:uint32 = SizeLimitsConfig;
796+
max_acc_public_libraries:uint32 defer_out_queue_size_limit:uint32 max_msg_extra_currencies:uint32
797+
max_acc_fixed_prefix_length:uint8 = SizeLimitsConfig;
805798
_ SizeLimitsConfig = ConfigParam 43;
806799

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

crypto/block/create-state.cpp

+14-14
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
}
@@ -514,7 +514,7 @@ Ref<vm::Cell> create_state() {
514514
// data (cell)
515515
// library (cell)
516516
// balance (int)
517-
// split_depth (int 0..32)
517+
// fixed_prefix_length (int 0..32)
518518
// special (int 0..3, +2 = tick, +1 = tock)
519519
// [ address (uint256) ]
520520
// mode (0 = compute address only, 1 = create uninit, 2 = create complete; +4 = with specified address)
@@ -536,7 +536,7 @@ void interpret_register_smartcontract(vm::Stack& stack) {
536536
if (special && workchain_id != wc_master) {
537537
throw fift::IntError{"cannot create special smartcontracts outside of the masterchain"};
538538
}
539-
int split_depth = stack.pop_smallint_range(32);
539+
int fixed_prefix_length = stack.pop_smallint_range(32);
540540
td::RefInt256 balance = stack.pop_int_finite();
541541
if (sgn(balance) < 0) {
542542
throw fift::IntError{"initial balance of a smartcontract cannot be negative"};
@@ -548,7 +548,7 @@ void interpret_register_smartcontract(vm::Stack& stack) {
548548
Ref<vm::Cell> data = stack.pop_cell();
549549
Ref<vm::Cell> code = stack.pop_cell();
550550
td::RefInt256 addr = create_smartcontract(std::move(spec_addr), std::move(code), std::move(data), std::move(library),
551-
std::move(balance), special, split_depth, mode);
551+
std::move(balance), special, fixed_prefix_length, mode);
552552
if (addr.is_null()) {
553553
throw fift::IntError{"internal error while creating smartcontract"};
554554
}

crypto/block/mc-config.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,7 @@ td::Result<SizeLimitsConfig> Config::do_get_size_limits_config(td::Ref<vm::CellS
19611961
limits.max_acc_public_libraries = rec.max_acc_public_libraries;
19621962
limits.defer_out_queue_size_limit = rec.defer_out_queue_size_limit;
19631963
limits.max_msg_extra_currencies = rec.max_msg_extra_currencies;
1964+
limits.max_acc_fixed_prefix_length = rec.max_acc_fixed_prefix_length;
19641965
};
19651966
gen::SizeLimitsConfig::Record_size_limits_config rec_v1;
19661967
gen::SizeLimitsConfig::Record_size_limits_config_v2 rec_v2;

crypto/block/mc-config.h

+1
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ struct SizeLimitsConfig {
398398
td::uint32 max_acc_public_libraries = 256;
399399
td::uint32 defer_out_queue_size_limit = 256;
400400
td::uint32 max_msg_extra_currencies = 2;
401+
td::uint32 max_acc_fixed_prefix_length = 8;
401402
};
402403

403404
struct CatchainValidatorsConfig {

0 commit comments

Comments
 (0)