Git Product home page Git Product logo

tact-challenge-contracts's Introduction

Tact Challenge

There are my solutions for the Tact Challenge.

Hacks

Some hacks are used in the solutions.

Major hacks

  • Storing the address as uint256 since Tact uses tact_verify_address every time an address is received, which consumes a lot of gas.

  • Using commit (c4 and c5 saving) and throw(0) to abruptly exit the function when you only need to send a message without changing storage.

  • nativeSendMessage, nativeRandomizeLt, nativeRandomInterval, nativeReserve.

  • Combining many numbers (storeUint + storeCoins) into one. For example, storing "NFT is still locked" as a number.

  • The correct order of data storage in the storage. It is important to understand how Tact works with storage. It depends on which value will be the first on the stack. With the correct sequence of values used and their location in the storage, a significant improvement in gas can be achieved.

  • Storing a numeric value in seed in tasks where possible and reducing its bitness.

Minor hacks

  • Changing the opcodes of messages, where possible, to values less than 10 for PUSHING to spend 18 units of gas instead of 26.

  • Reducing bitness in structures where possible due to inaccurate tests.

  • Ignoring certain conditions due to inaccurate tests. For example, nativeThrowUnless, with a small value to save gas instead of require, gives a value greater than 63. In this case, using the opcode is more expensive.

  • Small optimizations. For example, using preloadUint instead of loadUint if the slice is no longer needed, using numbers directly in the code instead of storing in a variable, incomplete clearing of the storage (in task 4 with seed = 0 means that there is no owner and nft, so they can not be reset).

Evaluation Results ๐Ÿ†

Task ID Compiled Tests Passed Points Gas Used Compilation Error
1 โœ… โœ… 8/8 5.3702 72,013,280
2 โœ… โœ… 6/6 5.3764 1,031,567,332
3 โœ… โœ… 10/10 5.4740 293,135,719
4 โœ… โœ… 5/5 5.4738 81,308,741
5 โœ… โœ… 11/11 5.4481 11,319,182,738

Some moment related to the tests

  • In task 3, it was possible not to process the condition under which division by 0 could occur. At the same time, when exchanging B -> A, it was possible not to use decimals in calculations.

  • In task 5, it was possible to fake a random and save a lot of gas.

However, these optimizations were not included in the solutions for reasons of honesty.

tact-challenge-contracts's People

Contributors

aspite avatar

Stargazers

Canfly avatar Eaxon avatar Imaginary Stargazer avatar Mahdi Bagheri avatar Oleksandr avatar Yu Cheng Tsai avatar Nikolai avatar Mario Reder avatar Roma avatar Morteza Bagheri avatar Konstantin Sitkin avatar Viacheslav Eliseev avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.