소스 검색

Release 0.3.4 London (#1811)

Signed-off-by: salaheldinsoliman <salaheldin_sameh@aucegypt.edu>
Signed-off-by: Sean Young <sean@mess.org>
Co-authored-by: Sean Young <sean@mess.org>
salaheldinsoliman 5 달 전
부모
커밋
f6307aeeb7

+ 1 - 0
.gitignore

@@ -1,4 +1,5 @@
 /docs/build
+/docs/.venv
 Cargo.lock
 /target
 **/*.rs.bk

+ 35 - 1
CHANGELOG.md

@@ -4,15 +4,49 @@ will be documented here.
 
 ## Unreleased
 
+## v0.3.4 London
+
 ### Added
+- **Soroban** Support for [Stellar Asset Contract(SAC)](https://developers.stellar.org/docs/tokens/stellar-asset-contract)
+- **Soroban** Support for [Cross Contract Calls](https://developers.stellar.org/docs/build/smart-contracts/example-contracts/cross-contract-call)
+- **Soroban** Support for [Soroban Authorization Framework](https://developers.stellar.org/docs/learn/fundamentals/contract-development/authorization)
+- **Soroban** Support for different [Soroban Storage types](https://developers.stellar.org/docs/build/guides/storage/choosing-the-right-storage)
 - **Soroban** Work on adding support for [Stellar's Soroban](https://soroban.stellar.org/docs) contracts platforms started, by adding a skeleton that supports the Soroban runtime. [Salaheldin Soliman](https://github.com/salaheldinsoliman)
-
 - The `string.concat()` and `bytes.concat()` builtin functions are supported. [seanyoung](https://github.com/seanyoung)
+- **Experimental**: Three address code format IR for the CFG has been implemented (disabled by default).
+  [fanyi-zhao](https://github.com/fanyi-zhao).
+- **Polkadot**: Compatibility with ink! v5.0 metadata and substrate-contracts-node v0.39.0
+- Implement event selectors [seanyoung](https://github.com/seanyoung)
+- Add a feature flag for compiling language server [xermicus](https://github.com/xermicus)
+- Parsing the pragma solidity version numbers, making this information available in the downstream 
+  compilation pipeline [seanyoung](https://github.com/seanyoung)
 
 ### Changed
+- **Polkadot/BREAKING**: Event encoding and topics follow [ink! v5.0](https://use.ink/faq/migrating-from-ink-4-to-5#events-20-1)
 - **BREAKING** The non-standard extension of concatenating strings using the `+` operator
   has been removed, use `string.concat()` instead. [seanyoung](https://github.com/seanyoung)
 - Removed the `--no-log-api-return-codes` compile flag as this is now done by the runtime [xermicus](https://github.com/xermicus)
+- **Solana/BREAKING**: Remove balance, transfer, and send builtins from Solana [LucasSte](https://github.com/LucasSte)
+- No longer support numbers in octal notation [seanyoung](https://github.com/seanyoung)
+- Moved to LLVM version 16 [seanyoung](https://github.com/seanyoung)
+- Improve overloaded function call diagnostics: From Solidity 0.6 onwards, overloaded functions or events
+  resolving to multiple candidates are an error. In earlier versions, the first result is used.
+  [seanyoung](https://github.com/seanyoung)
+- **Polkadot**: Implement the caller_is_root runtime API as a builtin [xermicus](https://github.com/xermicus)
+
+### Fixed
+- [Two Infinite loops in codegen](https://github.com/hyperledger-solang/solang/commit/c6db2acc8a3927fae17c437eeeea0d0ae49a67df), thanks to @smoelius.
+- [Handle abi.encode() with infinite empty arguments](https://github.com/hyperledger-solang/solang/commit/12a6d83b91f7f5a4cc48156e1112638e733e143a), thanks to @smoelius.
+- Unreachable code, function types with parameter/return names and unknown assembly flags are warnings
+  instead of errors, matching with solc. [xermicus](https://github.com/xermicus)
+- Fixed a bunch of typos in the documentation [divdeploy](https://github.com/divdeploy)
+- Clean up the LLD linker context after linking each contract, preventing potential issues when compiling
+  multiple contracts at once. [xermicus](https://github.com/xermicus)
+- Expression statement should be followed by a semicolon, fixing a bug where "_;" was incorrectly parsed
+  as a variable. [seanyoung](https://github.com/seanyoung)
+- Represent type(T) correctly in the AST, fixing various related issues [seanyoung](https://github.com/seanyoung)
+- Fix a bug in abi.encodeCall() argument parsing when there is only a single argument [seanyoung](https://github.com/seanyoung)
+- Fixed a codegen bug when the RHS of a shift expression is a struct member [PaddyClark0](https://github.com/PaddyClark0)
 
 ## v0.3.3 Atlantis
 

+ 6 - 5
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "solang"
-version = "0.3.3"
+version = "0.3.4"
 authors = ["Sean Young <sean@mess.org>", "Lucas Steuernagel <lucas.tnagel@gmail.com>", "Cyrill Leutwiler <bigcyrill@hotmail.com>"]
 repository = "https://github.com/hyperledger-solang/solang"
 documentation = "https://solang.readthedocs.io/"
@@ -10,7 +10,7 @@ description = "Solang Solidity Compiler"
 keywords = [ "solidity", "compiler", "solana", "polkadot", "substrate" ]
 rust-version = "1.85.0"
 edition = "2021"
-exclude = [ "/.*", "/docs",  "/examples", "/solana-library", "/tests", "/integration", "/vscode", "/testdata" ]
+exclude = [ "/.*", "/docs", "/solana-library", "/tests", "/integration", "/vscode", "/testdata" ]
 
 [build-dependencies]
 cc = "1.0"
@@ -46,7 +46,7 @@ itertools = ">=0.10, <=0.13"
 num-rational = "0.4"
 indexmap = "2.2"
 once_cell = "1.19"
-solang-parser = { path = "solang-parser", version = "0.3.3" }
+solang-parser = { path = "solang-parser", version = "0.3.5" }
 codespan-reporting = "0.11"
 phf = { version = "0.11", features = ["macros"] }
 rust-lapper = { version = "1.1", optional = true }
@@ -67,7 +67,7 @@ primitive-types = { version = "0.12", features = ["codec"] }
 normalize-path = "0.2.1"
 bitflags = "2.4"
 scopeguard = "1.2.0"
-forge-fmt = { path = "fmt", optional = true }
+solang-forge-fmt = { version = "0.2.0", optional = true }
 # We don't use ethers-core directly, but need the correct version for the
 # build to work.
 ethers-core = { version = "2.0.10", optional = true }
@@ -93,6 +93,7 @@ ink_primitives = "5.0.0"
 wasm_host_attr = { path = "tests/wasm_host_attr" }
 num-bigint = { version = "0.4", features = ["rand", "serde"]}
 
+
 [package.metadata.docs.rs]
 no-default-features = true
 
@@ -104,7 +105,7 @@ soroban = ["soroban-sdk"]
 default = ["llvm", "wasm_opt", "language_server", "soroban"]
 llvm = ["inkwell", "libc"]
 wasm_opt = ["llvm", "wasm-opt", "contract-build"]
-language_server = ["tower-lsp", "forge-fmt", "ethers-core", "tokio", "rust-lapper"]
+language_server = ["tower-lsp", "solang-forge-fmt", "ethers-core", "tokio", "rust-lapper"]
 
 [workspace]
 members = ["solang-parser", "fmt", "tests/wasm_host_attr"]

+ 37 - 2
README.md

@@ -1,6 +1,6 @@
 <img src="https://raw.githubusercontent.com/hyperledger/solang/main/docs/hl_solang_horizontal-color.svg" alt="Solang Logo" width="75%"/>
 
-# solang - Solidity Compiler for Solana and Polkadot
+# solang - Solidity Compiler for Solana, Polkadot and Soroban
 
 [![Discord](https://img.shields.io/discord/905194001349627914?logo=Hyperledger&style=plastic)](https://discord.gg/hyperledger)
 [![CI](https://github.com/hyperledger-solang/solang/workflows/test/badge.svg)](https://github.com/hyperledger-solang/solang/actions)
@@ -9,7 +9,7 @@
 [![LoC](https://tokei.rs/b1/github/hyperledger/solang?category=lines)](https://github.com/hyperledger-solang/solang)
 
 Welcome to Solang, a new Solidity compiler written in rust which uses
-llvm as the compiler backend. Solang can compile Solidity for Solana and
+llvm as the compiler backend. Solang can compile Solidity for Solana, Soroban and the
 Polkadot Parachains with the `contracts` pallet.
 Solang is source compatible with Solidity 0.8,
 with some caveats due to differences in the underlying blockchain.
@@ -51,6 +51,40 @@ You will have a file called flipper.contract. You can use this directly in
 the [Contracts UI](https://contracts-ui.substrate.io/),
 as if your smart contract was written using ink!.
 
+
+## Build for Soroban
+
+Select one of the supported contracts for Soroban, available in on Solang's repository:
+
+```bash
+solang compile --target soroban examples/soroban/token.sol
+```
+
+You will have a file called `token.wasm`. Deploy it using the [`Stellar CLI`](https://developers.stellar.org/docs/tools/cli), after following the [`Stellar CLI Setup Manual`](https://developers.stellar.org/docs/build/smart-contracts/getting-started/setup):
+
+``` bash
+stellar contract deploy --source-account alice --wasm token.wasm --network testnet -- --_admin alice --_name SolangToken --_symbol SOLT --_decimals 18
+ℹ️  Skipping install because wasm already installed
+ℹ️  Using wasm hash b1c84d8b8057a62fb6d77ef55c9e7fb2e66c74136c7df32efd87a1c9d475f1b0
+ℹ️  Simulating deploy transaction…
+ℹ️  Transaction hash is fc3b1f00d2940e646d210e6e96347fd45dc8dd873009604ec67957edb6f6589d
+🔗 https://stellar.expert/explorer/testnet/tx/fc3b1f00d2940e646d210e6e96347fd45dc8dd873009604ec67957edb6f6589d
+ℹ️  Signing transaction: fc3b1f00d2940e646d210e6e96347fd45dc8dd873009604ec67957edb6f6589d
+🌎 Submitting deploy transaction…
+🔗 https://stellar.expert/explorer/testnet/contract/CDGUMUXA6IRRVMMKIVQJWLZZONDXBJ4AITHQS757PTBVAL4U54HI3KEW
+✅ Deployed!
+CDGUMUXA6IRRVMMKIVQJWLZZONDXBJ4AITHQS757PTBVAL4U54HI3KEW
+```
+
+Once deployed, copy the deployed contract ID and interact with it:
+
+``` bash
+stellar contract invoke --network testnet --id CDGUMUXA6IRRVMMKIVQJWLZZONDXBJ4AITHQS757PTBVAL4U54HI3KEW  --source-account alice -- mint --to alice --amount 120
+ℹ️  Signing transaction: e0d68ae85bfbe0fceed8bcadd6613e12b3159f27dbf7c18e35e94de2b4a11ee2
+```
+
+
+
 ## Tentative roadmap
 
 Solang has a high level of compatibility with many blockchains. We are trying to ensure the compiler stays
@@ -69,6 +103,7 @@ Here is a brief description of what we envision for the next versions.
 | Declare accounts for a Solidity function on Solana | In progress                                          |
 | Tooling for calls between ink! <> solidity         | In progress                                          |
 | Provide CLI for node interactions                  | [Done](https://github.com/hyperledger-solang/solang-aqd)    |
+| Support all [Soroban examples](https://github.com/stellar/soroban-examples) | In progress |
 
 ## License
 

+ 19 - 0
docs/examples/soroban/auth.sol

@@ -0,0 +1,19 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract auth {
+    // Only this address can call the increment function
+    address public owner = address"GDRIX624OGPQEX264NY72UKOJQUASHU3PYKL6DDPGSTWXWJSBOTR6N7W";
+
+ 
+    uint64 public instance counter = 20;
+
+    function increment() public returns (uint64) {
+
+        owner.requireAuth();
+
+        counter = counter + 1;
+
+        return counter;
+       
+    }
+}

+ 14 - 0
docs/examples/soroban/deep_auth/a.sol

@@ -0,0 +1,14 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract a {
+    function call_b (address b, address c) public returns (uint64) {
+        address addr = address(this);
+        // authorize contract c to be called, with function name "get_num" and "a" as an arg.
+        // get_num calls a.require_auth()
+        auth.authAsCurrContract(c, "get_num", addr);
+        bytes payload = abi.encode("increment", addr, c);
+        (bool suc, bytes returndata) = b.call(payload);
+        uint64 result = abi.decode(returndata, (uint64));
+        return result;
+    }
+}

+ 19 - 0
docs/examples/soroban/deep_auth/b.sol

@@ -0,0 +1,19 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract b {
+ 
+    uint64 public instance counter = 20;
+
+    function increment(address a, address c) public returns (uint64) {
+
+        a.requireAuth();
+        bytes payload = abi.encode("get_num", a);
+        (bool suc, bytes returndata) = c.call(payload);
+        uint64 result = abi.decode(returndata, (uint64));
+
+        counter = counter + 2;
+
+        return counter;
+       
+    }
+} 

+ 8 - 0
docs/examples/soroban/deep_auth/c.sol

@@ -0,0 +1,8 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract c {
+    function get_num(address a) public returns (uint64) {
+        a.requireAuth();
+        return 2;
+    }
+}

+ 11 - 0
docs/examples/soroban/error.sol

@@ -0,0 +1,11 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract error {
+    uint64 public count = 1;
+
+    function decrement() public returns (uint64) {
+        print("Second call will FAIL!");
+        count -= 1;
+        return count;
+    }
+}

+ 23 - 0
docs/examples/soroban/storage_types.sol

@@ -0,0 +1,23 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract storage_types {
+            
+    uint64 public temporary var = 1;
+    uint64 public instance var1 = 1;
+    uint64 public persistent var2 = 2;
+    uint64 public var3 = 2;
+
+    function inc() public {
+        var++;
+        var1++;
+        var2++;
+        var3++;
+    }
+
+    function dec() public {
+        var--;
+        var1--;
+        var2--;
+        var3--;
+    }
+}

+ 89 - 0
docs/examples/soroban/token.sol

@@ -0,0 +1,89 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract token {
+    address public admin;
+    uint32 public decimals;
+    string public name;
+    string public symbol;
+
+    constructor(
+        address _admin,
+        string memory _name,
+        string memory _symbol,
+        uint32 _decimals
+    ) {
+        admin = _admin;
+        name = _name;
+        symbol = _symbol;
+        decimals = _decimals;
+    }
+
+    mapping(address => int128) public balances;
+    mapping(address => mapping(address => int128)) public allowances;
+
+    function mint(address to, int128 amount) public {
+        require(amount >= 0, "Amount must be non-negative");
+        admin.requireAuth();
+        setBalance(to, balance(to) + amount);
+    }
+
+    function approve(address owner, address spender, int128 amount) public {
+        require(amount >= 0, "Amount must be non-negative");
+        owner.requireAuth();
+        allowances[owner][spender] = amount;
+    }
+
+    function transfer(address from, address to, int128 amount) public {
+        require(amount >= 0, "Amount must be non-negative");
+        from.requireAuth();
+        require(balance(from) >= amount, "Insufficient balance");
+        setBalance(from, balance(from) - amount);
+        setBalance(to, balance(to) + amount);
+    }
+
+    function transfer_from(
+        address spender,
+        address from,
+        address to,
+        int128 amount
+    ) public {
+        require(amount >= 0, "Amount must be non-negative");
+        spender.requireAuth();
+        require(balance(from) >= amount, "Insufficient balance");
+        require(allowance(from, spender) >= amount, "Insufficient allowance");
+        setBalance(from, balance(from) - amount);
+        setBalance(to, balance(to) + amount);
+        allowances[from][spender] -= amount;
+    }
+
+    function burn(address from, int128 amount) public {
+        require(amount >= 0, "Amount must be non-negative");
+        require(balance(from) >= amount, "Insufficient balance");
+        from.requireAuth();
+        setBalance(from, balance(from) - amount);
+    }
+
+    function burn_from(address spender, address from, int128 amount) public {
+        require(amount >= 0, "Amount must be non-negative");
+        spender.requireAuth();
+        require(balance(from) >= amount, "Insufficient balance");
+        require(allowance(from, spender) >= amount, "Insufficient allowance");
+        setBalance(from, balance(from) - amount);
+        allowances[from][spender] -= amount;
+    }
+
+    function setBalance(address addr, int128 amount) internal {
+        balances[addr] = amount;
+    }
+
+    function balance(address addr) public view returns (int128) {
+        return balances[addr];
+    }
+
+    function allowance(
+        address owner,
+        address spender
+    ) public view returns (int128) {
+        return allowances[owner][spender];
+    }
+}

+ 19 - 0
docs/examples/soroban/ttl_storage.sol

@@ -0,0 +1,19 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract ttl_storage {
+    uint64 public persistent pCount = 11;
+    uint64 temporary tCount = 7;
+    uint64 instance iCount = 3;
+
+    function extend_persistent_ttl() public view returns (int64) {
+        return pCount.extendTtl(1000, 5000);
+    }
+
+    function extend_temp_ttl() public view returns (int64) {
+        return tCount.extendTtl(3000, 7000);
+    }
+
+    function extendInstanceTtl() public view returns (int64) {
+        return extendInstanceTtl(2000, 10000);
+    }
+}

+ 2 - 2
docs/extension.rst

@@ -75,8 +75,8 @@ Once you have node and npm installed, you can build the extension like so:
     npm install -g vsce
     vsce package
 
-You should now have an extension file called ``solang-0.3.3.vsix`` which can be
-installed using ``code --install-extension solang-0.3.3.vsix``.
+You should now have an extension file called ``solang-0.3.4.vsix`` which can be
+installed using ``code --install-extension solang-0.3.4.vsix``.
 
 Alternatively, the extension is run from vscode itself.
 

+ 1 - 0
docs/index.rst

@@ -41,6 +41,7 @@ Contents
 
    targets/solana.rst
    targets/polkadot.rst
+   targets/soroban.rst
 
 .. toctree::
    :maxdepth: 3

+ 6 - 6
docs/installing.rst

@@ -28,11 +28,11 @@ Option 2: Download binaries
 
 There are binaries available on github releases:
 
-- `Linux x86-64 <https://github.com/hyperledger-solang/solang/releases/download/v0.3.3/solang-linux-x86-64>`_
-- `Linux arm64 <https://github.com/hyperledger-solang/solang/releases/download/v0.3.3/solang-linux-arm64>`_
-- `Windows x64 <https://github.com/hyperledger-solang/solang/releases/download/v0.3.3/solang.exe>`_
-- `MacOS intel <https://github.com/hyperledger-solang/solang/releases/download/v0.3.3/solang-mac-intel>`_
-- `MacOS arm <https://github.com/hyperledger-solang/solang/releases/download/v0.3.3/solang-mac-arm>`_
+- `Linux x86-64 <https://github.com/hyperledger-solang/solang/releases/download/v0.3.4/solang-linux-x86-64>`_
+- `Linux arm64 <https://github.com/hyperledger-solang/solang/releases/download/v0.3.4/solang-linux-arm64>`_
+- `Windows x64 <https://github.com/hyperledger-solang/solang/releases/download/v0.3.4/solang.exe>`_
+- `MacOS intel <https://github.com/hyperledger-solang/solang/releases/download/v0.3.4/solang-mac-intel>`_
+- `MacOS arm <https://github.com/hyperledger-solang/solang/releases/download/v0.3.4/solang-mac-arm>`_
 
 Download the file and save it somewhere in your ``$PATH``, for example the bin directory in your home directory. If the
 path you use is not already in ``$PATH``, then you need to add it yourself.
@@ -56,7 +56,7 @@ Option 3: Use ghcr.io/hyperledger/solang containers
 
 New images are automatically made available on
 `solang containers <https://github.com/hyperledger-solang/solang/pkgs/container/solang>`_.
-There is a release `v0.3.3` tag and a `latest` tag:
+There is a release `v0.3.4` tag and a `latest` tag:
 
 .. code-block:: bash
 

+ 115 - 0
docs/targets/soroban.rst

@@ -0,0 +1,115 @@
+Soroban
+========
+
+.. note:: 
+  Soroban target is currently in Pre-Alpha stage, a lot of features are not yet implemented.
+  You can find supported examples in the `examples directory <https://github.com/hyperledger-solang/solang/tree/main/examples>`_.
+
+Soroban is the smart contracts platform on the Stellar network. The soroban environment is an interface that exposes the blockchain's facilities to the contract, such as the ability to read and write to the ledger, send and receive payments, and access account information.
+
+The environment has two sides: `Host and Guest <https://developers.stellar.org/docs/learn/fundamentals/contract-development/environment-concepts#host-and-guest>`_. Code in the host environment implements the environment interface; code in the guest environment uses the environment interface.
+
+The guest environment is an isolated WASM virtual machine, which means that smart contracts should constitue of a WASM module which may contain calls to the host environment.
+
+Values communicated between the contract WASM code and the host environment are all encoded as soroban `Vals`. A `Val` is a unsigned 64-bit integer, with a tag the represents the type of the Val. For cases where the type does not fir in the 64-bit integer, the Val contains a pointer to the data in the host environment.
+
+`CAP-0046-1 <https://github.com/stellar/stellar-protocol/blob/master/core/cap-0046-01.md>`_ goes into more detail about the Soroban environment and how it works.
+
+
+
+
+
+Solidity for Soroban: changes to note
++++++++++++++++++++++++++++++++++++++
+
+
+
+
+
+Authentication and Authorization
+________________________________
+
+Authentication in Solidity is mostly done using the `msg.sender` variable, which contains the address of the caller. In Soroban, this is not available, and instead, the contract authorizes the caller by an invokation of `multiple host functions <https://github.com/stellar/rs-soroban-env/blob/0ee19322795bd0ff9097a1984b39210d0c58a6ea/soroban-env-common/env.json#L2365>`_ which take an `Address` as an argument.
+
+For example, this is a simple contract that only allows the owner to call the `set` function:
+
+.. code-block:: solidity
+
+    pragma solidity ^0.8.20;
+
+    contract OnlyOwner {
+        address owner;
+        uint
+
+        constructor() {
+            owner = msg.sender;
+        }
+
+        function set(uint256 value) public {
+            require(msg.sender == owner, "Only owner can call this function");
+            // Set the value
+        }
+    }
+
+
+In Soroban, this would be written as:
+
+.. code-block:: solidity
+
+    contract auth {
+
+        address public owner;
+        uint64 public counter;
+
+        constructor(address _owner) public {
+            owner = _owner;
+        }
+
+        function increment() public returns (uint64) {
+
+            owner.requireAuth();
+
+            counter = counter + 1;
+
+            return counter;
+        }
+    }
+
+
+
+The `requireAuth()` Builtin function will result in a host function call to the Soroban host environment, which will check if the caller is the owner of the contract. If not, the contract will revert.
+
+
+
+Storage Types
+______________
+
+In Soroban, there exists `three storage types: Persistent, Temporary and Instance <https://developers.stellar.org/docs/build/guides/storage/choosing-the-right-storage>`_.
+You can specify the storage type of a variable by using the `persistent`, `temporary` or `instance` keyword before the variable type.
+
+.. code-block:: solidity
+
+  contract storage_types {
+              
+      uint64 public temporary counter = 1;
+      uint64 public instance counter1 = 1;
+      uint64 public persistent counter2 = 2;
+      uint64 public counter3 = 2;
+
+      function inc() public {
+          counter++;
+          counter1++;
+          counter2++;
+          counter3++;
+      }
+
+      function dec() public {
+          counter--;
+          counter1--;
+          counter2--;
+          counter3--;
+      }
+  }
+
+
+

+ 19 - 0
examples/soroban/auth.sol

@@ -0,0 +1,19 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract auth {
+    // Only this address can call the increment function
+    address public owner = address"GDRIX624OGPQEX264NY72UKOJQUASHU3PYKL6DDPGSTWXWJSBOTR6N7W";
+
+ 
+    uint64 public instance counter = 20;
+
+    function increment() public returns (uint64) {
+
+        owner.requireAuth();
+
+        counter = counter + 1;
+
+        return counter;
+       
+    }
+}

+ 14 - 0
examples/soroban/deep_auth/a.sol

@@ -0,0 +1,14 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract a {
+    function call_b (address b, address c) public returns (uint64) {
+        address addr = address(this);
+        // authorize contract c to be called, with function name "get_num" and "a" as an arg.
+        // get_num calls a.require_auth()
+        auth.authAsCurrContract(c, "get_num", addr);
+        bytes payload = abi.encode("increment", addr, c);
+        (bool suc, bytes returndata) = b.call(payload);
+        uint64 result = abi.decode(returndata, (uint64));
+        return result;
+    }
+}

+ 19 - 0
examples/soroban/deep_auth/b.sol

@@ -0,0 +1,19 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract b {
+ 
+    uint64 public instance counter = 20;
+
+    function increment(address a, address c) public returns (uint64) {
+
+        a.requireAuth();
+        bytes payload = abi.encode("get_num", a);
+        (bool suc, bytes returndata) = c.call(payload);
+        uint64 result = abi.decode(returndata, (uint64));
+
+        counter = counter + 2;
+
+        return counter;
+       
+    }
+} 

+ 8 - 0
examples/soroban/deep_auth/c.sol

@@ -0,0 +1,8 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract c {
+    function get_num(address a) public returns (uint64) {
+        a.requireAuth();
+        return 2;
+    }
+}

+ 11 - 0
examples/soroban/error.sol

@@ -0,0 +1,11 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract error {
+    uint64 public count = 1;
+
+    function decrement() public returns (uint64) {
+        print("Second call will FAIL!");
+        count -= 1;
+        return count;
+    }
+}

+ 23 - 0
examples/soroban/storage_types.sol

@@ -0,0 +1,23 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract storage_types {
+            
+    uint64 public temporary var = 1;
+    uint64 public instance var1 = 1;
+    uint64 public persistent var2 = 2;
+    uint64 public var3 = 2;
+
+    function inc() public {
+        var++;
+        var1++;
+        var2++;
+        var3++;
+    }
+
+    function dec() public {
+        var--;
+        var1--;
+        var2--;
+        var3--;
+    }
+}

+ 89 - 0
examples/soroban/token.sol

@@ -0,0 +1,89 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract token {
+    address public admin;
+    uint32 public decimals;
+    string public name;
+    string public symbol;
+
+    constructor(
+        address _admin,
+        string memory _name,
+        string memory _symbol,
+        uint32 _decimals
+    ) {
+        admin = _admin;
+        name = _name;
+        symbol = _symbol;
+        decimals = _decimals;
+    }
+
+    mapping(address => int128) public balances;
+    mapping(address => mapping(address => int128)) public allowances;
+
+    function mint(address to, int128 amount) public {
+        require(amount >= 0, "Amount must be non-negative");
+        admin.requireAuth();
+        setBalance(to, balance(to) + amount);
+    }
+
+    function approve(address owner, address spender, int128 amount) public {
+        require(amount >= 0, "Amount must be non-negative");
+        owner.requireAuth();
+        allowances[owner][spender] = amount;
+    }
+
+    function transfer(address from, address to, int128 amount) public {
+        require(amount >= 0, "Amount must be non-negative");
+        from.requireAuth();
+        require(balance(from) >= amount, "Insufficient balance");
+        setBalance(from, balance(from) - amount);
+        setBalance(to, balance(to) + amount);
+    }
+
+    function transfer_from(
+        address spender,
+        address from,
+        address to,
+        int128 amount
+    ) public {
+        require(amount >= 0, "Amount must be non-negative");
+        spender.requireAuth();
+        require(balance(from) >= amount, "Insufficient balance");
+        require(allowance(from, spender) >= amount, "Insufficient allowance");
+        setBalance(from, balance(from) - amount);
+        setBalance(to, balance(to) + amount);
+        allowances[from][spender] -= amount;
+    }
+
+    function burn(address from, int128 amount) public {
+        require(amount >= 0, "Amount must be non-negative");
+        require(balance(from) >= amount, "Insufficient balance");
+        from.requireAuth();
+        setBalance(from, balance(from) - amount);
+    }
+
+    function burn_from(address spender, address from, int128 amount) public {
+        require(amount >= 0, "Amount must be non-negative");
+        spender.requireAuth();
+        require(balance(from) >= amount, "Insufficient balance");
+        require(allowance(from, spender) >= amount, "Insufficient allowance");
+        setBalance(from, balance(from) - amount);
+        allowances[from][spender] -= amount;
+    }
+
+    function setBalance(address addr, int128 amount) internal {
+        balances[addr] = amount;
+    }
+
+    function balance(address addr) public view returns (int128) {
+        return balances[addr];
+    }
+
+    function allowance(
+        address owner,
+        address spender
+    ) public view returns (int128) {
+        return allowances[owner][spender];
+    }
+}

+ 19 - 0
examples/soroban/ttl_storage.sol

@@ -0,0 +1,19 @@
+/// SPDX-License-Identifier: Apache-2.0
+
+contract ttl_storage {
+    uint64 public persistent pCount = 11;
+    uint64 temporary tCount = 7;
+    uint64 instance iCount = 3;
+
+    function extend_persistent_ttl() public view returns (int64) {
+        return pCount.extendTtl(1000, 5000);
+    }
+
+    function extend_temp_ttl() public view returns (int64) {
+        return tCount.extendTtl(3000, 7000);
+    }
+
+    function extendInstanceTtl() public view returns (int64) {
+        return extendInstanceTtl(2000, 10000);
+    }
+}

+ 4 - 3
fmt/Cargo.toml

@@ -1,18 +1,19 @@
 [package]
-name = "forge-fmt"
+name = "solang-forge-fmt"
 version = "0.2.0"
 edition = "2021"
 authors = ["Foundry Contributors"]
 license = "MIT OR Apache-2.0"
 homepage = "https://github.com/foundry-rs/foundry"
 repository = "https://github.com/foundry-rs/foundry"
+description = "Solang's fork of forge-fmt"
 
 [dependencies]
 ariadne = "0.4"
 itertools = "0.12"
-solang-parser = { path = "../solang-parser" }
+solang-parser = { path = "../solang-parser", version = "0.3.5" }
 thiserror = "1"
-serde = "1.0"
+serde = {version = "1.0", features = ["derive"]}
 tracing = "0.1"
 alloy-primitives = "0.7"
 

+ 1 - 1
fmt/tests/formatter.rs

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: Apache-2.0
 
-use forge_fmt::{format_to, parse, solang_ext::AstEq, FormatterConfig};
+use solang_forge_fmt::{format_to, parse, solang_ext::AstEq, FormatterConfig};
 use itertools::Itertools;
 use std::{fs, path::PathBuf};
 use tracing_subscriber::{EnvFilter, FmtSubscriber};

+ 1 - 1
solang-parser/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "solang-parser"
-version = "0.3.3"
+version = "0.3.5"
 authors = ["Sean Young <sean@mess.org>", "Lucas Steuernagel <lucas.tnagel@gmail.com>", "Cyrill Leutwiler <bigcyrill@hotmail.com>"]
 repository = "https://github.com/hyperledger-solang/solang"
 documentation = "https://solang.readthedocs.io/"

+ 1 - 1
src/bin/languageserver/mod.rs

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: Apache-2.0
 
-use forge_fmt::{format_to, parse, FormatterConfig};
+use solang_forge_fmt::{format_to, parse, FormatterConfig};
 use itertools::Itertools;
 use num_traits::ToPrimitive;
 use rust_lapper::{Interval, Lapper};

+ 12 - 0
vscode/CHANGELOG.md

@@ -2,6 +2,18 @@
 
 All notable changes to the "solang" extension will be documented in this file.
 
+## [0.3.4]
+
+- Language server code completion is fully implemented. [chioni16](https://github.com/chioni16)
+- Fixed a bug in the renaming functionality. [chioni16](https://github.com/chioni16)
+- Fixed common panics. [seanyoung](https://github.com/seanyoung)
+- Improve overloaded function call diagnostics: From Solidity 0.6 onwards,
+  when an overloaded function/event resolves to multiple candidates, this is an error.
+  In earlier versions, the first result is used.
+  So, use the pragma solidity version to decide whether to error or not.
+  [seanyoung](https://github.com/seanyoung)
+- Updated dependencies.
+
 ## [0.3.3]
 
 - The same version of solang should be used by the language server as on the command line,

+ 1 - 1
vscode/package.json

@@ -9,7 +9,7 @@
 		"Govardhan G D <chioni1620@gmail.com>",
 		"Sean Young <sean@mess.org>"
 	],
-	"version": "0.3.3",
+	"version": "0.3.4",
 	"repository": "github.com/hyperledger/solang",
 	"engines": {
 		"vscode": "^1.43.0"

+ 1 - 1
vscode/src/test/suite/extension.test.ts

@@ -621,7 +621,7 @@ async function testhover(docUri: vscode.Uri) {
 
   const contentarr3 = actualhover3[0].contents as vscode.MarkdownString[];
 
-  assert.strictEqual(contentarr3[0].value, 'Abort execution if argument evaulates to false\n\n```solidity\n[built-in] void require (bool)\n```');
+  assert.strictEqual(contentarr3[0].value, 'Abort execution if argument evaluates to false\n\n```solidity\n[built-in] void require (bool)\n```');
 
   const pos4 = new vscode.Position(32, 13);