mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Increase limit for t_Block.validate, simplify validating StateInit (#691)
Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
parent
24ed85b155
commit
a78adf3062
6 changed files with 63 additions and 10 deletions
|
@ -2292,5 +2292,37 @@ bool Aug_ShardFees::eval_leaf(vm::CellBuilder& cb, vm::CellSlice& cs) const {
|
|||
|
||||
const Aug_ShardFees aug_ShardFees;
|
||||
|
||||
bool validate_message_libs(const td::Ref<vm::Cell> &cell) {
|
||||
gen::Message::Record rec;
|
||||
if (!type_unpack_cell(cell, gen::t_Message_Any, rec)) {
|
||||
return false;
|
||||
}
|
||||
vm::CellSlice& state_init = rec.init.write();
|
||||
if (!state_init.fetch_long(1)) {
|
||||
return true;
|
||||
}
|
||||
if (state_init.fetch_long(1)) {
|
||||
return gen::t_StateInitWithLibs.validate_ref(state_init.prefetch_ref());
|
||||
} else {
|
||||
return gen::t_StateInitWithLibs.validate_csr(rec.init);
|
||||
}
|
||||
}
|
||||
|
||||
bool validate_message_relaxed_libs(const td::Ref<vm::Cell> &cell) {
|
||||
gen::MessageRelaxed::Record rec;
|
||||
if (!type_unpack_cell(cell, gen::t_MessageRelaxed_Any, rec)) {
|
||||
return false;
|
||||
}
|
||||
vm::CellSlice& state_init = rec.init.write();
|
||||
if (!state_init.fetch_long(1)) {
|
||||
return true;
|
||||
}
|
||||
if (state_init.fetch_long(1)) {
|
||||
return gen::t_StateInitWithLibs.validate_ref(state_init.prefetch_ref());
|
||||
} else {
|
||||
return gen::t_StateInitWithLibs.validate_csr(rec.init);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace tlb
|
||||
} // namespace block
|
||||
|
|
|
@ -1113,5 +1113,9 @@ struct Aug_ShardFees final : AugmentationCheckData {
|
|||
|
||||
extern const Aug_ShardFees aug_ShardFees;
|
||||
|
||||
// Validate dict of libraries in message: used when sending and receiving message
|
||||
bool validate_message_libs(const td::Ref<vm::Cell> &cell);
|
||||
bool validate_message_relaxed_libs(const td::Ref<vm::Cell> &cell);
|
||||
|
||||
} // namespace tlb
|
||||
} // namespace block
|
||||
|
|
|
@ -143,8 +143,13 @@ tick_tock$_ tick:Bool tock:Bool = TickTock;
|
|||
|
||||
_ split_depth:(Maybe (## 5)) special:(Maybe TickTock)
|
||||
code:(Maybe ^Cell) data:(Maybe ^Cell)
|
||||
library:(HashmapE 256 SimpleLib) = StateInit;
|
||||
|
||||
library:(Maybe ^Cell) = StateInit;
|
||||
|
||||
// StateInitWithLibs is used to validate sent and received messages
|
||||
_ split_depth:(Maybe (## 5)) special:(Maybe TickTock)
|
||||
code:(Maybe ^Cell) data:(Maybe ^Cell)
|
||||
library:(HashmapE 256 SimpleLib) = StateInitWithLibs;
|
||||
|
||||
simple_lib$_ public:Bool root:^Cell = SimpleLib;
|
||||
|
||||
message$_ {X:Type} info:CommonMsgInfo
|
||||
|
|
|
@ -635,14 +635,15 @@ bool Transaction::unpack_input_msg(bool ihr_delivered, const ActionPhaseConfig*
|
|||
vm::CellBuilder cb;
|
||||
if (!(cs.advance(2) && block::gen::t_StateInit.fetch_to(cs, state_init) &&
|
||||
cb.append_cellslice_bool(std::move(state_init)) && cb.finalize_to(in_msg_state) &&
|
||||
block::gen::t_StateInit.validate_ref(in_msg_state))) {
|
||||
block::gen::t_StateInitWithLibs.validate_ref(in_msg_state))) {
|
||||
LOG(DEBUG) << "cannot parse StateInit in inbound message";
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: { // (just$1 (right$1 _:^StateInit ))
|
||||
if (!(cs.advance(2) && cs.fetch_ref_to(in_msg_state) && block::gen::t_StateInit.validate_ref(in_msg_state))) {
|
||||
if (!(cs.advance(2) && cs.fetch_ref_to(in_msg_state) &&
|
||||
block::gen::t_StateInitWithLibs.validate_ref(in_msg_state))) {
|
||||
LOG(DEBUG) << "cannot parse ^StateInit in inbound message";
|
||||
return false;
|
||||
}
|
||||
|
@ -1534,6 +1535,10 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
if (!tlb::type_unpack_cell(act_rec.out_msg, block::gen::t_MessageRelaxed_Any, msg)) {
|
||||
return -1;
|
||||
}
|
||||
if (!block::tlb::validate_message_relaxed_libs(act_rec.out_msg)) {
|
||||
LOG(DEBUG) << "outbound message has invalid libs in StateInit";
|
||||
return -1;
|
||||
}
|
||||
if (redoing >= 1) {
|
||||
if (msg.init->size_refs() >= 2) {
|
||||
LOG(DEBUG) << "moving the StateInit of a suggested outbound message into a separate cell";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue