Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/idouble/ethereum-solidity-inline-assembly
π A Collection of Notes & Knowledge about Solidity inline Assembly π§
https://github.com/idouble/ethereum-solidity-inline-assembly
blockchain blockchain-technology eth ethereum ethereum-assembly ethereum-blockchain ethereum-contract ethereum-inline-assembly smart-contract smart-contract-template smart-contracts solidity solidity-assembly solidity-inline-assembly solidity-language
Last synced: about 1 month ago
JSON representation
π A Collection of Notes & Knowledge about Solidity inline Assembly π§
- Host: GitHub
- URL: https://github.com/idouble/ethereum-solidity-inline-assembly
- Owner: IDouble
- License: mit
- Created: 2019-10-18T21:36:58.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-29T16:46:40.000Z (9 months ago)
- Last Synced: 2024-10-13T01:20:43.137Z (about 1 month ago)
- Topics: blockchain, blockchain-technology, eth, ethereum, ethereum-assembly, ethereum-blockchain, ethereum-contract, ethereum-inline-assembly, smart-contract, smart-contract-template, smart-contracts, solidity, solidity-assembly, solidity-inline-assembly, solidity-language
- Language: Solidity
- Homepage:
- Size: 680 KB
- Stars: 28
- Watchers: 3
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# π Ethereum Solidity inline Assembly π§
π A Collection of Notes & Knowledge about Solidity inline Assembly π§## What is Solidity inline Assembly β
Solidity defines an assembly language that you can use without Solidity and also as β**inline assembly**β **inside Solidity source code**.You can interleave Solidity statements with inline assembly in a language close to the one of the **Ethereum Virtual Machine (EVM)**.
As the **Ethereum Virtual Machine (EVM) is a stack machine**, it is often hard to address the correct stack slot and provide arguments to opcodes at the correct point on the stack. Solidityβs inline assembly helps you do this, and with other issues that arise when writing manual assembly.
## GetCode π
```
pragma solidity ^0.4.0;library GetCode {
function at(address _addr) public view returns (bytes o_code) {
assembly {
// retrieve the size of the code, this needs assembly
let size := extcodesize(_addr)
// allocate output byte array - this could also be done without assembly
// by using o_code = new bytes(size)
o_code := mload(0x40)
// new "memory end" including padding
mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f))))
// store length in memory
mstore(o_code, size)
// actually retrieve the code, this needs assembly
extcodecopy(_addr, add(o_code, 0x20), 0, size)
}
}
}
```
## sumPureAsm π§
```
pragma solidity ^0.4.16;library VectorSum {
function sumPureAsm(uint[] _data) public view returns (uint o_sum) {
assembly {
// Load the length (first 32 bytes)
let len := mload(_data)// Skip over the length field.
// Keep temporary variable so it can be incremented in place.
// NOTE: incrementing _data would result in an unusable
// _data variable after this assembly block
let data := add(_data, 0x20)// Iterate until the bound is not met.
for
{ let end := add(data, len) }
lt(data, end)
{ data := add(data, 0x20) }
{
o_sum := add(o_sum, mload(data))
}
}
}
}
```![Binance Ready to give crypto a try ? buy bitcoin and other cryptocurrencies on binance](Images/binance.jpg)