-
Notifications
You must be signed in to change notification settings - Fork 22
add Inline assembly solidity challenge #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Elli610
wants to merge
5
commits into
LevelUpWeb3:main
Choose a base branch
from
Elli610:inline-assembly
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
public/data/contents/exploring-solidity-objects-address-part-1.json
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
public/data/contents/exploring-solidity-objects-address-part-2.json
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| --- | ||
| name: Inline Assembly | ||
| index: 26 | ||
| lesson: 26 | ||
| summary: Introduction to Inline Assembly in Solidity and its use for low-level control over the EVM | ||
| labels: ["solidity"] | ||
| --- | ||
|
|
||
| Inline Assembly in Solidity allows developers to write low-level code directly within Solidity contracts. It provides fine-grained control over the Ethereum Virtual Machine (EVM) and enables developers to perform operations that are not directly available through Solidity's high-level constructs. Inline Assembly is written using the `assembly` keyword followed by a block of assembly code. | ||
|
|
||
| ## Purpose of Inline Assembly | ||
|
|
||
| Inline Assembly is primarily used for: | ||
|
|
||
| - **Optimization**: To reduce gas costs by implementing more efficient low-level operations. | ||
| - **Access to EVM Internals**: Direct access to low-level features and instructions that are not available in high-level Solidity. | ||
| - **Compatibility**: Interacting with legacy smart contracts or performing operations not directly supported by Solidity. | ||
| - | ||
| ## Dangerous Aspects of Inline Assembly | ||
|
|
||
| Inline Assembly is a powerful feature in Solidity, but it comes with certain risks and limitations: | ||
| - **Complexity**: Assembly code is more complex and harder to read than high-level Solidity code. | ||
| - **Security Risks**: Incorrectly written assembly code can lead to vulnerabilities and security risks. | ||
| - **Portability**: Assembly code may not be portable across different EVM versions or compilers. | ||
|
|
||
| ## Example of Inline Assembly | ||
|
|
||
| Here is an example illustrating the use of inline assembly in Solidity to perform arithmetic operations: | ||
|
|
||
| ```solidity | ||
| pragma solidity ^0.8.26; | ||
|
|
||
| contract AssemblyExample { | ||
| // Function to add two numbers using inline assembly | ||
| function add(uint256 a, uint256 b) public pure returns (uint256 result) { | ||
| assembly { | ||
| result := add(a, b) | ||
| } | ||
| } | ||
|
|
||
| // Function to save data to the contract storage using inline assembly | ||
| function setStorageData(uint256 slot, uint256 data) public { | ||
| assembly { | ||
| sstore(slot, data) | ||
| } | ||
| } | ||
|
|
||
| // Function to get stored data from the contract storage | ||
| // returns the value stored at the specified slot | ||
| function getStorageData( | ||
| uint256 slot | ||
| ) public view returns (uint256 data) { | ||
| assembly { | ||
| data := sload(slot) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work! Do you think it's possible to expand to five exercises and solutions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done