-
Notifications
You must be signed in to change notification settings - Fork 78
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
Polynetwork support #908
Merged
Merged
Polynetwork support #908
Changes from 40 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
dd93b89
Add header deserialization and utilities for it
vaivaswatha 7f8e87e
Merge branch 'master' into polynetwork
vaivaswatha c0fdad3
Merge branch 'master' into polynetwork
vaivaswatha 4627dc5
Make all integer conversions little-endian
vaivaswatha a52a191
Provide an option version of substr
vaivaswatha 4bd3e9a
Fix order of fields in Header and add test to testsuite
vaivaswatha 990b3f4
Deserialize TxParam and ToMerkleValue
vaivaswatha 844b5fd
test: add multiple tests for library function next_var_uint
renlulu 9cba52a
test: add test cases for library function extract_bystr
renlulu 7d47ef6
chore: add testing file into ml file
renlulu b21117f
Merge branch 'master' into polynetwork
vaivaswatha 8fbcaa1
Merge branch 'polynetwork' of github.com:Zilliqa/scilla into polynetwork
vaivaswatha 2234dbd
Merge branch 'master' into polynetwork
vaivaswatha f0c45f7
VarUint serialization
vaivaswatha a3dd75b
Merge branch 'master' into polynetwork
vaivaswatha d911fbf
Add serialization of variable length byte strings
vaivaswatha a24969d
Provide serialization to uint16
vaivaswatha 7ece7d7
Add compress_pubkey function
vaivaswatha bfc9fc0
add verifyPubkey and getBookKeeper functions
vaivaswatha c681469
Merge branch 'master' into polynetwork
vaivaswatha 2e03949
Rename few functions to not have confliction names
vaivaswatha 189d3d7
add initGenesisBlock transition
vaivaswatha d456444
Add merkle proof function
vaivaswatha 8ad57bf
Add verifyHeaderAndExecuteTx transition
vaivaswatha 49c451e
Add changeBookKeeper transition
vaivaswatha 96c2a77
Add transition crossChain
vaivaswatha 3713163
Add getBookKeeper test
vaivaswatha 717cdc2
Fix typo / bug in Polynetwork.lib
vaivaswatha c1c3e58
Add verifySig function along with eth compatible ecrecover
vaivaswatha 7cfe593
executeCrossChainTxn must pass fromContractAddr and fromChainId also
vaivaswatha 4fa7fec
Merge branch 'master' into polynetwork
vaivaswatha 9b12d5b
Add initGenesisBlock test
vaivaswatha 8dd38f0
Add a proof deserializer in tests
vaivaswatha 4081f48
Test for VerifyHeaderAndExecuteTxEvent
vaivaswatha 5f5904a
Improve VerifyHeaderAndExecuteTxEvent
vaivaswatha 64b791c
Merge branch 'master' into polynetwork
vaivaswatha d2c639d
use to_ascii instead of to_string for method_name
vaivaswatha 10c6d4a
Add more tests, including expected fail tests for Polynetwork
vaivaswatha bc55b73
Merge branch 'master' into polynetwork
vaivaswatha 88aa15a
Incorporate _origin and fix all tests
vaivaswatha cc3dcb2
Fix bugs in tests in creating div by zero error
vaivaswatha bd62317
Rename osubstr to substr_safe based on review comment
vaivaswatha 5f46817
Add a reference for ecrecover
vaivaswatha 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 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 @@ | ||
(* ******************************************************************************** *) | ||
(* This file is part of scilla. *) | ||
(* *) | ||
(* Copyright (c) 2018 - present Zilliqa Research Pvt. Ltd. *) | ||
(* *) | ||
(* scilla is free software: you can redistribute it and/or modify it under the *) | ||
(* terms of the GNU General Public License as published by the Free Software *) | ||
(* Foundation, either version 3 of the License, or (at your option) any later *) | ||
(* version. *) | ||
(* *) | ||
(* scilla is distributed in the hope that it will be useful, but WITHOUT ANY *) | ||
(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR *) | ||
(* A PARTICULAR PURPOSE. See the GNU General Public License for more details. *) | ||
(* *) | ||
(* You should have received a copy of the GNU General Public License along with *) | ||
(* scilla. If not, see <http://www.gnu.org/licenses/>. *) | ||
(* ******************************************************************************** *) | ||
scilla_version 0 | ||
|
||
import IntUtils | ||
|
||
library Conversions | ||
|
||
type IntegerEncoding = | ||
| LittleEndian | ||
| BigEndian | ||
|
||
(* does not throw exceptions *) | ||
let osubstr : ByStr -> Uint32 -> Uint32 -> Option ByStr = | ||
fun (bs : ByStr) => | ||
fun (pos : Uint32) => | ||
fun (len : Uint32) => | ||
let length = builtin strlen bs in | ||
let shorter = uint32_le len length in | ||
match shorter with | ||
| True => | ||
let delta = builtin sub length len in | ||
let safe_pos = uint32_le pos delta in | ||
match safe_pos with | ||
| True => | ||
let substr = builtin substr bs pos len in | ||
Some {ByStr} substr | ||
| False => None {ByStr} | ||
end | ||
| False => None {ByStr} | ||
end | ||
|
||
(* Extract out a Scilla type from a ByStr starting at pos. Returns next position. *) | ||
(* Use the type specific helpers below rather than this function. *) | ||
let extract_scillaval : forall 'A. forall 'B. (ByStr -> Option 'B) -> ('B -> 'A) -> ByStr -> Uint32 -> Uint32 -> Option (Pair 'A Uint32) = | ||
anton-trunov marked this conversation as resolved.
Show resolved
Hide resolved
jjcnn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tfun 'A => | ||
tfun 'B => | ||
fun (to_bystrx : ByStr -> Option 'B) => | ||
fun (to_uint : 'B -> 'A) => | ||
fun (bs : ByStr) => | ||
fun (pos : Uint32) => | ||
fun (len : Uint32) => (* Byte size of the Uint value. *) | ||
let subbs_opt = osubstr bs pos len in | ||
match subbs_opt with | ||
| Some subbs => | ||
let subbs_x_opt = to_bystrx subbs in | ||
match subbs_x_opt with | ||
| Some subbs_x => | ||
jjcnn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let ui = to_uint subbs_x in | ||
let next_pos = builtin add pos len in | ||
let res = Pair {'A Uint32} ui next_pos in | ||
Some {(Pair 'A Uint32)} res | ||
| None => | ||
None {(Pair 'A Uint32)} | ||
end | ||
| None => | ||
None {(Pair 'A Uint32)} | ||
end | ||
|
||
(* Extracts Uint32 in bs from position pos and returns next position. *) | ||
let extract_uint32 : IntegerEncoding -> ByStr -> Uint32 -> Option (Pair Uint32 Uint32) = | ||
fun (endian : IntegerEncoding) => | ||
fun (bs : ByStr) => | ||
fun (pos : Uint32) => | ||
let to_bystrx = fun (a : ByStr) => builtin to_bystr4 a in | ||
let to_uint = | ||
fun (a : ByStr4) => | ||
let b = match endian with | LittleEndian => builtin strrev a | BigEndian => a end in | ||
jjcnn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
builtin to_uint32 b | ||
in | ||
let extractor = @extract_scillaval Uint32 ByStr4 in | ||
let uint32_bsize = Uint32 4 in | ||
extractor to_bystrx to_uint bs pos uint32_bsize | ||
|
||
(* Extracts Uint64 in bs from position pos and returns next position. *) | ||
let extract_uint64 : IntegerEncoding -> ByStr -> Uint32 -> Option (Pair Uint64 Uint32) = | ||
fun (endian : IntegerEncoding) => | ||
fun (bs : ByStr) => | ||
fun (pos : Uint32) => | ||
let to_bystrx = fun (a : ByStr) => builtin to_bystr8 a in | ||
let to_uint = | ||
fun (a : ByStr8) => | ||
let b = match endian with | LittleEndian => builtin strrev a | BigEndian => a end in | ||
builtin to_uint64 b | ||
in | ||
let extractor = @extract_scillaval Uint64 ByStr8 in | ||
let uint64_bsize = Uint32 8 in | ||
extractor to_bystrx to_uint bs pos uint64_bsize | ||
|
||
(* Extracts Uint128 in bs from position pos and returns next position. *) | ||
let extract_uint128 : IntegerEncoding -> ByStr -> Uint32 -> Option (Pair Uint128 Uint32) = | ||
fun (endian : IntegerEncoding) => | ||
fun (bs : ByStr) => | ||
fun (pos : Uint32) => | ||
let to_bystrx = fun (a : ByStr) => builtin to_bystr16 a in | ||
let to_uint = | ||
fun (a : ByStr16) => | ||
let b = match endian with | LittleEndian => builtin strrev a | BigEndian => a end in | ||
builtin to_uint128 b | ||
in | ||
let extractor = @extract_scillaval Uint128 ByStr16 in | ||
let uint128_bsize = Uint32 16 in | ||
extractor to_bystrx to_uint bs pos uint128_bsize | ||
|
||
(* Extracts Uint256 in bs from position pos and returns next position. *) | ||
let extract_uint256 : IntegerEncoding -> ByStr -> Uint32 -> Option (Pair Uint256 Uint32) = | ||
fun (endian : IntegerEncoding) => | ||
fun (bs : ByStr) => | ||
fun (pos : Uint32) => | ||
let to_bystrx = fun (a : ByStr) => builtin to_bystr32 a in | ||
let to_uint = | ||
fun (a : ByStr32) => | ||
let b = match endian with | LittleEndian => builtin strrev a | BigEndian => a end in | ||
builtin to_uint256 b | ||
in | ||
let extractor = @extract_scillaval Uint256 ByStr32 in | ||
let uint256_bsize = Uint32 32 in | ||
extractor to_bystrx to_uint bs pos uint256_bsize | ||
|
||
(* Extracts ByStr1 in bs from position pos and returns next position *) | ||
let extract_bystr1 : ByStr -> Uint32 -> Option (Pair ByStr1 Uint32) = | ||
fun (bs : ByStr) => | ||
fun (pos : Uint32) => | ||
let to_bystrx = fun (a : ByStr) => builtin to_bystr1 a in | ||
let unit = fun (a : ByStr1) => a in | ||
let extractor = @extract_scillaval ByStr1 ByStr1 in | ||
let bystr1_bsize = Uint32 1 in | ||
extractor to_bystrx unit bs pos bystr1_bsize | ||
|
||
(* Extracts ByStr2 in bs from position pos and returns next position *) | ||
let extract_bystr2 : ByStr -> Uint32 -> Option (Pair ByStr2 Uint32) = | ||
fun (bs : ByStr) => | ||
fun (pos : Uint32) => | ||
let to_bystrx = fun (a : ByStr) => builtin to_bystr2 a in | ||
let unit = fun (a : ByStr2) => a in | ||
let extractor = @extract_scillaval ByStr2 ByStr2 in | ||
let bystr2_bsize = Uint32 2 in | ||
extractor to_bystrx unit bs pos bystr2_bsize | ||
|
||
(* Extracts ByStr20 in bs from position pos and returns next position *) | ||
let extract_bystr20 : ByStr -> Uint32 -> Option (Pair ByStr20 Uint32) = | ||
fun (bs : ByStr) => | ||
fun (pos : Uint32) => | ||
let to_bystrx = fun (a : ByStr) => builtin to_bystr20 a in | ||
let unit = fun (a : ByStr20) => a in | ||
let extractor = @extract_scillaval ByStr20 ByStr20 in | ||
let bystr20_bsize = Uint32 20 in | ||
extractor to_bystrx unit bs pos bystr20_bsize | ||
|
||
(* Extracts ByStr32 in bs from position pos and returns next position *) | ||
let extract_bystr32 : ByStr -> Uint32 -> Option (Pair ByStr32 Uint32) = | ||
fun (bs : ByStr) => | ||
fun (pos : Uint32) => | ||
let to_bystrx = fun (a : ByStr) => builtin to_bystr32 a in | ||
let unit = fun (a : ByStr32) => a in | ||
let extractor = @extract_scillaval ByStr32 ByStr32 in | ||
let bystr32_bsize = Uint32 32 in | ||
extractor to_bystrx unit bs pos bystr32_bsize | ||
|
||
(* Append serialized Uint32 value to given byte string *) | ||
let append_uint32 : IntegerEncoding -> ByStr -> Uint32 -> ByStr = | ||
fun (endian : IntegerEncoding) => | ||
fun (bs : ByStr) => | ||
fun (ui : Uint32) => | ||
let uibx = builtin to_bystr4 ui in | ||
let uib = builtin to_bystr uibx in | ||
let uib_endian = | ||
match endian with | LittleEndian => builtin strrev uib | BigEndian => uib end | ||
in | ||
builtin concat bs uib_endian | ||
|
||
(* Append serialized Uint64 value to given byte string *) | ||
let append_uint64 : IntegerEncoding -> ByStr -> Uint64 -> ByStr = | ||
fun (endian : IntegerEncoding) => | ||
fun (bs : ByStr) => | ||
fun (ui : Uint64) => | ||
let uibx = builtin to_bystr8 ui in | ||
let uib = builtin to_bystr uibx in | ||
let uib_endian = | ||
match endian with | LittleEndian => builtin strrev uib | BigEndian => uib end | ||
in | ||
builtin concat bs uib_endian | ||
|
||
(* Append serialized Uint128 value to given byte string *) | ||
let append_uint128 : IntegerEncoding -> ByStr -> Uint128 -> ByStr = | ||
fun (endian : IntegerEncoding) => | ||
fun (bs : ByStr) => | ||
fun (ui : Uint128) => | ||
let uibx = builtin to_bystr16 ui in | ||
let uib = builtin to_bystr uibx in | ||
let uib_endian = | ||
match endian with | LittleEndian => builtin strrev uib | BigEndian => uib end | ||
in | ||
builtin concat bs uib | ||
|
||
(* Append serialized Uint256 value to given byte string *) | ||
let append_uint256 : IntegerEncoding -> ByStr -> Uint256 -> ByStr = | ||
fun (endian : IntegerEncoding) => | ||
fun (bs : ByStr) => | ||
fun (ui : Uint256) => | ||
let uibx = builtin to_bystr32 ui in | ||
let uib = builtin to_bystr uibx in | ||
let uib_endian = | ||
match endian with | LittleEndian => builtin strrev uib | BigEndian => uib end | ||
in | ||
builtin concat bs uib |
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.
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 have an unsafe
substr
and theo
prefix indicates return of an option value. Since the name was suggested by @anton-trunov , let's see if he's ok with the new name too. If yes, I'll do this change.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.
I'm fine with renaming.