Skip to content

Commit e7b3595

Browse files
authored
fix: bounced message size validation for fixed-size slices (#3129)
1 parent 7b960b7 commit e7b3595

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

dev-docs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
- [fix] Added fixed-bytes support to bounced message size calculations
11+
1012
### Docs
1113

1214
- Changed the title of the "Gas-expensive" badge to "500+ gas" to avoid confusion when discussing relative gas-efficiency: PR [#3120](https://github.com/tact-lang/tact/pull/3120)

src/types/__snapshots__/resolveStatements.spec.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ exports[`resolveStatements should fail statements for bounced-type-is-smaller 1`
8181
"
8282
`;
8383

84+
exports[`resolveStatements should fail statements for bounced-type-is-smaller-in-bytes 1`] = `
85+
"<unknown>:18:22: Maximum size of the bounced message is 224 bits, but the "a" field of type "A" cannot fit into it because its too big, so it cannot be accessed. Reduce the type of this field so that it fits into 224 bits
86+
17 | bounced(src: bounced<A>) {
87+
> 18 | let x: Int = src.a;
88+
^
89+
19 | }
90+
"
91+
`;
92+
8493
exports[`resolveStatements should fail statements for call-non-optional-method-on-optional 1`] = `
8594
"<unknown>:10:13: Cannot call method "isNotNone" on an expression of type "Address?" (optional Address) without unwrapping it with "!!" first
8695
9 | receive() {

src/types/resolveDescriptors.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,14 +2460,16 @@ function resolvePartialFields(ctx: CompilerContext, type: TypeDescription) {
24602460

24612461
let fieldBits = f.abi.type.optional ? 1 : 0;
24622462

2463-
// TODO handle fixed-bytes
2464-
if (Number.isInteger(f.abi.type.format)) {
2465-
fieldBits += f.abi.type.format as number;
2466-
} else if (f.abi.type.format === "coins") {
2463+
const { type, format } = f.abi.type;
2464+
2465+
if (Number.isInteger(format)) {
2466+
const amount = format as number;
2467+
fieldBits += type === "fixed-bytes" ? amount * 8 : amount;
2468+
} else if (format === "coins") {
24672469
fieldBits += 124;
2468-
} else if (f.abi.type.type === "address") {
2470+
} else if (type === "address") {
24692471
fieldBits += 267;
2470-
} else if (f.abi.type.type === "bool") {
2472+
} else if (type === "bool") {
24712473
fieldBits += 1;
24722474
} else {
24732475
// Unsupported - all others (slice, builder, nested structs, maps)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
primitive Slice;
2+
3+
trait BaseTrait {
4+
5+
}
6+
7+
message A {
8+
a: Slice as bytes32;
9+
}
10+
11+
contract Test {
12+
init() {}
13+
receive(src: A) {
14+
15+
}
16+
17+
bounced(src: bounced<A>) {
18+
let x: Int = src.a;
19+
}
20+
}

0 commit comments

Comments
 (0)