Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added normalized hash of external-in message and increased stack depth for tonlib #1557

Merged
merged 3 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tl/generate/scheme/tonlib_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ raw.message hash:bytes source:accountAddress destination:accountAddress value:in
raw.transaction address:accountAddress utime:int53 data:bytes transaction_id:internal.transactionId fee:int64 storage_fee:int64 other_fee:int64 in_msg:raw.message out_msgs:vector<raw.message> = raw.Transaction;
raw.transactions transactions:vector<raw.transaction> previous_transaction_id:internal.transactionId = raw.Transactions;

raw.extMessageInfo hash:bytes = raw.ExtMessageInfo;
raw.extMessageInfo hash:bytes hash_norm:bytes = raw.ExtMessageInfo;

pchan.config alice_public_key:string alice_address:accountAddress bob_public_key:string bob_address:accountAddress init_timeout:int32 close_timeout:int32 channel_id:int64 = pchan.Config;

Expand Down
Binary file modified tl/generate/scheme/tonlib_api.tlo
Binary file not shown.
44 changes: 41 additions & 3 deletions tonlib/tonlib/TonlibClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3312,9 +3312,47 @@ td::Status TonlibClient::do_request(const tonlib_api::raw_sendMessageReturnHash&
td::Promise<object_ptr<tonlib_api::raw_extMessageInfo>>&& promise) {
TRY_RESULT_PREFIX(body, vm::std_boc_deserialize(request.body_), TonlibError::InvalidBagOfCells("body"));
auto hash = body->get_hash().as_slice().str();

// compute hash normalized
block::gen::Message::Record message;
if (!tlb::type_unpack_cell(body, block::gen::t_Message_Any, message)) {
return td::Status::Error("Failed to unpack Message");
}
auto tag = block::gen::CommonMsgInfo().get_tag(*message.info);
if (tag != block::gen::CommonMsgInfo::ext_in_msg_info) {
return td::Status::Error("CommonMsgInfo tag is not ext_in_msg_info");
}
block::gen::CommonMsgInfo::Record_ext_in_msg_info msg_info;
if (!tlb::csr_unpack(message.info, msg_info)) {
return td::Status::Error("Failed to unpack CommonMsgInfo::ext_in_msg_info");
}

td::Ref<vm::Cell> body_norm;
auto body_cs = message.body.write();
if (body_cs.fetch_long(1) == 1) {
body_norm = body_cs.fetch_ref();
} else {
body_norm = vm::CellBuilder().append_cellslice(body_cs).finalize();
}

auto cb = vm::CellBuilder();
bool status =
cb.store_long_bool(2, 2) && // message$_ -> info:CommonMsgInfo -> ext_in_msg_info$10
cb.store_long_bool(0, 2) && // message$_ -> info:CommonMsgInfo -> src:MsgAddressExt -> addr_none$00
cb.append_cellslice_bool(msg_info.dest) && // message$_ -> info:CommonMsgInfo -> dest:MsgAddressInt
cb.store_long_bool(0, 4) && // message$_ -> info:CommonMsgInfo -> import_fee:Grams -> 0
cb.store_long_bool(0, 1) && // message$_ -> init:(Maybe (Either StateInit ^StateInit)) -> nothing$0
cb.store_long_bool(1, 1) && // message$_ -> body:(Either X ^X) -> right$1
cb.store_ref_bool(body_norm);

if (!status) {
return td::Status::Error("Failed to build normalized message");
}
auto hash_norm = cb.finalize()->get_hash().as_slice().str();

make_request(int_api::SendMessage{std::move(body)},
promise.wrap([hash = std::move(hash)](auto res) {
return tonlib_api::make_object<tonlib_api::raw_extMessageInfo>(std::move(hash));
promise.wrap([hash = std::move(hash), hash_norm = std::move(hash_norm)](auto res) {
return tonlib_api::make_object<tonlib_api::raw_extMessageInfo>(std::move(hash), std::move(hash_norm));
}));
return td::Status::OK();
}
Expand Down Expand Up @@ -4510,7 +4548,7 @@ auto to_tonlib_api(const vm::StackEntry& entry, int& limit) -> td::Result<tonlib
};

auto to_tonlib_api(const td::Ref<vm::Stack>& stack) -> td::Result<std::vector<tonlib_api::object_ptr<tonlib_api::tvm_StackEntry>>> {
int stack_limit = 1000;
int stack_limit = 8000;
std::vector<tonlib_api::object_ptr<tonlib_api::tvm_StackEntry>> tl_stack;
for (auto& entry: stack->as_span()) {
TRY_RESULT(tl_entry, to_tonlib_api(entry, --stack_limit));
Expand Down