Skip to content
Open
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 contract-dev/gas.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ let sizeMsg = computeDataSize(
);

let fwdFee = getForwardFee(
sizeMsg.cells - 1,
sizeMsg.cells - 1,
sizeMsg.bits - msg.toCell().bits(),
isAccountInMasterchain
);
Expand Down
24 changes: 12 additions & 12 deletions contract-dev/security.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Improper handling of signed integers can allow attackers to exploit overflow/und
(cell,()) transfer_voting_power(cell votes, slice from, slice to, int amount) impure {
int from_votes = get_voting_power(votes, from);
int to_votes = get_voting_power(votes, to);

from_votes -= amount; // Can become negative!
to_votes += amount;

votes~set_voting_power(from, from_votes);
votes~set_voting_power(to, to_votes);
return (votes,());
Expand All @@ -30,12 +30,12 @@ Improper handling of signed integers can allow attackers to exploit overflow/und
(cell,()) transfer_voting_power(cell votes, slice from, slice to, int amount) impure {
int from_votes = get_voting_power(votes, from);
int to_votes = get_voting_power(votes, to);

throw_unless(998, from_votes >= amount); // Validate sufficient balance

from_votes -= amount;
to_votes += amount;

votes~set_voting_power(from, from_votes);
votes~set_voting_power(to, to_votes);
return (votes,());
Expand Down Expand Up @@ -67,7 +67,7 @@ Destroying accounts using [send mode](/foundations/messages/modes) `128 + 32` wi
if (in_msg_body.slice_empty?()) {
return (); ;; Dangerous: empty message handling
}

;; Process and destroy account
send_raw_message(msg, 128 + 32); ;; Destroys account
}
Expand All @@ -79,10 +79,10 @@ Destroying accounts using [send mode](/foundations/messages/modes) `128 + 32` wi
() recv_internal(msg_value, in_msg_full, in_msg_body) {
;; Proper validation before any destruction
throw_unless(error::unauthorized, authorized_sender?(sender));

;; Ensure no pending operations
throw_unless(error::pending_operations, safe_to_destroy?());

;; Then proceed with destruction if really needed
}
```
Expand All @@ -98,11 +98,11 @@ Replay protection is a security mechanism that prevents an attacker from [reusin
slice ds = get_data().begin_parse();
int stored_seqno = ds~load_uint(32);
int msg_seqno = in_msg~load_uint(32);

throw_unless(33, msg_seqno == stored_seqno); ;; Prevent replay

accept_message();

;; Update sequence number
set_data(begin_cell().store_uint(stored_seqno + 1, 32).end_cell());
}
Expand Down Expand Up @@ -454,7 +454,7 @@ Contracts can be updated if not properly protected, changing their behavior unex
() update_code(cell new_code) impure {
throw_unless(error::unauthorized, authorized_admin?(sender()));
throw_unless(error::invalid_code, validate_code?(new_code));

set_code(new_code);
}
```
12 changes: 6 additions & 6 deletions contract-dev/testing/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ describe('MyContract', () => {

beforeEach(async () => {
blockchain = await Blockchain.create();

myContract = blockchain.openContract(
MyContract.createFromConfig({}, code)
);

deployer = await blockchain.treasury('deployer');

const deployResult = await myContract.sendDeploy(
deployer.getSender(),
deployer.getSender(),
toNano('0.05')
);

Expand Down Expand Up @@ -103,7 +103,7 @@ Each test should include a fresh `Blockchain` instance to ensure:
beforeEach(async () => {
// Fresh blockchain for each test
blockchain = await Blockchain.create();

// Each test gets clean treasuries
deployer = await blockchain.treasury('deployer');
user = await blockchain.treasury('user');
Expand Down Expand Up @@ -154,7 +154,7 @@ npx blueprint test MyContract
# Run with coverage
npx blueprint test --coverage

# Run with gas reporting
# Run with gas reporting
npx blueprint test --gas-report
```

Expand Down
34 changes: 17 additions & 17 deletions contract-dev/upgrades.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ fun onInternalMessage(in: InMessage) {
}
}
else => {
// just accept TON
else => {
// just accept TON
}
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ fun onInternalMessage(in: InMessage) {
ApproveUpgrade => {
var storage = lazy Storage.load();
assert (in.senderAddress == storage.adminAddress) throw 100;
assert (storage.CurrentRequest != null) throw 301;
assert (storage.CurrentRequest!.timestamp + storage.timeout < blockchain.now()) throw 302;
Expand All @@ -189,8 +189,8 @@ fun onInternalMessage(in: InMessage) {
}
}
else => {
// just accepted tons
else => {
// just accepted tons
}
}
}
Expand Down Expand Up @@ -260,7 +260,7 @@ type AllowedMessages =
| HotUpgrade
| IncreaseCounter
// migration function must have method_id
// migration function must have method_id
@method_id(2121)
fun hotUpgradeData(additionalData: cell?) { return null; }
Expand All @@ -273,21 +273,21 @@ fun onInternalMessage(in: InMessage) {
HotUpgrade => {
var storage = lazy Storage.load();
assert (in.senderAddress == storage.adminAddress) throw 1111;
contract.setCodePostponed(msg.code);
setTvmRegisterC3(transformSliceToContinuation(msg.code.beginParse()));
hotUpgradeData(msg.additionalData);
}
}
IncreaseCounter => {
var storage = lazy Storage.load();
storage.counter += 1;
storage.save();
}
else => {
// just accept TON
else => {
// just accept TON
}
}
}
Expand Down Expand Up @@ -333,13 +333,13 @@ type AllowedMessages =
| HotUpgrade
| IncreaseCounter
// migration function must have method_id
// migration function must have method_id
@method_id(2121)
fun hotUpgradeData(additionalData: cell?) {
fun hotUpgradeData(additionalData: cell?) {
var oldStorage = lazy oldStorage.load();
assert (additionalData != null) throw 1112;
var storage = Storage {
adminAddress: oldStorage.adminAddress,
counter: oldStorage.counter,
Expand Down Expand Up @@ -368,21 +368,21 @@ fun onInternalMessage(in: InMessage) {
HotUpgrade => {
var storage = lazy Storage.load();
assert (in.senderAddress == storage.adminAddress) throw 1111;
contract.setCodePostponed(msg.code);
setTvmRegisterC3(transformSliceToContinuation(msg.code.beginParse()));
hotUpgradeData(msg.additionalData);
}
}
IncreaseCounter => {
var storage = lazy Storage.load();
storage.counter += 1;
storage.save();
}
else => {
// just accept TON
else => {
// just accept TON
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion contract-dev/vanity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class VanityContract implements Contract {
}

static createFromConfig(
config: VanityContractConfig,
config: VanityContractConfig,
workchain = 0
) {
const data = vanityContractConfigToCell(config);
Expand Down
2 changes: 1 addition & 1 deletion foundations/actions/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Finally, in the action phase, created actions are executed in the order they wer
out_list_empty$_ = OutList 0;
out_list$_ {n:#} prev:^(OutList n) action:OutAction
= OutList (n + 1);
action_send_msg#0ec3c86d mode:(## 8)
action_send_msg#0ec3c86d mode:(## 8)
out_msg:^(MessageRelaxed Any) = OutAction;
action_set_code#ad4de08e new_code:^Cell = OutAction;
action_reserve_currency#36e6b809 mode:(## 8)
Expand Down
6 changes: 3 additions & 3 deletions foundations/actions/send.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ If after the second attempt the message is still too large, the exception is thr
## Serialization

```tlb
action_send_msg#0ec3c86d mode:(## 8)
action_send_msg#0ec3c86d mode:(## 8)
out_msg:^(MessageRelaxed Any) = OutAction;

out_list_node$_ prev:^Cell action:OutAction = OutListNode;
Expand All @@ -49,10 +49,10 @@ message$_ {X:Type} info:CommonMsgInfoRelaxed
body:(Either X ^X) = MessageRelaxed X;

int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool
src:MsgAddress dest:MsgAddressInt
src:MsgAddress dest:MsgAddressInt
value:CurrencyCollection extra_flags:(VarUInteger 16) fwd_fee:Grams
created_lt:uint64 created_at:uint32 = CommonMsgInfoRelaxed;

ext_out_msg_info$11 src:MsgAddress dest:MsgAddressExt
created_lt:uint64 created_at:uint32 = CommonMsgInfoRelaxed;
created_lt:uint64 created_at:uint32 = CommonMsgInfoRelaxed;
```
6 changes: 3 additions & 3 deletions foundations/serialization/boc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ A final serialization of the bag of cells must include a magic number indicating
Only one [serialization scheme of BoCs](https://github.com/ton-blockchain/ton/blob/24dc184a2ea67f9c47042b4104bbb4d82289fac1/crypto/tl/boc.tlb#L25) is used in TON Blockchain (there are also two outdated BoC serialization schemes in the file):

```tlb PseudoTL-B
serialized_boc#b5ee9c72 has_idx:(## 1) has_crc32c:(## 1)
serialized_boc#b5ee9c72 has_idx:(## 1) has_crc32c:(## 1)
has_cache_bits:(## 1) flags:(## 2) { flags = 0 }
size:(## 3) { size <= 4 }
off_bytes:(## 8) { off_bytes <= 8 }
cells:(##(size * 8))
off_bytes:(## 8) { off_bytes <= 8 }
cells:(##(size * 8))
roots:(##(size * 8)) { roots >= 1 }
absent:(##(size * 8)) { roots + absent <= cells }
tot_cells_size:(##(off_bytes * 8))
Expand Down
14 changes: 7 additions & 7 deletions languages/func/known-issues.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ effectively removing the expected division by zero exception.
Examples:

```func
;; All these produce 0, irrespective of divisor z,
;; All these produce 0, irrespective of divisor z,
;; even when z is 0.
muldiv(0, 1, z);
muldivc(1, 0, z);
Expand Down Expand Up @@ -87,11 +87,11 @@ but the FunC compiler simplifies them irrespective of `z`:

```func
(0 & (- z)) <= 0; ;; Should overflow for z = -115792089237316195423570985008687907853269984665640564039457584007913129639936,
;; but simplified to true
;; but simplified to true
(0 * (- z)) <= 0; ;; Should overflow for z = -115792089237316195423570985008687907853269984665640564039457584007913129639936,
;; but simplified to true
;; but simplified to true
((z / -1) % 2) > -2; ;; Should overflow for z = -115792089237316195423570985008687907853269984665640564039457584007913129639936,
;; but simplified to true
;; but simplified to true
```

The following are further examples of expressions that should produce integer overflows at the indicated values,
Expand All @@ -100,15 +100,15 @@ but the FunC compiler simplifies them to `true` irrespective of the value of `z`
```func
(~(-1) & (-1 * z)) <= 0; ;; for z = MIN_INT.
((1 & (~ 1)) & (z / -1)) <= 0; ;; for z = MIN_INT.
((z & 0) & (z * 2)) <= 0; ;; for z = MAX_INT
((z & 0) & (z * 2)) <= 0; ;; for z = MAX_INT
((z * 0) & (z + 1)) <= 0; ;; for z = MAX_INT.
(~(-1) * (-1 * z)) <= 0; ;; for z = MIN_INT
((1 & (~ 1)) * (z / -1)) <= 0; ;; for z = MIN_INT
((z & 0) * (z * 2)) <= 0; ;; for z = MAX_INT
((z * 0) * (z + 1)) <= 0; ;; for z = MAX_INT
((-1 * z) % 2) > -2; ;; for z = MIN_INT
((- z) % 2) > -2; ;; for z = MIN_INT
((z * 2) % 2) > -2; ;; for z = MAX_INT
((z * 2) % 2) > -2; ;; for z = MAX_INT
((z + 1) % 2) > -2; ;; for z = MAX_INT
```

Expand Down Expand Up @@ -174,7 +174,7 @@ The following code produces a stack underflow when `run_method3` executes:
```func
() test(int a, int b, int c) impure method_id(16384) {
~dump(a);
~dump(b);
~dump(b);
~dump(c);
}

Expand Down
Loading