forked from ethereum/fe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes ethereum#75
- Loading branch information
Showing
22 changed files
with
714 additions
and
111 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::yul::names; | ||
use fe_analyzer::namespace::types::Struct; | ||
use fe_analyzer::namespace::types::{AbiEncoding, FixedSize}; | ||
use fe_common::utils::abi as abi_utils; | ||
use yultsur::*; | ||
|
||
fn selector(name: &str, params: &[FixedSize]) -> yul::Expression { | ||
let params = params | ||
.iter() | ||
.map(|param| param.abi_selector_name()) | ||
.collect::<Vec<String>>(); | ||
|
||
literal_expression! {(abi_utils::func_selector(name, ¶ms))} | ||
} | ||
|
||
/// Generate a YUL function to revert with the `Error` signature and the | ||
/// given set of params. | ||
/// NOTE: This is currently used for `assert False, "message"` statements which are | ||
/// encoded as `Error(msg="message")`. This will be removed in the future. | ||
pub fn generate_revert_fn_for_assert(params: &[FixedSize]) -> yul::Statement { | ||
generate_revert_fn("Error", params, params) | ||
} | ||
|
||
/// Generate a YUL function to revert with a specific struct used as error data | ||
pub fn generate_struct_revert(val: &Struct) -> yul::Statement { | ||
let struct_fields = val.get_field_types(); | ||
generate_revert_fn(&val.name, &[FixedSize::Struct(val.clone())], &struct_fields) | ||
} | ||
|
||
/// Generate a YUL function that can be used to revert with data | ||
pub fn generate_revert_fn( | ||
name: &str, | ||
encoding_params: &[FixedSize], | ||
selector_params: &[FixedSize], | ||
) -> yul::Statement { | ||
let abi_encode_fn = names::encode_name(encoding_params); | ||
|
||
let function_name = names::revert_name(name, selector_params); | ||
|
||
let selector = selector(name, &selector_params); | ||
|
||
return function_definition! { | ||
function [function_name](data_ptr, size) { | ||
(let ptr := alloc_mstoren([selector], 4)) | ||
(pop(([abi_encode_fn](data_ptr)))) | ||
(revert(ptr, (add(4, size)))) | ||
} | ||
}; | ||
} |
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
Oops, something went wrong.