From a6ea8b12239cb1418817603bcef634153b148814 Mon Sep 17 00:00:00 2001 From: JackLee <280147597@qq.com> Date: Fri, 15 Mar 2024 22:45:13 +0800 Subject: [PATCH 1/4] update general/conflux-basics/glossary.md, regarding the issue #455 --- docs/general/conflux-basics/glossary.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/general/conflux-basics/glossary.md b/docs/general/conflux-basics/glossary.md index b51bb501ae..10a16b9bf9 100644 --- a/docs/general/conflux-basics/glossary.md +++ b/docs/general/conflux-basics/glossary.md @@ -98,6 +98,9 @@ ERC20 is a standard for tokens on the Ethereum blockchain. It specifies a set of ### **ERC721** ERC721 is a standard for non-fungible tokens (NFTs) on the Ethereum blockchain. Unlike ERC20 tokens, which are identical to each other, each ERC721 token is unique. This makes them suitable for representing ownership of unique items or assets. Like ERC20, ERC721 tokens can also exist on the Conflux network, especially if they are transferred from the Ethereum network. +### **ERC1155** +ERC1155 is a Ethereum token standard that supports multiple token types, including fungible and non-fungible tokens, within a single contract. This reduces transaction costs by enabling batch transfers and offers complex access controls. ERC1155 tokens can also exist on the Conflux network, enhancing flexibility and interoperability for digital assets in gaming, art, and beyond. + ### **Fork** A fork in a blockchain system denotes a split or divergence in the chain, originating from a common point with a shared history and creating two distinct paths. They can be implemented intentionally via software updates to either bring about significant changes (hard fork) or introduce backward-compatible alterations (soft fork). However, forks can also occur organically due to simultaneous block creation or as a result of network latencies and block propagation delays. From 2722691c929aa1ad0ef9f6ee66bb7fb16ce1168b Mon Sep 17 00:00:00 2001 From: Jack Lee <280147597@qq.com> Date: Mon, 18 Mar 2024 11:20:11 +0800 Subject: [PATCH 2/4] Update docs/general/conflux-basics/glossary.md Co-authored-by: darwintree <17946284+darwintree@users.noreply.github.com> --- docs/general/conflux-basics/glossary.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/general/conflux-basics/glossary.md b/docs/general/conflux-basics/glossary.md index 10a16b9bf9..0eed4bc23e 100644 --- a/docs/general/conflux-basics/glossary.md +++ b/docs/general/conflux-basics/glossary.md @@ -99,7 +99,7 @@ ERC20 is a standard for tokens on the Ethereum blockchain. It specifies a set of ERC721 is a standard for non-fungible tokens (NFTs) on the Ethereum blockchain. Unlike ERC20 tokens, which are identical to each other, each ERC721 token is unique. This makes them suitable for representing ownership of unique items or assets. Like ERC20, ERC721 tokens can also exist on the Conflux network, especially if they are transferred from the Ethereum network. ### **ERC1155** -ERC1155 is a Ethereum token standard that supports multiple token types, including fungible and non-fungible tokens, within a single contract. This reduces transaction costs by enabling batch transfers and offers complex access controls. ERC1155 tokens can also exist on the Conflux network, enhancing flexibility and interoperability for digital assets in gaming, art, and beyond. +ERC1155 is an Ethereum token standard that supports multiple token types, including fungible and non-fungible tokens, within a single contract. This reduces transaction costs by enabling batch transfers and offers complex access controls. ERC1155 tokens can also exist on the Conflux network, enhancing flexibility and interoperability for digital assets in gaming, art, and beyond. ### **Fork** From e306cb66ffc7876aa81ac8869a4b51333a6c8422 Mon Sep 17 00:00:00 2001 From: Jack Lee <280147597@qq.com> Date: Mon, 18 Mar 2024 11:31:17 +0800 Subject: [PATCH 3/4] Update glossary.md --- docs/general/conflux-basics/glossary.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/general/conflux-basics/glossary.md b/docs/general/conflux-basics/glossary.md index 0eed4bc23e..6c1e3b4ae1 100644 --- a/docs/general/conflux-basics/glossary.md +++ b/docs/general/conflux-basics/glossary.md @@ -99,7 +99,7 @@ ERC20 is a standard for tokens on the Ethereum blockchain. It specifies a set of ERC721 is a standard for non-fungible tokens (NFTs) on the Ethereum blockchain. Unlike ERC20 tokens, which are identical to each other, each ERC721 token is unique. This makes them suitable for representing ownership of unique items or assets. Like ERC20, ERC721 tokens can also exist on the Conflux network, especially if they are transferred from the Ethereum network. ### **ERC1155** -ERC1155 is an Ethereum token standard that supports multiple token types, including fungible and non-fungible tokens, within a single contract. This reduces transaction costs by enabling batch transfers and offers complex access controls. ERC1155 tokens can also exist on the Conflux network, enhancing flexibility and interoperability for digital assets in gaming, art, and beyond. +ERC1155 is an Ethereum token standard that supports multiple token types, including fungible and non-fungible tokens, within a single contract. By enabling batch transfers, it efficiently reduces transaction costs. ERC1155 tokens can also exist on the Conflux network, enhancing flexibility and interoperability for digital assets in gaming, art, and beyond. ### **Fork** From ced442f33a86df7371ca78375ac2793316ff6bd7 Mon Sep 17 00:00:00 2001 From: JackLee <280147597@qq.com> Date: Tue, 2 Apr 2024 21:04:07 +0800 Subject: [PATCH 4/4] add Comparison Operators --- .../gas-optimization/LessThan.md | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docs/general/build/smart-contracts/gas-optimization/LessThan.md diff --git a/docs/general/build/smart-contracts/gas-optimization/LessThan.md b/docs/general/build/smart-contracts/gas-optimization/LessThan.md new file mode 100644 index 0000000000..68eebce679 --- /dev/null +++ b/docs/general/build/smart-contracts/gas-optimization/LessThan.md @@ -0,0 +1,36 @@ +--- +displayed_sidebar: generalSidebar +--- + +# Comparison Operators + +In the Ethereum Virtual Machine (EVM), the selection of comparison operators influences the efficiency and gas consumption of smart contracts. Opting for `<` (less than) and `>` (greater than) over `≤` (less than or equal to) and `≥` (greater than or equal to) is notably more gas-efficient. This is due to the absence of direct opcode instructions for `≤` and `≥` in the EVM's design, which requires additional operations to achieve these comparisons. + +Given that iszero consumes 3 units of gas, utilizing `≤` and `≥` in contracts that frequently perform comparisons can lead to increased gas expenditures. + +**DemoCode** + +Below are examples of code achieving the same result using `<` and `<=`, respectively. + +```solidity +contract CompareLessThan { + // gas: 247 + function isSmallerThan(uint256 value) external pure returns (bool) { + return value < 8; + } +} + +contract CompareLessThanOrEqual { + // gas: 250 + function isSmallerThanOrEqual(uint256 value) external pure returns (bool) { + return value <= 7; + } +} +``` + +Assuming `value` is 7, both functions will return the same result. However, the `<` operator will be more gas-efficient than the `<=` operator. + + +Recommendations for gas optimization: + +🌟 Using the `<` and `>` operators is more gas-efficient than `<=` and `>=` in smart contracts. \ No newline at end of file