-
-
Notifications
You must be signed in to change notification settings - Fork 37
Experimental example translation for CI test #535
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
InfiniteEchoes
wants to merge
34
commits into
main
Choose a base branch
from
gy@ExpSnippet
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 all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
4aa17bf
Experimental translation for CI test
InfiniteEchoes fefd563
Add traits.v
InfiniteEchoes 895a12e
Update `traits.v`
InfiniteEchoes 377ef39
Update `traits.v`
InfiniteEchoes bb472da
Update `traits.v`: Finished function definitions
InfiniteEchoes bc13690
`traits.v`: Remove comments
InfiniteEchoes 287f430
Minor fixes
InfiniteEchoes 5c83ccd
Update `traits.v`
InfiniteEchoes 6ed6eee
Update `traits.v`
InfiniteEchoes 8a94f10
Update `traits.v` according to comments
InfiniteEchoes 5cad995
Update `constants.v` according to comment
InfiniteEchoes 81fc18c
More minor fixes
InfiniteEchoes 83ce23f
More fixes according to comments
InfiniteEchoes f443776
Compiler-checked `constants.v`
InfiniteEchoes 555eac5
Compiler-passed `traits.v` with unfixed bug
InfiniteEchoes dcfe964
Fixed all bugs of `traits.v`
InfiniteEchoes dcfaf13
Add initial `erc.1155.v`
InfiniteEchoes 309606b
Update erc1155
InfiniteEchoes 33cf84c
More updates on `erc1155.v`
InfiniteEchoes 89ccad6
Update `traits.v`
InfiniteEchoes 09fb455
Finished defining `traits.v` for simulation(?)
InfiniteEchoes fdff43f
remove comments
InfiniteEchoes 419d9c7
minor fixes
InfiniteEchoes 9aa87c4
format fix
InfiniteEchoes e7c562f
draft update
InfiniteEchoes 344a47f
Merge branch 'main' into gy@ExpSnippet
InfiniteEchoes 40c77d7
snapshot
InfiniteEchoes ab0ba4a
Update `traits.v`
InfiniteEchoes c32c5fb
Fix `traits.v`
InfiniteEchoes 57b1481
Update `constants.v`
InfiniteEchoes 315d42b
Update `erc1155.v`
InfiniteEchoes f7c44b6
Merge branch 'main' into gy@ExpSnippet
InfiniteEchoes 29671f5
Fix file location after merging main
InfiniteEchoes 9897d26
Update according to main & delete redundant deps
InfiniteEchoes 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
12 changes: 12 additions & 0 deletions
12
CoqOfRust/examples/default/examples/ink_contracts/proofs/constants.v
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,12 @@ | ||
| Require Import CoqOfRust.CoqOfRust. | ||
| Require Import CoqOfRust.proofs.M. | ||
| Require Import CoqOfRust.simulations.M. | ||
| Require Import CoqOfRust.lib.proofs.lib. | ||
| Require CoqOfRust.core.proofs.option. | ||
| Require CoqOfRust.examples.default.examples.ink_contracts.proofs.lib. | ||
| Require CoqOfRust.examples.default.examples.ink_contracts.simulations.constants. | ||
| (* TODO: Refer to real translated code *) | ||
| (* Require CoqOfRust.examples.default.examples.ink_contracts.constants. *) | ||
|
|
||
| Import simulations.M.Notations. | ||
| Import Run. |
11 changes: 11 additions & 0 deletions
11
CoqOfRust/examples/default/examples/ink_contracts/proofs/traits.v
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,11 @@ | ||
| Require Import CoqOfRust.CoqOfRust. | ||
| Require Import CoqOfRust.proofs.M. | ||
| Require Import CoqOfRust.simulations.M. | ||
| Require Import CoqOfRust.lib.proofs.lib. | ||
| Require CoqOfRust.core.proofs.option. | ||
| Require CoqOfRust.examples.default.examples.ink_contracts.proofs.lib. | ||
| Require CoqOfRust.examples.default.examples.ink_contracts.simulations.traits. | ||
| Require CoqOfRust.examples.default.examples.ink_contracts.erc20. | ||
|
|
||
| Import simulations.M.Notations. | ||
| Import Run. |
221 changes: 221 additions & 0 deletions
221
CoqOfRust/examples/default/examples/ink_contracts/simulations/erc1155.v
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,221 @@ | ||
| Require Import CoqOfRust.CoqOfRust. | ||
| Require CoqOfRust.core.simulations.default. | ||
| Require Import CoqOfRust.core.simulations.option. | ||
| Require Import CoqOfRust.core.simulations.bool. | ||
| Require CoqOfRust.examples.default.examples.ink_contracts.simulations.lib. | ||
| Require Import CoqOfRust.simulations.M. | ||
|
|
||
| (* TODO: | ||
| - Check the Mapping structure in erc1155 | ||
|
|
||
| *) | ||
|
|
||
| (* ******** Primitives ******** *) | ||
|
|
||
| (* | ||
| struct AccountId(u128); | ||
| *) | ||
| Module AccountId. | ||
| Inductive t : Set := | ||
| | Make (account_id : Z). | ||
|
|
||
| Global Instance IsToValue : ToValue t := { | ||
| Φ := Ty.path "erc1155::AccountId"; | ||
| φ '(Make account_id) := | ||
| Value.StructTuple "erc1155::AccountId" [Value.Integer Integer.U128 account_id]; | ||
| }. | ||
| End AccountId. | ||
|
|
||
| (* type Balance = u128; *) | ||
| Module Balance. | ||
| Inductive t : Set := | ||
| | Make (balance : Z). | ||
|
|
||
| Global Instance IsToTy : ToTy t := { | ||
| Φ := Ty.path "erc1155::Balance"; | ||
| }. | ||
|
|
||
| Global Instance IsToValue : ToValue t := { | ||
| φ '(Make balance) := | ||
| Value.StructTuple "erc1155::Balance" [Value.Integer Integer.U128 balance]; | ||
| }. | ||
| End Balance. | ||
|
|
||
| (* | ||
| struct Env { | ||
| caller: AccountId, | ||
| } | ||
| *) | ||
|
|
||
| Module Env. | ||
| Record t : Set := { | ||
| caller : AccountId.t; | ||
| }. | ||
|
|
||
| Global Instance IsToTy : ToTy t := { | ||
| Φ := Ty.path "erc1155::Env"; | ||
| }. | ||
|
|
||
| Global Instance IsToValue : ToValue t := { | ||
| φ '(Make x) := | ||
| Value.StructTuple "erc1155::Env" φ x; | ||
| }. | ||
| End Env. | ||
|
|
||
| (* ******** IN PROGRESS ******** *) | ||
|
|
||
| (* | ||
| fn zero_address() -> AccountId { | ||
| [0u8; 32].into() | ||
| } | ||
| *) | ||
|
|
||
| (* | ||
| const ON_ERC_1155_RECEIVED_SELECTOR: [u8; 4] = [0xF2, 0x3A, 0x6E, 0x61]; | ||
| *) | ||
|
|
||
| (* | ||
| const _ON_ERC_1155_BATCH_RECEIVED_SELECTOR: [u8; 4] = [0xBC, 0x19, 0x7C, 0x81]; | ||
| *) | ||
|
|
||
| (* pub type TokenId = u128; *) | ||
| Module TokenId. | ||
| Inductive t : Set := | ||
| | Make (token_id : Z). | ||
|
|
||
| Global Instance IsToTy : ToTy t := { | ||
| Φ := Ty.path "erc1155::TokenId"; | ||
| }. | ||
|
|
||
| Global Instance IsToValue : ToValue t := { | ||
| φ '(Make token_id) := | ||
| Value.StructTuple "erc1155::TokenId" [Value.Integer Integer.U128 token_id]; | ||
| }. | ||
| End TokenId. | ||
|
|
||
| (* | ||
| // The ERC-1155 error types. | ||
| #[derive(PartialEq, Eq)] | ||
| pub enum Error { | ||
| /// This token ID has not yet been created by the contract. | ||
| UnexistentToken, | ||
| /// The caller tried to sending tokens to the zero-address (`0x00`). | ||
| ZeroAddressTransfer, | ||
| /// The caller is not approved to transfer tokens on behalf of the account. | ||
| NotApproved, | ||
| /// The account does not have enough funds to complete the transfer. | ||
| InsufficientBalance, | ||
| /// An account does not need to approve themselves to transfer tokens. | ||
| SelfApproval, | ||
| /// The number of tokens being transferred does not match the specified number of | ||
| /// transfers. | ||
| BatchTransferMismatch, | ||
| } | ||
| *) | ||
| Module Error. | ||
| Inductive t : Set := | ||
| | UnexistentToken | ||
| | ZeroAddressTransfer | ||
| | NotApproved | ||
| | InsufficientBalance | ||
| | SelfApproval | ||
| | BatchTransferMismatch. | ||
|
|
||
| (* TODO: finish the ToValue here? *) | ||
| End Error. | ||
|
|
||
| (* pub type Result<T> = core::result::Result<T, Error>; *) | ||
| Module Result. | ||
| (* TODO: Check if this is the right way to use the Result *) | ||
| Definition t (T : Set) : Set := core.result.Result T Error. | ||
| End Result. | ||
|
|
||
| (* pub trait Erc1155 { .. }*) | ||
| Module Erc1155. | ||
| Class Trait (Self : Set) : Set := { | ||
| (* | ||
| fn safe_transfer_from( | ||
| &mut self, | ||
| from: AccountId, | ||
| to: AccountId, | ||
| token_id: TokenId, | ||
| value: Balance, | ||
| data: Vec<u8>, | ||
| ) -> Result<()>; | ||
| *) | ||
|
|
||
| (* fn safe_batch_transfer_from( | ||
| &mut self, | ||
| from: AccountId, | ||
| to: AccountId, | ||
| token_ids: Vec<TokenId>, | ||
| values: Vec<Balance>, | ||
| data: Vec<u8>, | ||
| ) -> Result<()>; *) | ||
|
|
||
| (* fn balance_of(&self, owner: AccountId, token_id: TokenId) -> Balance; *) | ||
|
|
||
| (* fn balance_of_batch(&self, owners: Vec<AccountId>, token_ids: Vec<TokenId>) -> Vec<Balance>; *) | ||
|
|
||
| (* fn set_approval_for_all(&mut self, operator: AccountId, approved: bool) -> Result<()>; *) | ||
|
|
||
| (* fn is_approved_for_all(&self, owner: AccountId, operator: AccountId) -> bool; *) | ||
|
|
||
| }. | ||
| End Erc1155. | ||
|
|
||
| (* pub trait Erc1155TokenReceiver { .. } *) | ||
| Module Erc1155TokenReceiver. | ||
| Class Trait (Self : Set) : Set := { | ||
| (* fn on_received( | ||
| &mut self, | ||
| operator: AccountId, | ||
| from: AccountId, | ||
| token_id: TokenId, | ||
| value: Balance, | ||
| data: Vec<u8>, | ||
| ) -> Vec<u8>; *) | ||
|
|
||
| (* fn on_batch_received( | ||
| &mut self, | ||
| operator: AccountId, | ||
| from: AccountId, | ||
| token_ids: Vec<TokenId>, | ||
| values: Vec<Balance>, | ||
| data: Vec<u8>, | ||
| ) -> Vec<u8>; *) | ||
| }. | ||
| End Erc1155TokenReceiver. | ||
|
|
||
| (* type Owner = AccountId; | ||
| type Operator = AccountId; *) | ||
|
|
||
| (* pub struct TransferSingle { | ||
| operator: Option<AccountId>, | ||
| from: Option<AccountId>, | ||
| to: Option<AccountId>, | ||
| token_id: TokenId, | ||
| value: Balance, | ||
| } *) | ||
| Module TransferSingle. | ||
| Record t : Set := { | ||
|
|
||
| }. | ||
| End TransferSingle. | ||
|
|
||
| (* pub struct ApprovalForAll { | ||
| owner: AccountId, | ||
| operator: AccountId, | ||
| approved: bool, | ||
| } | ||
|
|
||
| pub struct Uri { | ||
| value: String, | ||
| token_id: TokenId, | ||
| } | ||
|
|
||
| enum Event { | ||
| TransferSingle(TransferSingle), | ||
| ApprovalForAll(ApprovalForAll), | ||
| Uri(Uri), | ||
| } *) | ||
33 changes: 33 additions & 0 deletions
33
CoqOfRust/examples/default/examples/simulations/constants.v
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,33 @@ | ||
| (* custom_type/constants.v *) | ||
| Require Import CoqOfRust.CoqOfRust. | ||
| Require Import CoqOfRust.simulations.M. | ||
| Import simulations.M.Notations. | ||
|
|
||
| (* | ||
| static LANGUAGE: &str = "Rust"; | ||
| const THRESHOLD: i32 = 10; | ||
| *) | ||
| Definition LANGUAGE : string := "Rust". | ||
| Definition THRESHOLD : Z := 10. | ||
|
|
||
| (* | ||
| fn is_big(n: i32) -> bool { | ||
| // Access constant in some function | ||
| n > THRESHOLD | ||
| } | ||
| *) | ||
|
|
||
| Definition is_big | ||
| (n: Z) : bool := | ||
| let get_n := n in | ||
| let get_THRESHOLD := THRESHOLD in | ||
| get_n >? get_THRESHOLD. | ||
|
|
||
| (* | ||
| fn main() { | ||
| let n = 16; | ||
| } *) | ||
|
|
||
| Definition main : unit := | ||
| let n := 16 in | ||
| tt. |
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.
Uh oh!
There was an error while loading. Please reload this page.