This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from huff-language/md/free-slot-bug
fix: free storage pointer used in param bug
- Loading branch information
Showing
8 changed files
with
140 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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 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,37 @@ | ||
use huff_codegen::Codegen; | ||
use huff_lexer::Lexer; | ||
use huff_parser::Parser; | ||
use huff_utils::{prelude::FullFileSource, token::Token}; | ||
|
||
/// Check that free storage pointers referenced outside of macro bodies | ||
/// are assigned correctly at compilation | ||
#[test] | ||
fn test_set_free_storage_pointers() { | ||
let source: &str = r#" | ||
#define constant FREE = FREE_STORAGE_POINTER() | ||
#define macro TEST_MACRO(slot) = { | ||
<slot> sload 0x00 mstore 0x20 0x00 return | ||
} | ||
#define macro MAIN() = { | ||
TEST_MACRO(FREE) | ||
} | ||
"#; | ||
|
||
// Parse tokens | ||
let flattened_source = FullFileSource { source, file: None, spans: vec![] }; | ||
let lexer = Lexer::new(flattened_source); | ||
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>(); | ||
let mut parser = Parser::new(tokens, None); | ||
|
||
// Parse AST | ||
let mut contract = parser.parse().unwrap(); | ||
|
||
// Derive storage pointers | ||
contract.derive_storage_pointers(); | ||
|
||
// Assert the Free storage pointer has been set to 0 | ||
let mbytes = Codegen::generate_main_bytecode(&contract, None).unwrap(); | ||
assert!(mbytes.starts_with("6000")); | ||
} |
This file contains 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 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 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 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 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 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