Solidity language preview
1. NatSpec comments
/// @title, @notice, @param
horizon-dark
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title A simple counter
/// @notice Stores a number that anyone can increment
contract Counter {
uint256 public count;
/// @param amount the value to add
function increment(uint256 amount) external {
count += amount;
emit Incremented(msg.sender, amount);
}
event Incremented(address indexed by, uint256 amount);
} atom-one-dark
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title A simple counter
/// @notice Stores a number that anyone can increment
contract Counter {
uint256 public count;
/// @param amount the value to add
function increment(uint256 amount) external {
count += amount;
emit Incremented(msg.sender, amount);
}
event Incremented(address indexed by, uint256 amount);
} github-dark
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title A simple counter
/// @notice Stores a number that anyone can increment
contract Counter {
uint256 public count;
/// @param amount the value to add
function increment(uint256 amount) external {
count += amount;
emit Incremented(msg.sender, amount);
}
event Incremented(address indexed by, uint256 amount);
} dracula
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title A simple counter
/// @notice Stores a number that anyone can increment
contract Counter {
uint256 public count;
/// @param amount the value to add
function increment(uint256 amount) external {
count += amount;
emit Incremented(msg.sender, amount);
}
event Incremented(address indexed by, uint256 amount);
} nord
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title A simple counter
/// @notice Stores a number that anyone can increment
contract Counter {
uint256 public count;
/// @param amount the value to add
function increment(uint256 amount) external {
count += amount;
emit Incremented(msg.sender, amount);
}
event Incremented(address indexed by, uint256 amount);
} github
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title A simple counter
/// @notice Stores a number that anyone can increment
contract Counter {
uint256 public count;
/// @param amount the value to add
function increment(uint256 amount) external {
count += amount;
emit Incremented(msg.sender, amount);
}
event Incremented(address indexed by, uint256 amount);
} 2. Mappings and modifiers
uint8, bytes32, mapping, modifier, require
horizon-dark
pragma solidity ^0.8.24;
contract Token {
mapping(address => uint256) private _balances;
uint8 public constant decimals = 18;
bytes32 public constant MAGIC = 0x1234_5678;
bytes32 public immutable salt;
address payable public owner;
modifier onlyOwner() {
require(msg.sender == owner, "not owner");
_;
}
function transfer(address to, uint256 amount)
public
returns (bool success)
{
require(_balances[msg.sender] >= amount, "insufficient");
_balances[msg.sender] -= amount;
_balances[to] += amount;
return true;
}
} atom-one-dark
pragma solidity ^0.8.24;
contract Token {
mapping(address => uint256) private _balances;
uint8 public constant decimals = 18;
bytes32 public constant MAGIC = 0x1234_5678;
bytes32 public immutable salt;
address payable public owner;
modifier onlyOwner() {
require(msg.sender == owner, "not owner");
_;
}
function transfer(address to, uint256 amount)
public
returns (bool success)
{
require(_balances[msg.sender] >= amount, "insufficient");
_balances[msg.sender] -= amount;
_balances[to] += amount;
return true;
}
} github-dark
pragma solidity ^0.8.24;
contract Token {
mapping(address => uint256) private _balances;
uint8 public constant decimals = 18;
bytes32 public constant MAGIC = 0x1234_5678;
bytes32 public immutable salt;
address payable public owner;
modifier onlyOwner() {
require(msg.sender == owner, "not owner");
_;
}
function transfer(address to, uint256 amount)
public
returns (bool success)
{
require(_balances[msg.sender] >= amount, "insufficient");
_balances[msg.sender] -= amount;
_balances[to] += amount;
return true;
}
} dracula
pragma solidity ^0.8.24;
contract Token {
mapping(address => uint256) private _balances;
uint8 public constant decimals = 18;
bytes32 public constant MAGIC = 0x1234_5678;
bytes32 public immutable salt;
address payable public owner;
modifier onlyOwner() {
require(msg.sender == owner, "not owner");
_;
}
function transfer(address to, uint256 amount)
public
returns (bool success)
{
require(_balances[msg.sender] >= amount, "insufficient");
_balances[msg.sender] -= amount;
_balances[to] += amount;
return true;
}
} nord
pragma solidity ^0.8.24;
contract Token {
mapping(address => uint256) private _balances;
uint8 public constant decimals = 18;
bytes32 public constant MAGIC = 0x1234_5678;
bytes32 public immutable salt;
address payable public owner;
modifier onlyOwner() {
require(msg.sender == owner, "not owner");
_;
}
function transfer(address to, uint256 amount)
public
returns (bool success)
{
require(_balances[msg.sender] >= amount, "insufficient");
_balances[msg.sender] -= amount;
_balances[to] += amount;
return true;
}
} github
pragma solidity ^0.8.24;
contract Token {
mapping(address => uint256) private _balances;
uint8 public constant decimals = 18;
bytes32 public constant MAGIC = 0x1234_5678;
bytes32 public immutable salt;
address payable public owner;
modifier onlyOwner() {
require(msg.sender == owner, "not owner");
_;
}
function transfer(address to, uint256 amount)
public
returns (bool success)
{
require(_balances[msg.sender] >= amount, "insufficient");
_balances[msg.sender] -= amount;
_balances[to] += amount;
return true;
}
} 3. Modular arithmetic builtins
addmod, mulmod, and keccak256 globals
horizon-dark
pragma solidity ^0.8.24;
contract ModExp {
function powMod(uint256 base, uint256 exp, uint256 m) public pure returns (uint256 result) {
result = 1;
base = base % m;
while (exp > 0) {
if (exp % 2 == 1) {
result = mulmod(result, base, m);
}
base = mulmod(base, base, m);
exp /= 2;
}
}
function commitmentHash(uint256 a, uint256 b, uint256 m) public pure returns (bytes32) {
return keccak256(abi.encodePacked(addmod(a, b, m)));
}
} atom-one-dark
pragma solidity ^0.8.24;
contract ModExp {
function powMod(uint256 base, uint256 exp, uint256 m) public pure returns (uint256 result) {
result = 1;
base = base % m;
while (exp > 0) {
if (exp % 2 == 1) {
result = mulmod(result, base, m);
}
base = mulmod(base, base, m);
exp /= 2;
}
}
function commitmentHash(uint256 a, uint256 b, uint256 m) public pure returns (bytes32) {
return keccak256(abi.encodePacked(addmod(a, b, m)));
}
} github-dark
pragma solidity ^0.8.24;
contract ModExp {
function powMod(uint256 base, uint256 exp, uint256 m) public pure returns (uint256 result) {
result = 1;
base = base % m;
while (exp > 0) {
if (exp % 2 == 1) {
result = mulmod(result, base, m);
}
base = mulmod(base, base, m);
exp /= 2;
}
}
function commitmentHash(uint256 a, uint256 b, uint256 m) public pure returns (bytes32) {
return keccak256(abi.encodePacked(addmod(a, b, m)));
}
} dracula
pragma solidity ^0.8.24;
contract ModExp {
function powMod(uint256 base, uint256 exp, uint256 m) public pure returns (uint256 result) {
result = 1;
base = base % m;
while (exp > 0) {
if (exp % 2 == 1) {
result = mulmod(result, base, m);
}
base = mulmod(base, base, m);
exp /= 2;
}
}
function commitmentHash(uint256 a, uint256 b, uint256 m) public pure returns (bytes32) {
return keccak256(abi.encodePacked(addmod(a, b, m)));
}
} nord
pragma solidity ^0.8.24;
contract ModExp {
function powMod(uint256 base, uint256 exp, uint256 m) public pure returns (uint256 result) {
result = 1;
base = base % m;
while (exp > 0) {
if (exp % 2 == 1) {
result = mulmod(result, base, m);
}
base = mulmod(base, base, m);
exp /= 2;
}
}
function commitmentHash(uint256 a, uint256 b, uint256 m) public pure returns (bytes32) {
return keccak256(abi.encodePacked(addmod(a, b, m)));
}
} github
pragma solidity ^0.8.24;
contract ModExp {
function powMod(uint256 base, uint256 exp, uint256 m) public pure returns (uint256 result) {
result = 1;
base = base % m;
while (exp > 0) {
if (exp % 2 == 1) {
result = mulmod(result, base, m);
}
base = mulmod(base, base, m);
exp /= 2;
}
}
function commitmentHash(uint256 a, uint256 b, uint256 m) public pure returns (bytes32) {
return keccak256(abi.encodePacked(addmod(a, b, m)));
}
} 4. Interface and library
interface, library, is, ether, assembly
horizon-dark
pragma solidity ^0.8.24;
interface IERC20 {
function totalSupply() external view returns (uint256);
}
library Math {
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
}
contract Vault is IERC20, Ownable {
using Math for uint256;
uint256 public totalSupply = 1_000 ether;
uint256 public lockUntil = block.timestamp + 30 days;
function totalSupply() external view returns (uint256) {
uint256 free;
assembly {
free := sload(0)
}
return free;
}
} atom-one-dark
pragma solidity ^0.8.24;
interface IERC20 {
function totalSupply() external view returns (uint256);
}
library Math {
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
}
contract Vault is IERC20, Ownable {
using Math for uint256;
uint256 public totalSupply = 1_000 ether;
uint256 public lockUntil = block.timestamp + 30 days;
function totalSupply() external view returns (uint256) {
uint256 free;
assembly {
free := sload(0)
}
return free;
}
} github-dark
pragma solidity ^0.8.24;
interface IERC20 {
function totalSupply() external view returns (uint256);
}
library Math {
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
}
contract Vault is IERC20, Ownable {
using Math for uint256;
uint256 public totalSupply = 1_000 ether;
uint256 public lockUntil = block.timestamp + 30 days;
function totalSupply() external view returns (uint256) {
uint256 free;
assembly {
free := sload(0)
}
return free;
}
} dracula
pragma solidity ^0.8.24;
interface IERC20 {
function totalSupply() external view returns (uint256);
}
library Math {
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
}
contract Vault is IERC20, Ownable {
using Math for uint256;
uint256 public totalSupply = 1_000 ether;
uint256 public lockUntil = block.timestamp + 30 days;
function totalSupply() external view returns (uint256) {
uint256 free;
assembly {
free := sload(0)
}
return free;
}
} nord
pragma solidity ^0.8.24;
interface IERC20 {
function totalSupply() external view returns (uint256);
}
library Math {
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
}
contract Vault is IERC20, Ownable {
using Math for uint256;
uint256 public totalSupply = 1_000 ether;
uint256 public lockUntil = block.timestamp + 30 days;
function totalSupply() external view returns (uint256) {
uint256 free;
assembly {
free := sload(0)
}
return free;
}
} github
pragma solidity ^0.8.24;
interface IERC20 {
function totalSupply() external view returns (uint256);
}
library Math {
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
}
contract Vault is IERC20, Ownable {
using Math for uint256;
uint256 public totalSupply = 1_000 ether;
uint256 public lockUntil = block.timestamp + 30 days;
function totalSupply() external view returns (uint256) {
uint256 free;
assembly {
free := sload(0)
}
return free;
}
}