string private constant _NAME = "OneSwap-Share"; uint8 private constant _DECIMALS = 18;In the code, the name of the ERC20 token is set by the constant_NAME, and the effective number of decimal places after the decimal point is set by_DECIMALS. As long as these constants are modified, the code can be applied to different occasions.
mapping (address => uint256) private _balances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private immutable _decimals; constructor (string memory name, string memory symbol, uint256 supply, uint8 decimals) public OneSwapBlackList() { _name = name; _symbol = symbol; _decimals = decimals; _totalSupply = supply; _balances[msg.sender] = supply; }The state variables_name,_symbol, and_decimals here are all assigned values only once in the constructor, and they are read-only during subsequent operations.
pragma solidity =0.6.12; contract ImmutableDemo { uint256 private constant _f0 = 0x1234; uint256 private immutable _f1 = 0x5678; uint256 private immutable _f2; uint256 private _f3; constructor(uint256 f2) public { _f2 = f2 & 0xABCD; _f3 = 0xEFEF; } function addF0(uint256 x) external pure returns (uint256) { return (x + _f0) & 0xFFFFFF00; } function addF1(uint256 x) external view returns (uint256) { return (x + _f1) & 0xFFFFFF01; } function addF2(uint256 x) external view returns (uint256) { return (x + _f2) & 0xFFFFFF02; } function addF3(uint256 x) external view returns (uint256) { return (x + _f3) & 0xFFFFFF03; } }The contract defines a total of 4 variables. Among them, _f0 is a known constant at compile time, _f1 and _f2 are invariables, and _f3 is an ordinary state variable. The value of _f1 is determined at compile time, and the value of _f2 is calculated through the parameters passed to the constructor when the contract is created. The value of _f3 is initialized when the contract is created. In addition to the constructor, the contract also defines 4 external methods. To facilitate the observation of the compiled bytecode of the contract, we used some special constants in these methods and performed simple calculations. In addition, the logic of these methods is very simple.
0x60c060405261567860809081525034801561001957600080fd5b506040516102a13803806102a18339818101604052602081101561003c57600080fd5b810190808051906020019092919050505061abcd811660a0818152505061efef6000819055505060805160a05161021b610086600039806101a8525080610176525061021b6000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c8063091ecb4e146100515780632183283914610093578063648dfa46146100d55780637217d1a014610117575b600080fd5b61007d6004803603602081101561006757600080fd5b8101908080359060200190929190505050610159565b6040518082815260200191505060405180910390f35b6100bf600480360360208110156100a957600080fd5b810190808035906020019092919050505061016d565b6040518082815260200191505060405180910390f35b610101600480360360208110156100eb57600080fd5b810190808035906020019092919050505061019f565b6040518082815260200191505060405180910390f35b6101436004803603602081101561012d57600080fd5b81019080803590602001909291905050506101d1565b6040518082815260200191505060405180910390f35b600063ffffff006112348301169050919050565b600063ffffff017f00000000000000000000000000000000000000000000000000000000000000008301169050919050565b600063ffffff027f00000000000000000000000000000000000000000000000000000000000000008301169050919050565b600063ffffff03600054830116905091905056fea2646970667358221220f2e74694c1ee966e6985b7d31032343ce592dc88a10f9359fa6a42fdbeff1cbe64736f6c634300060c0033The runtime code of the contract starts from the 134th (0x86) byte and totals 539 (0x21B) bytes, as shown below:
0x608060405234801561001057600080fd5b506004361061004c5760003560e01c8063091ecb4e146100515780632183283914610093578063648dfa46146100d55780637217d1a014610117575b600080fd5b61007d6004803603602081101561006757600080fd5b8101908080359060200190929190505050610159565b6040518082815260200191505060405180910390f35b6100bf600480360360208110156100a957600080fd5b810190808035906020019092919050505061016d565b6040518082815260200191505060405180910390f35b610101600480360360208110156100eb57600080fd5b810190808035906020019092919050505061019f565b6040518082815260200191505060405180910390f35b6101436004803603602081101561012d57600080fd5b81019080803590602001909291905050506101d1565b6040518082815260200191505060405180910390f35b600063ffffff006112348301169050919050565b600063ffffff017f00000000000000000000000000000000000000000000000000000000000000008301169050919050565b600063ffffff027f00000000000000000000000000000000000000000000000000000000000000008301169050919050565b600063ffffff03600054830116905091905056fea2646970667358221220f2e74694c1ee966e6985b7d31032343ce592dc88a10f9359fa6a42fdbeff1cbe64736f6c634300060c0033Below we will carefully analyze these two bytecodes to see how the invariables work.
... [345] JUMPDEST [346] PUSH1 0x00 [348] PUSH4 0xffffff00 [353] PUSH2 0x1234 [356] DUP4 [357] ADD [358] AND ... [365] JUMPDEST [366] PUSH1 0x00 [368] PUSH4 0xffffff01 [373] PUSH32 0x0000000000000000000000000000000000000000000000000000000000000000 [406] DUP4 [407] ADD [408] AND ... [415] JUMPDEST [416] PUSH1 0x00 [418] PUSH4 0xffffff02 [423] PUSH32 0x0000000000000000000000000000000000000000000000000000000000000000 [456] DUP4 [457] ADD [458] AND ... [465] JUMPDEST [466] PUSH1 0x00 [468] PUSH4 0xffffff03 [473] PUSH1 0x00 [475] SLOAD [476] DUP4 [477] ADD [478] AND ...Obviously,
contract disassembler { function main() public return () { mstore(0x40,0xC0); mstore(0x80,0x5678); var0 = msg.value; require(!msg.value); var1 = (code.size - 0x2A1); callcodecopy(0xC0,0x2A1,(code.size - 0x2A1)); mstore(0x40,((code.size - 0x2A1) + 0xC0)); require((0x20 < (code.size - 0x2A1))); temp0 = (0xC0 + var1); temp1 = mload(0xC0); mstore(0xA0,(temp1 & 0xABCD)); sstore(0x0,0xEFEF); temp3 = mload(0x80); temp2 = mload(0xA0); callcodecopy(0x0,0x86,0x21B); mstore(0x1A8,temp2); mstore(0x176,temp3); RETURN(0x0,0x21B); } }Compared with the bytecode and assembly code, it is already an improvement. Still hard to understand? Don't worry. We will add comments to the disassembly code above, remove the irrelevant code, rename some variables, and explain each line of code in detail.
function main() public return () { mstore(0x40,0xC0); // m[0x40] = 0xC0 mstore(0x80,0x5678); // m[0x80] = 0x5678 require(!msg.value);Line 1 above: The compiler reserves 0xC0 bytes of memory, and records this number in memory 0x40. Line 2: Record 0x5678 in memory 0x80. Line 3 has nothing to do with the discussion in this article and can be ignored.
argsLen = (code.size - 0x2A1); callcodecopy(0xC0,0x2A1,argsLen); // m[0xC0] = args mstore(0x40,(argsLen + 0xC0)); // m[0x40] = 0xC0 + argsLen require((0x20 < argsLen));Line 1: When the contract is deployed, the parameters passed to the constructor (after ABI encoding) will be spliced behind the bytecode. We can obtain the total length of the code after adding the parameter with the CODESIZE instruction, and, after subtracting the real code length 0x2A1, get the length of the parameter. Line 2: Copy the incoming parameters to 0xC0 in the memory. Line 3: Update the number of memory usage. Line 4: Ensure the length of the incoming parameter is sufficient.
f2 = mload(0xC0); // f2 = m[0xC0] mstore(0xA0,(f2 & 0xABCD)); // m[0xA0] = f2 & 0xABCD sstore(0x0,0xEFEF); // _f3 = 0xEFEFLine 1: Load the parameter f2 that has been loaded into the memory onto the operand stack. Line 2: Perform a bitwise AND operation between f2 and 0xABCD, and then record it in memory 0xA0. Line 3: Initialize the state variable_f3.
_f1 = mload(0x80); // _f1 = m[0x80] = 0x5678 _f2 = mload(0xA0); // _f2 = m[0xA0] = f2 & 0xABCD callcodecopy(0x0,0x86,0x21B); // m[0x00:] = code[0x86: 0x86+0x21B] mstore(0x1A8,_f2); // m[0x01A8] = _f2 mstore(0x176,_f1); // m[0x0176] = _f1 RETURN(0x0,0x21B); }The first and second lines above load the values at memory 0x80 and 0xA0 onto the operand stack. These two temporary variables record the actual values of _f1 and _f2. Then the value previously placed in memory is completely useless, so on the third line all the runtime bytecodes are copied to memory 0. On Lines 4 and 5, the immediate placeholders of PUSH instructions of two invariables in the runtime bytecode (located at 0x0176 and 0x01A8 in the runtime bytecode, respectively) are replaced with actual values. At this point, the runtime bytecode is ready, and then returns on Line 6 through the RETURN instruction. The following is the complete disassembly code after being adjusted with comments:
contract disassembler { function main() public return () { mstore(0x40,0xC0); // m[0x40] = 0xC0 mstore(0x80,0x5678); // m[0x80] = 0x5678 require(!msg.value); argsLen = (code.size - 0x2A1); callcodecopy(0xC0,0x2A1,argsLen); // m[0xC0] = args mstore(0x40,(argsLen + 0xC0)); // m[0x40] = 0xC0 + argsLen require((0x20 < argsLen)); f2 = mload(0xC0); // f2 = m[0xC0] mstore(0xA0,(f2 & 0xABCD)); // m[0xA0] = f2 & 0xABCD sstore(0x0,0xEFEF); // _f3 = 0xEFEF _f1 = mload(0x80); // _f1 = m[0x80] = 0x5678 _f2 = mload(0xA0); // _f2 = m[0xA0] = f2 & 0xABCD callcodecopy(0x0,0x86,0x21B); // m[0x00:] = code[0x86: 0x86+0x21B] mstore(0x1A8,_f2); // m[0x01A8] = _f2 mstore(0x176,_f1); // m[0x0176] = _f1 RETURN(0x0,0x21B); } }
contract OneSwapPairProxy { uint internal _unlocked; uint internal immutable _immuFactory; uint internal immutable _immuMoneyToken; uint internal immutable _immuStockToken; uint internal immutable _immuOnes; uint internal immutable _immuOther; constructor(address stockToken, address moneyToken, bool isOnlySwap, uint64 stockUnit, uint64 priceMul, uint64 priceDiv, address ones) public { _immuFactory = uint(msg.sender); _immuMoneyToken = uint(moneyToken); _immuStockToken = uint(stockToken); _immuOnes = uint(ones); uint temp = isOnlySwap ? 1 : 0; temp = (temp<<64) | stockUnit; temp = (temp<<64) | priceMul; temp = (temp<<64) | priceDiv; _immuOther = temp; _unlocked = 1; } receive() external payable { } fallback() payable external { /* code omitted */ } }Similar to Uniswap, OneSwap's Pair contract is created by the Factory contract. The difference is that OneSwap adopts a proxy model in order to minimize the gas consumption when a Pair is created. Considering the complex logic of Pair and the gas-consuming deployment, OneSwap puts this part of the logic in the OneSwapPair contract which needs to be deployed only once. The Factory deploys the OneSwapPairProxy contract each time, which forwards all actual operations to OneSwapPair for processing. With the proxy mode, OneSwap also supports the upgrade of the Pair logic. In addition, to benefit from both the invariable and proxy mode at the same time, the OneSwap project has also explored the "Immutable Forwading" mode, which we will specifically introduce in a follow-up article.
contract OneSwapBuyback is IOneSwapBuyback { mapping (address => bool) private _mainTokens; address[] private _mainTokenArr; ... // Other codes omitted function addMainToken(address token) external override { require(msg.sender == IOneSwapToken(ones).owner()); if (!_mainTokens[token]) { _mainTokens[token] = true; _mainTokenArr.push(token); } } function removeMainToken(address token) external override { require(msg.sender == IOneSwapToken(ones).owner()); if (_mainTokens[token]) { _mainTokens[token] = false; uint256 lastIdx = _mainTokenArr.length - 1; for (uint256 i = 0; i < lastIdx; i++) { if (_mainTokenArr[i] == token) { _mainTokenArr[i] = _mainTokenArr[lastIdx]; break; } } _mainTokenArr.pop(); } } }The feeBPS and pairLogic variables of the OneSwapFactory contract are configured through the OneSwapGov contract. The feeBPS variable is read by the OneSwapPair contract to control the fee rate. The pairLogic variable is read by the OneSwapProxy contract. This variable and dynamic configuration is a major contributor to the negligible gas consumed by the Pair deployment and upgradeable Pair logic of the OneSwap project.
![]() | Blockchain has completed its journey of a decade. In this span, despite facing a lot of resilience, technology has overcome all the challenges and become one of the leading technologies. As per Upwork, Blockchain was one of the fastest-growing skills in 2008. Knowing its importance and growth that it has to offer, many individuals are now opting for Blockchain courses. There are specified Blockchain courses for Blockchain developer, Blockchain engineer, and other associated profiles. You can pick the one you interest you and start the journey to become a successful blockchain developer. While you pick up the Blockchain training, it also becomes crucial that you must acquire the knowledge about Blockchain tools. In this blog, we will discuss ten different Blockchain tools that will help you become a proficient Blockchain developer. submitted by Blockchain_org to BlockchainStartups [link] [comments] https://preview.redd.it/98ir6txo1jf51.jpg?width=1280&format=pjpg&auto=webp&s=7d0e5e32f552febd9084afae29c79c29cc7b5a7d Top 10 Blockchain tools: 1. Geth- The first tool that we are discussing here is Geth; it is an implementation of Ethereym node and is written in the Go programming language. It acts as a node for Ethereum Blockchain. One can easily mine token, transfer the tokens, and also create smart contracts using Geth. 2. Solidity- if you are planning to become an Ethereum expert, you must have expertise in Solidity. It is one of the most popular programming languages. It supports the OOP paradigm and is mostly used for writing smart contracts. Blockchain developers can use Solidity to write applications. It is useful in creating contracts for voting, multi-signature wallet, and blind auctions. 3. Mist- This is the official Ethereum wallet that is available on Windows, Mac, and Linux. One of the key things you must know about Mist is that once you have created the password for it, you have to remember it, as you cannot change it. 4. Solc- or Solidity Compiler is written in C++. It converts solidity scripts into a more readable format. The smart contracts written in Solidity must be converted into a format that can be easily read by the EVM, and here Solc comes into the picture. 5. Remix- It is a browser-based Blockchain tool. This is also used for the creation of smart contracts. This one is written in Javascript. It is used for testing, troubleshooting, and debugging the smart contracts written in Solidity. 6. Metamask- It is a wallet which acts as a connecting line between a browser and Ethereum Blockchain. It acts as a browser extension. 7. Truffle- It is an Ethereum Blockchain framework used to create a development environment for developing applications based on Ethereum. Blockchain developers can access a vast library. This is used for developing complex Ethereum dApps. It can also perform automated contract testing using Mocha and Chain. 8. Ganache- You can create a private Blockchain using this tool. This can be used to test dApps and execute commands. 9. Blockchain Testnet- Blockchain developers develop apps, but it’s important for them to check if the app is free from error or not, with the help of Blockchain Testnet, you can test the applications before making them go live. You can check for the bugs or other errors. 10. Blockchain-as-a-Service (BaaS)- This works similarly as that of SaaS. You can leverage cloud-based solutions to build and hose custom-made Blockchain applications. Wrapping up- These were some of the important Blockchain tools. If you are planning to enroll in Blockchain training, you must also develop expertise in using these tools. They will help in better implementation of technology. Moreover, with the right set of skills, you also become eligible for a better Blockchain developer salary. Blockchain development is not just about learning the concepts. Still, it is also about implementing the concepts; Blockchain Council is the platform that will provide you all the information and knowledge about Blockchain courses. If you wish to become an expert Blockchain developer, Blockchain certification will give you the right direction. |
Unfortunately, the official Ethereum documentation has not been updated to reflect the fact that compiling using the solC compiler is no longer possible via RPC. This means that you will end up in a rabbit hole if you try to follow the instructions on the official Ethereum documentation and many other tutorials based on official documentation. npm install solc 그리고 geth 폴더에서 ./geth –testnet –datadir ./chaindata6 console > eth.getCompilers() [] 결과가 solidity 가 나와야 한다. brew tap ethereum/ethereum brew install solidity which sol… A Python implementation of the Ethereum Virtual Machine https://trinity.ethereum.org/ Container. 100K+ Downloads. 0 Stars. ethereum/solidity-buildpack-deps The assertion is clearly false, and an assertion failure warning should be returned.. Low-level API. The low-level API is as follows: solc.lowlevel.compileSingle: the original entry point, supports only a single file; solc.lowlevel.compileMulti: this supports multiple files, introduced in 0.1.6; solc.lowlevel.compileCallback: this supports callbacks, introduced in 0.2.1 Friends, From our team to you and yours, we hope everyone and their families are well and keeping safe during these complicated weeks. To help pass some time while we’re all stuck in doors, it’s time again to update the community on progress made by some of the EF-supported projects not covered in last week’s ESP Allocation Update.While the last Winter edition in this series was posted ...
[index] [3292] [3077] [906] [6841] [5208] [822] [5392] [4443] [6413] [5704]
Ethereum Classic (ETC) was 51% attacked in the past few days with a major block reorganization, according to Coinbase and other sources. What does it mean for #ETC, what does it mean for other ... 1BestCsharp blog Recommended for you 44:14 3 Compile and run your first smart contract against local private node - Ethereum from scratch - Duration: 32:42. Vous aurez maintenant une idée de la puissance de l'Ethereum et la différence entre ce dernier avec l'Ethereum Classic. Je compte sur vous pour déposer un pe... This screencast describes the process of making two of Ethereum's language compilers available to a developer. The work is all done at an Ubuntu command line. It starts at the point following a ... In this the first part of a series of videos we describe an experimental VS Code extension for Solidity programs that makes greater use of solc's AST and uses a library that I hope will become the ...