-
-
Notifications
You must be signed in to change notification settings - Fork 31
draft: implement eof_create_inputs definitions #648
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
0xMushow
wants to merge
3
commits into
main
Choose a base branch
from
antoine-james@links-file-eof-create-inputs
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 1 commit
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
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 |
---|---|---|
|
@@ -3,6 +3,61 @@ Require Import CoqOfRust.links.M. | |
Require Import CoqOfRust.revm.links.dependencies. | ||
Require Import CoqOfRust.revm.links.primitives.bytecode.eof. | ||
|
||
(* | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub enum EOFCreateKind { | ||
Tx { | ||
initdata: Bytes, | ||
}, | ||
Opcode { | ||
initcode: Eof, | ||
input: Bytes, | ||
created_address: Address, | ||
}, | ||
} | ||
*) | ||
|
||
Module EOFCreateKind. | ||
Inductive t : Type := | ||
| Tx (initdata : Bytes.t) | ||
| Opcode (initcode : Eof.t) (input : Bytes.t) (created_address : Address.t). | ||
|
||
Global Instance IsLink : Link t := { | ||
Φ := Ty.path "revm_interpreter::interpreter::eof_create_input::EOFCreateKind"; | ||
φ k := | ||
match k with | ||
| Tx initdata => | ||
Value.StructRecord "revm_interpreter::interpreter::eof_create_input::EOFCreateKind::Tx" [ | ||
("initdata", φ initdata) | ||
] | ||
| Opcode initcode input created_address => | ||
Value.StructRecord "revm_interpreter::interpreter::eof_create_input::EOFCreateKind::Opcode" [ | ||
("initcode", φ initcode); | ||
("input", φ input); | ||
("created_address", φ created_address) | ||
] | ||
end; | ||
}. | ||
End EOFCreateKind. | ||
|
||
(* | ||
impl EOFCreateKind { | ||
/// Returns created address | ||
pub fn created_address(&self) -> Option<&Address> { | ||
match self { | ||
EOFCreateKind::Opcode { | ||
created_address, .. | ||
} => Some(created_address), | ||
EOFCreateKind::Tx { .. } => None, | ||
} | ||
} | ||
} | ||
*) | ||
|
||
|
||
|
||
|
||
(* | ||
/// Inputs for EOF create call. | ||
#[derive(Debug, Default, Clone, PartialEq, Eq)] | ||
|
@@ -21,7 +76,7 @@ Require Import CoqOfRust.revm.links.primitives.bytecode.eof. | |
} | ||
*) | ||
|
||
Module EOFCreateInput. | ||
Module EOFCreateInputs. | ||
Record t : Set := { | ||
caller : Address.t; | ||
created_address : Address.t; | ||
|
@@ -31,14 +86,78 @@ Module EOFCreateInput. | |
}. | ||
|
||
Global Instance IsLink : Link t := { | ||
Φ := Ty.path "revm_interpreter::interpreter::eof_create_input::EOFCreateInput"; | ||
Φ := Ty.path "revm_interpreter::interpreter::eof_create_input::EOFCreateInputs"; | ||
φ x := | ||
Value.StructRecord "revm_interpreter::interpreter::eof_create_input::EOFCreateInput" [ | ||
Value.StructRecord "revm_interpreter::interpreter::eof_create_input::EOFCreateInputs" [ | ||
("caller", φ x.(caller)); | ||
("created_address", φ x.(created_address)); | ||
("value", φ x.(value)); | ||
("eof_init_code", φ x.(eof_init_code)); | ||
("gas_limit", φ x.(gas_limit)) | ||
]; | ||
}. | ||
End EOFCreateInput. | ||
End EOFCreateInputs. | ||
|
||
Module Impl_EOFCreateInputs. | ||
Definition Self := EOFCreateInputs.t. | ||
|
||
(* | ||
pub fn new(caller: Address, value: U256, gas_limit: u64, kind: EOFCreateKind) -> Self { | ||
//let (eof_init_code, input) = Eof::decode_dangling(tx.data.clone())?; | ||
EOFCreateInputs { | ||
caller, | ||
value, | ||
gas_limit, | ||
kind, | ||
} | ||
} | ||
*) | ||
|
||
Parameter address_default : Address.t. | ||
Parameter eof_decode : Bytes.t -> Eof.t. | ||
|
||
Definition new (caller : Address.t) (value : U256.t) | ||
(gas_limit : U64.t) (kind : EOFCreateKind.t) : Self := | ||
{| EOFCreateInputs.caller := caller; | ||
EOFCreateInputs.created_address := | ||
match kind with | ||
| EOFCreateKind.Opcode _ _ addr => addr | ||
| EOFCreateKind.Tx _ => address_default | ||
end; | ||
EOFCreateInputs.value := value; | ||
EOFCreateInputs.eof_init_code := | ||
match kind with | ||
| EOFCreateKind.Opcode code _ _ => code | ||
| EOFCreateKind.Tx data => eof_decode data | ||
end; | ||
EOFCreateInputs.gas_limit := gas_limit |}. | ||
|
||
(* | ||
pub fn new_opcode( | ||
caller: Address, | ||
created_address: Address, | ||
value: U256, | ||
eof_init_code: Eof, | ||
gas_limit: u64, | ||
input: Bytes, | ||
) -> EOFCreateInputs { | ||
EOFCreateInputs::new( | ||
caller, | ||
value, | ||
gas_limit, | ||
EOFCreateKind::Opcode { | ||
initcode: eof_init_code, | ||
input, | ||
created_address, | ||
}, | ||
) | ||
} | ||
*) | ||
|
||
Definition new_opcode (caller : Address.t) (created_address : Address.t) | ||
(value : U256.t) (eof_init_code : Eof.t) | ||
(gas_limit : U64.t) (input : Bytes.t) : Self := | ||
new caller value gas_limit (EOFCreateKind.Opcode eof_init_code input created_address). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as with the |
||
|
||
End Impl_EOFCreateInputs. | ||
|
Oops, something went wrong.
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.
We do not create any definitions in the links mode and only write
run_new
. This is one advantage of the links approach. Here the statement would be something like:Then for an example of proof there is the file https://github.com/formal-land/coq-of-rust/blob/main/CoqOfRust/revm/links/interpreter/interpreter/gas.v , although it is still quite experimental.