ProvableHQ / leo

🦁 The Leo Programming Language. A Programming Language for Formally Verified, Zero-Knowledge Applications
https://leo-lang.org/
GNU General Public License v3.0
4.78k stars 660 forks source link

[Feature] Support for global variables #2182

Open tanqiangyes opened 2 years ago

tanqiangyes commented 2 years ago

🚀 Feature

Support for global variables to make programs more diverse

Motivation

program global.aleo {
         let  global_address: address;
         let  is_set = bool;

        transition deploy(addr: address) -> bool {
              if is_set {
                  return false;
              }
              global_address = addr;
              is_set = true;
          }

          transition change_deploy(addr: address, new_addr: address) -> bool {
                if addr != global_address {
                    return false;
                }
                global_address = new_addr;
            }

         //some other features.
}

As you can see, if global variables are implemented, then when writing a game-like contract, players send their game pledges to the contract deployer, so that no player can raise the pledge privately, and the contract deployer can use zero-knowledge proofs to control the access to the game funds through the application made by the player, which greatly ensures the financial security and fairness of the contract.

Implementation

As it stands now, it may be necessary to modify variable declarations, as well as the internal constructs of the program and the corresponding compiler. This will be a lot of work, but it will be a huge boost to the programming effort.

d0cd commented 1 year ago

Thank you for the proposal! We are definitely open to introducing this into the language. We will need to iron out details of the design and programming model in an ARC. Here are some relevant links:

tanqiangyes commented 1 year ago

Thank you for the proposal! We are definitely open to introducing this into the language. We will need to iron out details of the design and programming model in an ARC. Here are some relevant links:

Here is:

tanqiangyes commented 1 year ago

@d0cd Please review the latest ARC, thanks.