Starlight: Orchestration Support For Big Integers
Hey guys! Let's dive into something super important for Starlight – making sure we can handle BIG numbers (we're talking seriously big!) in our orchestration. As you know, Starlight helps us convert Solidity contracts into zApps, which are essentially JavaScript programs. But there's a slight hiccup when dealing with the sizes of numbers we can use. So, we are going to fix it. This is how we are going to do it.
The Big Integer Problem in Starlight
Okay, so here's the deal. Solidity, the language used for writing smart contracts, has a type called uint256. This type can handle really, really big integers – up to a whopping 2^256 - 1. That's a huge number! However, when Starlight turns these contracts into zApps (which run on JavaScript), we run into a bit of a limitation. JavaScript's standard Number type can only safely represent integers up to 9,007,199,254,740,991 (which is the same as 2^53 – 1). This is known as Number.MAX_SAFE_INTEGER. What does this mean? Basically, if you try to use a number bigger than that in your JavaScript code generated by Starlight, you're going to have problems. The number might lose precision, or behave in ways you don't expect.
Why is this happening?
It's all about how JavaScript stores numbers. It uses a specific format that works well for most everyday numbers, but it has a limit on how many digits it can accurately represent. When you go beyond that limit, things get a little wonky. This is why we need to address this limitation to ensure that Starlight can handle the large integer values that are common in blockchain applications.
Addressing the Issue: BigInts to the Rescue
The good news is that JavaScript has a solution: BigInts! BigInts are a special type in JavaScript that can handle integers of arbitrary precision. This means they can represent those super-large numbers that we need for our Solidity contracts. Our goal is to rewrite the orchestration logic in Starlight to use BigInts instead of the standard Number type. This will make sure that the numbers in your zApps behave as expected, no matter how large they are (within the bounds of the underlying zero-knowledge circuits, of course!).
Impact of the Change
So, what does this all mean for you? Well, it means that you'll be able to write Solidity contracts with large integer values and have them work correctly when converted to zApps by Starlight. No more unexpected behavior or lost precision! This change is crucial for making Starlight a robust and reliable tool for developing decentralized applications that rely on large numbers, such as those that involve financial calculations, complex data structures, and other sophisticated operations. This enhancement will also ensure that Starlight remains compatible with the ever-evolving landscape of blockchain technology, where the need for handling large numbers is becoming increasingly common.
Tasks to Implement BigInt Support
Alright, let's break down the work that needs to be done to get BigInts working seamlessly in Starlight. We need to focus on a few key areas to make sure everything functions smoothly and accurately. Let's see what the main things are that need to be done.
Rewriting the Code Generator and Boilerplates
The first and most important task is to rewrite the code generator and boilerplates to use BigInts instead of the standard parseInt function. This is where the magic happens! The code generator is responsible for translating the Solidity contract code into JavaScript. This includes handling all the integer values used in the contract. We need to make sure that the generator understands how to work with BigInts and correctly uses them in the generated JavaScript code.
Updating the Readme
Next, we need to update the README file. This is super important because it's the first place people go to learn about Starlight. We need to clearly explain the change to BigInts and how it affects developers. This should include:-
- How to use
BigIntsin your Solidity contracts: Are there any specific things developers need to do in their Solidity code to ensure that the numbers are handled correctly by Starlight? Perhaps using a specific type or format. - Limitations: While
BigIntsremove the JavaScriptNumberlimitation, we need to mention that there will still be a limit because of the circuits used. We should clarify the maximum size allowed, which is defined by the underlying zero-knowledge circuits, to set proper expectations. - Examples: It's always helpful to provide clear examples that illustrate how to use
BigIntsin your Solidity code and how they translate into the generated zApp code. This will help developers understand the change quickly and easily.
Testing with Zolidity Contracts
Finally, we need to thoroughly test Starlight with a variety of Solidity contracts. This is how we make sure everything works as expected. We need to test contracts with both secret and public variables to cover all the bases. This means testing a range of scenarios to verify that:
BigIntsare correctly handled in both secret and public variables.- Arithmetic operations work as expected with
BigInts. - Contracts with large integer values function correctly in the zApp.
Definition of Done: Ensuring Success
To consider this work complete, we need to meet a clear definition of done. This means we have a set of criteria that must be met to ensure that the BigInt implementation is successful and that Starlight is working as expected. Here's what needs to happen to call this task done.
Removing the Integer Limit
The most important goal is to remove the integer limit. We want to make sure that we can handle integers larger than 2^53 - 1 without any problems in the zApp code. This means the zApp should accurately represent and process large integers as defined in the Solidity contract.
Testing Contracts
Next, we need to test all the contracts to confirm that BigInts work flawlessly. We need to test a variety of Solidity contracts with both secret and public variables to ensure that the implementation is reliable and works in all expected scenarios.
Verification
We need to verify that all the test cases pass and the generated zApp code accurately represents and processes the integer values defined in the Solidity contract, even when they're very large. This validation confirms that the core functionality is correct and that users can rely on the system to handle large integers.
Documentation
We need to ensure all changes are well-documented. This includes updating the Readme file, code comments, and any relevant documentation to provide clear and up-to-date guidance to users. This will enable developers to understand and correctly utilize the new BigInt support within the Starlight ecosystem.
By following these steps, we can ensure that Starlight is a reliable and accurate tool for generating zApps from Solidity contracts, making it easier for developers to work with large integers in their blockchain applications. This enhancement will significantly improve the flexibility and performance of Starlight, making it a more powerful tool for the future of decentralized applications.