Skip to content

Commit 3c3afd6

Browse files
ref: align opcodes in Utils
1 parent 53a92d7 commit 3c3afd6

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

contracts/contracts/ccip/fee_quoter/contract.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ fun calculateValidatedFee(msg: Router_CCIPSend): Fee {
251251
8 => {
252252
throw FeeQuoter_Error.MsgDataTooLarge;
253253
}
254-
ERROR_INVALID_DATA => {
254+
Utils_Error.InvalidData as int => {
255255
throw FeeQuoter_Error.InvalidMsgData;
256256
}
257257
else => {

contracts/contracts/lib/utils.tolk

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import "@stdlib/lisp-lists"
22
import "@stdlib/gas-payments";
33

4-
const ERROR_INVALID_DATA = 0x77;
5-
const ERROR_BITMAP_OUT_OF_BOUNDS = 0x78;
4+
const Utils_FACILITY_NAME = "com.chainlink.ton.lib.Utils";
5+
// getFacilityId(stringCrc32(Utils_FACILITY_NAME));
6+
const Utils_FACILITY_ID = 489;
7+
8+
enum Utils_Error {
9+
InvalidData = Utils_FACILITY_ID * 100
10+
BitmapOutOfBounds
11+
}
612

713
/// Returns the facility ID for the given CRC32 key (e.g. stringCrc32("com.chainlink.ton.mcms.Timelock")).
814
/// Returns a value in range 10..649 (640 values).
@@ -119,7 +125,7 @@ fun Iterator<T>.next(mutate self): T {
119125
var (bits, refs) = self.data.remainingBitsAndRefsCount();
120126
if (bits == 0) {
121127
// for snakeData to be well formed, there should only be one reference
122-
assert(refs == 1, ERROR_INVALID_DATA);
128+
assert(refs == 1, Utils_Error.InvalidData);
123129
self.data = self.data.loadRef().beginParse();
124130
}
125131
return self.data.loadAny<T>();
@@ -131,7 +137,7 @@ fun Iterator<T>.next(mutate self): T {
131137
fun Iterator<T>.countBytes(self): int {
132138
val maxCells = 128;
133139
val (cellsCount, dataBitsSize, _cellRefs) = self.data.calculateSizeStrict(maxCells);
134-
assert(dataBitsSize % 8 == 0, ERROR_INVALID_DATA);
140+
assert(dataBitsSize % 8 == 0, Utils_Error.InvalidData);
135141
return dataBitsSize / 8;
136142
}
137143

@@ -141,7 +147,7 @@ fun Iterator<T>.countBytes(self): int {
141147
// ExitCodes:
142148
// - 0: no error
143149
// - 8 (cell overflow): exceeded maxCells
144-
// - ERROR_INVALID_DATA: data is invalid (not byte-aligned)
150+
// - Utils_Error.InvalidData: data is invalid (not byte-aligned)
145151
@inline
146152
fun Iterator<T>.countBytesSafe(self): (int, int) {
147153
try {
@@ -201,13 +207,13 @@ fun Bitmap256.new(): Bitmap256 {
201207

202208
@inline
203209
fun Bitmap256.set(mutate self, index: int): void {
204-
assert(index >= 0 && index < 256, ERROR_BITMAP_OUT_OF_BOUNDS);
210+
assert(index >= 0 && index < 256, Utils_Error.BitmapOutOfBounds);
205211
self.bits = self.bits | (1 << index);
206212
}
207213

208214
@inline
209215
fun Bitmap256.has(self, index: int): bool {
210-
assert(index >= 0 && index < 256, ERROR_BITMAP_OUT_OF_BOUNDS);
216+
assert(index >= 0 && index < 256, Utils_Error.BitmapOutOfBounds);
211217
return (self.bits & (1 << index)) != 0;
212218
}
213219

@@ -216,7 +222,7 @@ fun Bitmap256.has(self, index: int): bool {
216222
fun countAddresses(data: cell): int {
217223
val maxCells = 128;
218224
val (cellsCount, dataBitsSize, cellRefs) = data.calculateSizeStrict(maxCells);
219-
assert(dataBitsSize % ADDR_KEY_LEN == 0, ERROR_INVALID_DATA);
225+
assert(dataBitsSize % ADDR_KEY_LEN == 0, Utils_Error.InvalidData);
220226
return dataBitsSize / ADDR_KEY_LEN;
221227
}
222228

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import '@ton/test-utils'
2+
3+
import { crc32 } from 'zlib'
4+
import * as utils from '../../../wrappers/libraries/utils/Utils'
5+
import { facilityId } from '../../../wrappers/utils'
6+
7+
describe('MerkleMultiProof Unit Tests', () => {
8+
it('should match facility ID', async () => {
9+
expect(utils.FACILITY_ID).toBe(facilityId(crc32(utils.FACILITY_NAME)))
10+
})
11+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const FACILITY_NAME = 'com.chainlink.ton.lib.Utils'
2+
export const FACILITY_ID = 489
3+
export const ERROR_CODE = FACILITY_ID * 100
4+
5+
export enum Errors {
6+
InvalidData = ERROR_CODE,
7+
BitmapOutOfBounds,
8+
}

0 commit comments

Comments
 (0)