-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(codegen): introduce storage related built-in functions (#97)
* feat(codegen): introduce module func for built-in functions * feat(codegen): introduce built-in function sload and sstore * feat(compiler): passing imported zink functions to codegen * feat(codegen): process base function index from imports * feat(codegen): adjust imported functions in calls * feat(compiler): add storage to the outputs of EVM tests * feat(compiler): test sstore * feat(codegen): correct the code section generation order
- Loading branch information
Showing
21 changed files
with
604 additions
and
151 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,70 @@ | ||
//! Built-in functions for EVM | ||
use opcodes::ShangHai as OpCode; | ||
|
||
/// Function `select` from WASM which is not avaiable in EVM. | ||
const SELECT: [OpCode; 6] = [ | ||
OpCode::JUMPDEST, | ||
OpCode::POP, | ||
OpCode::PUSH1, | ||
OpCode::Data(0x06), | ||
OpCode::ADD, | ||
OpCode::JUMP, | ||
]; | ||
|
||
/// Function `sload` from EVM which is not avaiable in WASM. | ||
const SLOAD: [OpCode; 7] = [ | ||
OpCode::JUMPDEST, | ||
OpCode::SLOAD, | ||
OpCode::SWAP1, | ||
OpCode::PUSH1, | ||
OpCode::Data(0x05), | ||
OpCode::ADD, | ||
OpCode::JUMP, | ||
]; | ||
|
||
/// Function `sload` from EVM which is not avaiable in WASM. | ||
const SSTORE: [OpCode; 6] = [ | ||
OpCode::JUMPDEST, | ||
OpCode::SSTORE, | ||
OpCode::PUSH1, | ||
OpCode::Data(0x05), | ||
OpCode::ADD, | ||
OpCode::JUMP, | ||
]; | ||
|
||
/// Function selector. | ||
#[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)] | ||
pub enum Func { | ||
/// Run function select. | ||
Select, | ||
/// Run function sload. | ||
Sload, | ||
/// Run function sstore. | ||
Sstore, | ||
} | ||
|
||
impl Func { | ||
/// Get the bytecode of the function. | ||
pub fn bytecode(&self) -> Vec<u8> { | ||
match self { | ||
Self::Select => SELECT.to_vec(), | ||
Self::Sload => SLOAD.to_vec(), | ||
Self::Sstore => SSTORE.to_vec(), | ||
} | ||
.into_iter() | ||
.map(|op| op.into()) | ||
.collect() | ||
} | ||
} | ||
|
||
impl TryFrom<(&str, &str)> for Func { | ||
type Error = (); | ||
|
||
fn try_from(import: (&str, &str)) -> Result<Self, Self::Error> { | ||
match import { | ||
("zink", "sload") => Ok(Self::Sload), | ||
("zink", "sstore") => Ok(Self::Sstore), | ||
_ => Err(()), | ||
} | ||
} | ||
} |
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
Oops, something went wrong.