### Install Ligo Compiler (Optional) Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md Installs the Ligo compiler from a .deb package for testing purposes. ```sh curl -o /tmp/ligo.deb https://ligolang.org/deb/ligo.deb dpkg -i /tmp/ligo.deb ``` -------------------------------- ### Install Node Version Manager (nvm) Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md Installs nvm for managing Node.js versions. Recommended for development. ```sh curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash # relogin or source ~/.bashrc nvm i 12 ``` -------------------------------- ### Install sol2ligo and Dependencies Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md Installs the sol2ligo transpiler globally using npm, along with Iced Coffee Script. ```sh npm i -g iced-coffee-script npm i -g madfish-solutions/sol2ligo ``` -------------------------------- ### Clone Repository and Install Packages Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md Clones the sol2ligo repository and installs project dependencies using npm. ```sh git clone https://github.com/madfish-solutions/sol2ligo cd sol2ligo npm ci ``` -------------------------------- ### Install sol2ligo Node Module Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md Install sol2ligo and its dependency iced-coffee-script globally. This is required before using sol2ligo as a module. ```sh npm i -g iced-coffee-script npm i madfish-solutions/sol2ligo ``` -------------------------------- ### Solidity Contract Example Source: https://github.com/madfish-solutions/sol2ligo/wiki/Router This Solidity contract defines two simple methods, method1 and method2, which can be called externally. ```solidity pragma solidity ^0.4.16; contract eee { function method1(int y) public { int x = y + 1; } function method2(int y) public { int x = y + 2; } } ``` -------------------------------- ### FA1.2 Token Interface from ERC-20 Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Illustrates the conversion of ERC-20 token interfaces to the FA1.2 standard for Tezos token interoperability, including example functions. ```pascal (* FA1.2 Token Interface (converted from ERC-20) *) type amt is nat; type fa12_action is | Transfer of (address * address * amt) | Approve of (address * amt) | GetAllowance of (address * address * contract(amt)) | GetBalance of (address * contract(amt)) | GetTotalSupply of (unit * contract(amt)) (* Example token transfer function *) function transfer (const self : state; const recipient : address; const value : nat) : (list(operation) * state) is block { self.balances[sender] := abs((case self.balances[sender] of | None -> 0n | Some(x) -> x end) - value); self.balances[recipient] := ((case self.balances[recipient] of | None -> 0n | Some(x) -> x end) + value); } with ((nil: list(operation)), self); ``` -------------------------------- ### Solidity Foreign Contract Call Source: https://github.com/madfish-solutions/sol2ligo/wiki/Foreign-contract-callback-stub Example of a synchronous balance check in Solidity that cannot be directly translated to LIGO. ```solidity // granted `token` is a foreign contract uint b = token.balance(user_address); ``` -------------------------------- ### Perform Basic CLI Transpilation Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Use these commands to convert Solidity files to PascalLIGO, manage output files, and handle deployment state or compiler versions. ```bash # Basic transpilation sol2ligo contract.sol # Output to file (creates MyToken.ligo and MyToken.storage) sol2ligo contract.sol -o MyToken # With default state for deployment sol2ligo contract.sol --ds # Specify solc version and test compilation sol2ligo contract.sol --solc 0.5.12 --test ``` -------------------------------- ### Process Directories with CLI Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Transpile entire Solidity projects while maintaining the original directory structure. ```bash # Process all .sol files in a directory sol2ligo --dir ./solidity-project # Specify output directory sol2ligo --dir ./solidity-project --outdir ./ligo-output # Combine with other options sol2ligo --dir ./solidity-project --outdir ./output --test ``` -------------------------------- ### LIGO Type Conversions from Solidity Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Demonstrates how various Solidity types are mapped to their LIGO equivalents, including basic types, mappings, arrays, and structs. ```pascal (* Solidity -> LIGO Type Conversions *) (* bool -> bool *) const flag : bool = False; (* string -> string *) const name : string = ""; (* int/int256 -> int *) const number : int = 0; (* uint/uint256 -> nat *) const amount : nat = 0n; (* address -> address (null address for defaults) *) const owner : address = ("tz1ZZZZZZZZZZZZZZZZZZZZZZZZZZZZNkiRg" : address); (* mapping(K => V) -> map(K, V) *) const balances : map(address, nat) = (map end: map(address, nat)); (* array T[] -> map(nat, T) where nat is index *) const items : map(nat, string) = map 0n -> "first"; 1n -> "second"; end; (* struct -> record *) type MyStruct is record field1 : nat; field2 : string; end; ``` -------------------------------- ### Run External Compiler Tests (with solidity_samples) Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md Runs external compiler tests, including solidity_samples, which may produce Ligo errors. ```sh npm run test-ext-compiler ``` -------------------------------- ### Run Fast Tests (Excluding solidity_samples) Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md Executes tests quickly, excluding the solidity_samples directory. ```sh npm run test-fast ``` -------------------------------- ### Initialize Solidity Types in LIGO Source: https://github.com/madfish-solutions/sol2ligo/wiki/Default-Values Default initial values for common Solidity types when represented in LIGO. ```LIGO boolean: False ``` ```LIGO string: "" ``` ```LIGO int: 0 ``` ```LIGO uint: 0n ``` ```LIGO enum: the first element of the enum - enum[NAME_OF_FIRST_KEY] ``` ```LIGO address: ("tz1ZZZZZZZZZZZZZZZZZZZZZZZZZZZZNkiRg": address) ``` ```LIGO mapping: (map end: map(key_type, value_type)) - an empty map ``` ```LIGO struct: a struct where all members are set to initial values ``` ```LIGO array: (map end: map(nat, value_type)) - nat is the index of map ``` ```LIGO timestamp: abs(now - ("1970-01-01T00:00:00Z" : timestamp)) - since Solidity timestamp is stored in uint to emulate the same behaviour we convert Tezos timestamp typed value by subtracting "beginning of unix times" from it ``` -------------------------------- ### Complete Transpilation Workflow with sol2ligo Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Illustrates the end-to-end process of transpiling a Solidity contract to LIGO using the sol2ligo Node.js API. This includes reading the Solidity source, compiling with specific options, checking for errors and warnings, writing the output LIGO code and default storage, and optionally verifying with the LIGO compiler. ```javascript const sol2ligo = require("sol2ligo"); const fs = require("fs"); const { execSync } = require("child_process"); // Step 1: Read Solidity source const soliditySource = fs.readFileSync("./contracts/MyToken.sol", "utf-8"); // Step 2: Transpile with options const result = sol2ligo.compile(soliditySource, { router: true, contract: "MyToken", replace_enums_by_nats: true }); // Step 3: Check for errors and warnings if (result.errors.length > 0) { console.error("Compilation errors:", result.errors); process.exit(1); } result.warnings.forEach(w => console.warn("Warning:", w)); if (result.prevent_deploy) { console.error("CRITICAL: Code requires manual fixes before deployment!"); } // Step 4: Write output files fs.writeFileSync("./output/MyToken.ligo", result.ligo_code); fs.writeFileSync("./output/MyToken.storage", result.default_state); // Step 5: Optionally compile with LIGO compiler to verify try { execSync("ligo compile-contract ./output/MyToken.ligo main", { stdio: "inherit" }); console.log("LIGO compilation successful!"); } catch (err) { console.error("LIGO compilation failed - manual fixes required"); } ``` -------------------------------- ### Run Emulator Tests Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md Executes special tests that launch Ligo dry-runs for head-to-head comparison with Eth Ganache results. ```sh npm run test-emulator ``` -------------------------------- ### Run Full Test Suite Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md Executes the complete test suite for the sol2ligo project. ```sh npm test ``` -------------------------------- ### Ether and Time Unit Conversions in LIGO Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Provides reference for converting Solidity's ether and time units to their Tezos equivalents, including scaling factors for tez and time in seconds. ```pascal (* Ether Unit Conversions (1 tez = 1,000,000 mutez) *) (* szabo -> 1 mutez *) const fee1 : tez = 1mutez; (* finney -> 1,000 mutez *) const fee2 : tez = 1000mutez; (* ether -> 1,000,000 mutez (1 tez) *) const fee3 : tez = 1000000mutez; (* Time Unit Conversions (in seconds) *) const oneSecond : int = 1; const oneMinute : int = 60; const oneHour : int = 3600; const oneDay : int = 86400; const oneWeek : int = 604800; ``` -------------------------------- ### LIGO Global Variable Mappings from Solidity Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Shows the mapping of common Solidity global variables (like msg.sender, tx.origin, block.timestamp) to their corresponding LIGO/Tezos equivalents. ```pascal (* Solidity -> LIGO Global Variable Mappings *) (* msg.sender -> sender *) const caller : address = sender; (* tx.origin -> source *) const origin : address = source; (* block.timestamp / now -> now *) const currentTime : timestamp = now; (* msg.value -> amount *) const sentAmount : tez = amount; (* address(this) -> self_address *) const contractAddr : address = self_address; (* this -> get_contract(self_address) *) const selfContract : contract(unit) = Tezos.get_contract(self_address); (* require(condition) / assert(condition) *) if not (condition) then failwith("error message") else skip; (* revert() *) failwith("error message"); ``` -------------------------------- ### Run Fast External Compiler Tests Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md Performs quick tests using the external Ligo compiler. ```sh npm run test-ext-compiler-fast ``` -------------------------------- ### Foreign Contract Callback Pattern in LIGO Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Demonstrates how to handle asynchronous foreign contract calls using callbacks in LIGO, essential for Tezos transactions. This involves declaring a callback handler, creating a transaction with the callback entrypoint, and returning the operation. ```pascal (* Foreign contract calls require callbacks in LIGO *) (* Unlike Solidity where you can: uint b = token.balance(user_address); *) (* Step 1: Declare callback handler *) function getBalanceCallback (const self : state; const balance_ : nat) : (list(operation) * state) is block { (* Execute code dependent on returned value here *) self.lastBalance := balance_; } with ((nil: list(operation)), self); (* Step 2: Create transaction with callback *) const op : operation = transaction( (sender, Tezos.self("%GetBalanceCallback")), 0tez, Tezos.get_entrypoint("%GetBalance", token) ); (* Step 3: Return operation in list to execute *) (* The callback will be invoked after current contract execution completes *) ``` -------------------------------- ### Use Node.js compile API Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Programmatically transpile Solidity code using the compile function, which returns generated LIGO code and diagnostic information. ```javascript const sol2ligo = require("sol2ligo"); const solidityCode = ` pragma solidity ^0.5.12; contract BasicToken { mapping(address => uint256) balances; function transfer(address recipient, uint256 value) public { balances[msg.sender] -= value; balances[recipient] += value; } function balanceOf(address account) public view returns (uint256) { return balances[account]; } }`; const result = sol2ligo.compile(solidityCode, { solc_version: "0.5.12", // Override solc version suggest_solc_version: "0.4.26", // Fallback version if pragma missing auto_version: true, // Read version from pragma (default: true) allow_download: true, // Download solc if needed (default: true) router: true, // Generate router (default: true) contract: "BasicToken", // Target contract for router replace_enums_by_nats: true, // Convert enums to nat (default: true) debug: false // Enable debug output }); // Output structure: // { // errors: [], // Compilation errors // warnings: [], // Transpilation warnings // ligo_code: "...", // Generated PascalLIGO code // default_state: "...", // Initial state for deployment // prevent_deploy: false // True if code has critical issues // } console.log(result.ligo_code); if (result.prevent_deploy) { console.error("WARNING: Generated code requires manual fixes before deployment"); } ``` -------------------------------- ### Compile Solidity Code with sol2ligo Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md Use the sol2ligo.compile function to convert Solidity code to LIGO. The function accepts the Solidity code as a string and an optional options object for customization. ```javascript const sol2ligo = require("sol2ligo"); console.log(sol2ligo.compile( ` pragma solidity ^0.5.12; contract FooBarContract { function foo(uint number) internal returns (int) { string[2] memory arr = ["hello", "world"]; bool isEven = number % 2 == 0; int result = 42 * 42; return isEven ? -1 : result; } }`, { // you can specify compilation options here })); ``` -------------------------------- ### Error Handling Equivalents in Ligo Source: https://github.com/madfish-solutions/sol2ligo/wiki/Units-and-globally-available-variables Translates Solidity's error handling functions (`assert`, `require`, `revert`) into Ligo's `failwith` mechanism. Other dialects may support `assert` syntax. ```plaintext assert(bool condition) => if condition then skip else failwith(string error_msg) require(bool condition) => if condition then skip else failwith(string error_msg) revert() => failwith(string error_msg) ``` -------------------------------- ### Configure Enum Handling in CLI Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Toggle between converting Solidity enums to NAT constants or LIGO variant types. ```bash # Default: convert enums to nat constants for Solidity-like behavior sol2ligo contract.sol # Result: const FIRST_ENUM_VAL : nat = 0n; # const SECOND_ENUM_VAL : nat = 1n; # Disable nat conversion to use LIGO variant types sol2ligo contract.sol --disable_enums_to_nat # Result: type Enum_val of | FIRST_ENUM_VAL | SECOND_ENUM_VAL ``` -------------------------------- ### Time Unit Conversion in Ligo Source: https://github.com/madfish-solutions/sol2ligo/wiki/Units-and-globally-available-variables Illustrates the time unit conversions in Ligo, where 1 second is the base unit, similar to Solidity. ```plaintext 1 seconds => 1 1 minutes => 60 1 hours => 3600 1 days => 86400 1 weeks => 604800 ``` -------------------------------- ### Block and Transaction Property Mappings in Ligo Source: https://github.com/madfish-solutions/sol2ligo/wiki/Units-and-globally-available-variables Shows the Ligo equivalents for commonly used Solidity block and transaction properties. Note that not all Solidity properties are directly supported. ```plaintext msg.sender => sender tx.origin => source block.timestamp => now msg.value => amount now => now ``` -------------------------------- ### Solidity Contract for Router Pattern Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Input Solidity contract code that will be converted to a LIGO router pattern. ```solidity // Input Solidity pragma solidity ^0.4.16; contract SimpleContract { function method1(int y) public { int x = y + 1; } function method2(int y) public { int x = y + 2; } } ``` -------------------------------- ### ABI Encoding/Decoding Functions in Ligo Source: https://github.com/madfish-solutions/sol2ligo/wiki/Units-and-globally-available-variables Maps Solidity's ABI encoding and decoding functions to their Ligo equivalents. Note that `abi.encodePacked`, `abi.encodeWithSelector`, and `abi.encodeWithSignature` all map to `bytes_pack`. ```plaintext abi.decode => bytes_unpack abi.encode => bytes_pack abi.encodePacked => bytes_pack abi.encodeWithSelector => bytes_pack abi.encodeWithSignature => bytes_pack ``` -------------------------------- ### sol2ligo Compilation Options Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md An object containing optional fields to customize the Solidity to LIGO compilation process. These options control aspects like the Solidity compiler version, router generation, and enum transformation. ```javascript { solc_version: String, // override solc version specified in pragma suggest_solc_version: String, // (default: 0.4.26) suggested solc version if pragma is not specified auto_version: Boolean, // (default: true) setting this to false disables reading solc version from pragma allow_download: Boolean, // (default: true) download solc catalog router: Boolean, // (default: true) generate router contract: String, // (default: ) name of contract to generate router for replace_enums_by_nats: Boolean, // (default: true) transform enums to number constants debug: Boolean // (default: false) self explanatory } ``` -------------------------------- ### Contract Related Mappings in Ligo Source: https://github.com/madfish-solutions/sol2ligo/wiki/Units-and-globally-available-variables Shows the Ligo equivalents for Solidity's `address(this)` and `this`. Destruct functions like `suicide` and `selfdestruct` are not supported. ```plaintext address(this) => self_address this => get_contract(self_address) ``` -------------------------------- ### Translate Solidity to Ligo Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md Converts a Solidity contract function to its Ligo equivalent. Ensure to review and audit the generated code. ```solidity contract FooBarContract { function foo(uint number) internal returns (int) { string[2] memory arr = ["hello", "world"]; bool isEven = number % 2 == 0; int result = 42 * 42; return isEven ? -1 : result; } } ``` ```js function foo (const self : state; const number : nat) : (state * int) is block { const arr : map(nat, string) = map 0n -> "hello"; 1n -> "world"; end; const isEven : bool = ((number mod 2n) = 0n); const result : int = (42 * 42); } with (case isEven of | True -> -(1) | False -> result end); ``` -------------------------------- ### LIGO Callback Pattern Source: https://github.com/madfish-solutions/sol2ligo/wiki/Foreign-contract-callback-stub The required pattern for subscribing to a foreign contract response using a callback function and an operation list. ```pascal (* declare a callback *) function getBalanceCallback (const self : state; const balance_ : nat) : (list(operation) * state) is block { (* here you execute your code dependent on value returned by foreign contract *) } with ((nil: list(operation)), self); const op : operation = transaction((sender, Tezos.self("%GetBalanceCallback")), 0tez, Tezos.get_entrypoint("%GetBalance", token)); (* return `list [op]` as a first return value of your contract to actually execute the call to foreign contract *) ``` -------------------------------- ### Error Handling and Cryptography in LIGO Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Shows LIGO equivalents for common Solidity error handling and cryptographic functions. Assertions and reverts are handled using `failwith`, and cryptographic functions like SHA-256, SHA-512, and BLAKE2b are available. Note that Keccak256, RIPEMD160, and SHA3 are not supported, but `ecrecover` can be approximated. ```pascal (* Error Handling *) (* assert(condition) and require(condition) become: *) if not (condition) then failwith("Condition not met") else skip; (* revert() becomes: *) failwith("Reverted"); (* Cryptographic Functions *) (* sha256 -> sha_256 (fully supported) *) const hash1 : bytes = Crypto.sha256(someBytes); (* sha512 -> sha_512 *) const hash2 : bytes = Crypto.sha512(someBytes); (* blake2b -> blake2b *) const hash3 : bytes = Crypto.blake2b(someBytes); (* NOTE: keccak256, ripemd160, sha3 are NOT supported in LIGO *) (* ecrecover can be approximated with: *) const isValid : bool = Crypto.check(publicKey, signature, messageHash); ``` -------------------------------- ### Generated LIGO Router Pattern Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt The LIGO equivalent of a Solidity contract, generated with a router pattern for external method calls. ```pascal (* Generated LIGO with router *) type method1_args is unit; type method2_args is unit; type router_enum is | Method1 of method1_args | Method2 of method2_args; function method1 (const self : state; const y : int) : (list(operation) * state) is block { const x : int = (y + 1); } with ((nil: list(operation)), self); function method2 (const self : state; const y : int) : (list(operation) * state) is block { const x : int = (y + 2); } with ((nil: list(operation)), self); function main (const action : router_enum; const self : state) : (list(operation) * state) is (case action of | Method1(match_action) -> method1(self) | Method2(match_action) -> method2(self) end); ``` -------------------------------- ### Configure CLI Router Generation Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Control how the router structure is generated to enable external calls to contract methods. ```bash # Generate with router (default behavior) sol2ligo contract.sol --router # Specify which contract to generate router for (when multiple contracts exist) sol2ligo contract.sol --contract TokenContract # Disable router generation sol2ligo contract.sol --router=false ``` -------------------------------- ### Mathematical and Cryptographic Functions in Ligo Source: https://github.com/madfish-solutions/sol2ligo/wiki/Units-and-globally-available-variables Provides Ligo equivalents for Solidity's mathematical and cryptographic functions. Note that `ecrecover` has a potential replacement with `crypto_check`, and some functions like `keccak256` and `sha3` are not directly supported. ```plaintext addmod(uint x, uint y, uint k) => (x + y) % k mulmod(uint x, uint y, uint k) => (x * y) % k sha256(bytes memory) => sha_256 ``` -------------------------------- ### Global Variables Source: https://github.com/madfish-solutions/sol2ligo/wiki/Feature-status Details the support status for global variables in Sol2Ligo. ```APIDOC ## Global Variables Support This section outlines the support status for global variables in Sol2Ligo. | Variable | LIGO | Michelson | Notes | |---|---|---|---| | `now` | yes | yes | yes | | `msg.sender` | yes | yes | yes | | `tx.origin` | yes | yes | yes | | `block.timestamp` | yes | yes | yes | ``` -------------------------------- ### Unsupported Address Type Members in Ligo Source: https://github.com/madfish-solutions/sol2ligo/wiki/Units-and-globally-available-variables Lists unsupported actions for address types in Ligo that are available in Solidity. ```plaintext
.send(uint256 amount)
.call(bytes memory)
.staticcall(bytes memory)
.delegatecall(bytes memory) ``` -------------------------------- ### Unsupported Block and Transaction Properties in Ligo Source: https://github.com/madfish-solutions/sol2ligo/wiki/Units-and-globally-available-variables Lists Solidity block and transaction properties that are not accessible or directly transpilable in Ligo. ```plaintext blockhash(uint blockNumber) block.blockhash(uint blockNumber) block.coinbase block.difficulty block.gaslimit block.number gasleft() msg.data msg.sig msg.gas tx.gasprice ``` -------------------------------- ### Address Type Members in Ligo Source: https://github.com/madfish-solutions/sol2ligo/wiki/Units-and-globally-available-variables Details the support for members of address types in Ligo, contrasting supported, partially supported, and unsupported actions from Solidity. ```plaintext
.transfer(uint256 amount) ``` -------------------------------- ### Resolve Solidity Imports with sol2ligo Source: https://context7.com/madfish-solutions/sol2ligo/llms.txt Use the import_resolver function to inline Solidity import statements from URLs or local paths. The import_cache parameter can preload external dependencies. ```javascript const sol2ligo = require("sol2ligo"); const fs = require("fs"); // Resolve imports from a Solidity file const resolvedCode = sol2ligo.import_resolver("./contracts/MyToken.sol", {}); // The import_cache parameter can preload external dependencies const import_cache = { "https://github.com/OpenZeppelin/contracts/SafeMath.sol": fs.readFileSync("./cached/SafeMath.sol", "utf-8") }; const resolvedWithCache = sol2ligo.import_resolver("./contracts/MyToken.sol", import_cache); // Use resolved code with compile const result = sol2ligo.compile(resolvedCode, { router: true }); console.log(result.ligo_code); ``` -------------------------------- ### Partially Supported Address Balance in Ligo Source: https://github.com/madfish-solutions/sol2ligo/wiki/Units-and-globally-available-variables Indicates that the balance of an address is supported in Ligo, but only for the current contract. ```plaintext
.balance => balance (of current contract only) ``` -------------------------------- ### Operator Support Source: https://github.com/madfish-solutions/sol2ligo/wiki/Feature-status Details the support status for unary, arithmetic, array, and other operators in Sol2Ligo. ```APIDOC ## Operator Support Overview This section outlines the support status for various operators in Sol2Ligo. ### Unary Operators | Operator | LIGO | Michelson | Notes | |---|---|---|---| | `!` | yes | yes | yes | | `-` | yes | yes | partially (-uint is vulnerability and will throw) | | `a++` | yes | partially | yes (need check fo all types) | | `a--` | yes | partially | yes (need check fo all types) | | `++a` | yes | partially | yes (need check fo all types) | | `--a` | yes | partially | yes (need check fo all types) | ### Arithmetic Binary Operators | Operator | LIGO | Michelson | Notes | |---|---|---|---| | `=` | yes | yes | partially (different types are not always supported) | | `+`, `-`, `*`, `/`, `%` | yes | yes | yes (need check fo all types) | | `&&`, `||` | yes | yes | partially (works ok only with bool) | | `==`, `!=` | yes | yes | partially (different types are not always supported) | | `<`, `<=`, `>`, `>=` | yes | yes | partially (bytes not supported) | | `<<`, `>>` | yes | yes | yes (only last LIGO builds) | | `**` | yes | no (TBD emulation) | no (not available in Michelson) | ### Array Operators | Operator | LIGO | Michelson | Notes | |---|---|---|---| | `a[b]` | yes | yes | partially (some accesses are not fully supported. Need recheck) | | `a.b` | yes | partially (TBD bug with structs) | yes | | `delete a[b]` | yes | yes | yes | ### Other Operators | Operator | LIGO | Michelson | Notes | |---|---|---|---| | Type cast | yes | partially | partially | | `new` | yes | partially | yes | | Array init (e.g. `[1,2,3]`) | yes | yes | yes | | Ternary (e.g. `a?b:c`) | yes | yes | yes | ``` -------------------------------- ### Unsupported Mathematical and Cryptographic Functions in Ligo Source: https://github.com/madfish-solutions/sol2ligo/wiki/Units-and-globally-available-variables Lists Solidity mathematical and cryptographic functions that are not directly supported in Ligo, with potential replacements noted. ```plaintext ecrecover(bytes msg, bytes32 v, bytes32 r, bytes32 s) => address (may be replaced with crypto_check(pk: key, signed: signature, msg: bytes) => bool) keccak256 ripemd160 sha3 (may be replaced with blake2b) ``` -------------------------------- ### Ligo Router Stub Generation Source: https://github.com/madfish-solutions/sol2ligo/wiki/Router Ligo automatically generates these stubs to handle method calls via a router. Each method is wrapped in an enum with a struct payload. ```pascal type method1_args is unit; type method2_args is unit; type router_enum is | Method1 of method1_args | Method2 of method2_args; function main (const action : router_enum; const self : state) : (list(operation) * state) is (case action of | Method1(match_action) -> method1(self) | Method2(match_action) -> method2(self) end); ``` -------------------------------- ### LIGO Crypto.check function Source: https://github.com/madfish-solutions/sol2ligo/wiki/Known-issues LIGO's `Crypto.check` function is a rough equivalent to Solidity's `ecrecover`. It verifies a signature against a hash and returns a boolean indicating success. The `signed` parameter in LIGO combines the `v`, `r`, and `s` components from Solidity. ```pascal Crypto.check (address, signed, hash) ``` -------------------------------- ### Cryptographic Functions API Source: https://github.com/madfish-solutions/sol2ligo/wiki/Feature-status Overview of supported cryptographic functions and their implementation status in Sol2Ligo. ```APIDOC ## Cryptographic Functions ### Description This section lists the cryptographic functions supported by Sol2Ligo and their respective implementation status. ### Functions - **sha256**: Supported - **sha3**: Partially supported (calls sha256) - **keccak256**: Partially supported (calls sha256) - **ripemd160**: Partially supported (calls blake2b) - **ecrecover**: Partially supported (pass-through) ``` -------------------------------- ### sol2ligo Compilation Output Source: https://github.com/madfish-solutions/sol2ligo/blob/pretty-ligo/README.md The object returned by the sol2ligo.compile function, containing compilation results. It includes any errors, warnings, the generated LIGO code, default state, and a flag indicating if deployment is prevented. ```javascript { errors: Array, warnings: Array, ligo_code: String, default_state: String, prevent_deploy: Boolean } ``` -------------------------------- ### Incorrect LIGO Transaction Attempt Source: https://github.com/madfish-solutions/sol2ligo/wiki/Foreign-contract-callback-stub An invalid attempt to treat a Tezos transaction as a synchronous return value. ```pascal (* incorrect code *) const b : nat = transaction(unit, 0tez, Tezos.get_entrypoint("%GetBalance", token))" ``` -------------------------------- ### Ether Units Convention in Ligo Source: https://github.com/madfish-solutions/sol2ligo/wiki/Units-and-globally-available-variables Defines the convention for ether units in Ligo, mapping mutez to szabo, finney, and ether for precision differences. ```plaintext szabo => 1mutez finney => 1_000mutez ether => 1_000_000mutez ``` -------------------------------- ### Solidity ecrecover function Source: https://github.com/madfish-solutions/sol2ligo/wiki/Known-issues The Solidity `ecrecover` function is used for cryptographic signature verification. It returns the address that signed the hash. ```solidity ecrecover(hash, v, r, s) == address ``` -------------------------------- ### Enum to Nat Conversion in LIGO Source: https://github.com/madfish-solutions/sol2ligo/wiki/CLI-usage When `--disable_enums_to_nat` is false (default), enums are translated to LIGO variant types. Setting this flag to true produces nat constants for each enum value, mimicking Solidity's behavior but sacrificing type safety. ```pascal const FIRST_ENUM_VAL : nat = 0; const SECOND_ENUM_VAL : nat = 1; ``` ```pascal type Enum_val of | FIRST_ENUM_VAL | SECOND_ENUM_VL ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.