-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(stdlib): rewrite contractAddressExt
, newAddress
and Address.asSlice
functions to Tact; add asAddressUnsafe
and contractHash
#1766
refactor(stdlib): rewrite contractAddressExt
, newAddress
and Address.asSlice
functions to Tact; add asAddressUnsafe
and contractHash
#1766
Conversation
contractAddressExt
, newAddress
and Address.asSlice
functions to TactcontractAddressExt
, newAddress
and Address.asSlice
functions to Tact
…ead of `endCell().hash()`
merge conflicts |
Fixed |
…github.com:tact-lang/tact into pmakhnev/rewrite-address-related-functions-to-tact
Added docs, please take a look! Renamed Also renamed
In general, I think at some point we might carefully split all the P.S.: We can revert those renames if you wish, but I believe they are on point :) |
I've renamed The current implementation of $global_contractHash PROCINLINE:<{
NEWC
131380 PUSHINT
SWAP
24 STU
s2 PUSH
CDEPTH
SWAP
16 STU
OVER
CDEPTH
SWAP
16 STU
s0 s2 XCHG
HASHCU
ROT
256 STU
SWAP
HASHCU
SWAP
256 STU
ONE HASHEXT_SHA256
}> If we rewrite it as a Tact That's why instead of writing docs for asm fun contractHash(code: Cell, data: Cell): Int {
// According to the https://docs.tact-lang.org/book/cells#cells-representation,
// the layout for the Builder to hash goes as follows:
// 1) refs_descriptor:bits8 | bits_descriptor:bits8 | data:bitsN
//
// refs_descriptor: ref_count + ((exotic? & 1) * 8) + (mask * 32)
// 2 refs (code + data), non-exotic, zero-mask
//
// bits_descriptor: floor(bit_count / 8) + ceil(bit_count, 8)
// floor (5 bits / 8) + ceil(5 bits / 8) = 0 + 1 = 1
//
// data: [0b00110] + [0b100] = [0b00110100] = 0x34 (data + augmented bits)
// 0b00110 - data (split_depth, special, code, data, Library)
// 0b100 - augmented bits (Leading 1 + zeroes to make section multiple of eight)
//
// That is: (2 << 16) | (1 << 8) | 0x34 = 131380 for all three.
//
// 2) and 3) depth_descriptors: CDEPTH of `code` and CDEPTH of `data`
// 4) and 5) ref hashes: HASHCU of `code` and HASHCU of `data`
// Group 1: Computations and arrangements
s0 PUSH HASHCU // `data` hash
s2 PUSH HASHCU // `code` hash
SWAP2
CDEPTH // `data` depth
SWAP
CDEPTH // `code` depth
131380 INT // (2 << 16) | (1 << 8) | 0x34
// Group 2: Composition of the Builder
NEWC
24 STU // store refs_descriptor | bits_descriptor | data
16 STU // store depth_descriptor for `code`
16 STU // store depth_descriptor for `data`
256 STU // store `code` hash
256 STU // store `data` hash
// Group 3: SHA256 hash of the resulting Builder
ONE HASHEXT_SHA256 // a.k.a. Builder.hash()
} In this form, it consumes 90 less gas than its non- @anton-trunov @Shvandre @i582 @Gusarich If you agree with this vision, let's remove the |
And removal of unnecessary `Builder.hash()`, which was originally intended to be private and only used in previous code of `contractHash()`
Fixing benchmarks, uno momento por favor |
contractAddressExt
, newAddress
and Address.asSlice
functions to TactcontractAddressExt
, newAddress
and Address.asSlice
functions to Tact; add asAddressUnsafe
and contractHash
Issue
Closes #1763.
Closes #1764.
Closes #1765.
Towards #1736.
Towards #573.
Checklist