-
Notifications
You must be signed in to change notification settings - Fork 2
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
Induce data availability into contract #41
Open
noel2004
wants to merge
14
commits into
master
Choose a base branch
from
with_DA
base: master
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
14 commits
Select commit
Hold shift + click to select a range
e97431b
contract with DA
b31275f
fmt
4464b42
resume committing action for submitting
16ac1cf
change parameters from memory to calldata in external function
772c3c2
code for priority op queue, include unit-tests
d561685
handling priority op in demo contract
6741026
add mine script for localhost (instead of tick)
0b97fae
encode op for registerUser
8abd4d6
catching up with new master
e0fcb4d
fmt
270b5e3
update contracts
d172c9c
update for DA features
b97eb89
deposit script
3a9026b
update yarn lock
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
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,156 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
library Bytes { | ||
function shiftAndReverseBits8(uint8 val, uint8 offset) | ||
internal | ||
pure | ||
returns (uint256 ret) | ||
{ | ||
uint16 effectLen = offset < 248 ? 8 : 256 - offset; | ||
for (uint16 i = 0; i < effectLen; i++) { | ||
if (val & 1 == 1) { | ||
ret += (1 << (255 - i - offset)); | ||
} | ||
val >>= 1; | ||
} | ||
} | ||
|
||
function shiftAndReverseBits16(uint16 val, uint8 offset) | ||
internal | ||
pure | ||
returns (uint256 ret) | ||
{ | ||
uint16 effectLen = offset < 240 ? 16 : 256 - offset; | ||
for (uint16 i = 0; i < effectLen; i++) { | ||
if (val & 1 == 1) { | ||
ret += (1 << (255 - i - offset)); | ||
} | ||
val >>= 1; | ||
} | ||
} | ||
|
||
function shiftAndReverseBits32(uint32 val, uint8 offset) | ||
internal | ||
pure | ||
returns (uint256 ret) | ||
{ | ||
uint16 effectLen = offset < 224 ? 32 : 256 - offset; | ||
for (uint16 i = 0; i < effectLen; i++) { | ||
if (val & 1 == 1) { | ||
ret += (1 << (255 - i - offset)); | ||
} | ||
val >>= 1; | ||
} | ||
} | ||
|
||
function shiftAndReverseBits64(uint64 val, uint8 offset) | ||
internal | ||
pure | ||
returns (uint256 ret) | ||
{ | ||
uint16 effectLen = offset < 192 ? 64 : 256 - offset; | ||
for (uint16 i = 0; i < effectLen; i++) { | ||
if (val & 1 == 1) { | ||
ret += (1 << (255 - i - offset)); | ||
} | ||
val >>= 1; | ||
} | ||
} | ||
|
||
function shiftAndReverseBits128(uint128 val, uint8 offset) | ||
internal | ||
pure | ||
returns (uint256 ret) | ||
{ | ||
uint16 effectLen = offset < 128 ? 128 : 256 - offset; | ||
for (uint16 i = 0; i < effectLen; i++) { | ||
if (val & 1 == 1) { | ||
ret += (1 << (255 - i - offset)); | ||
} | ||
val >>= 1; | ||
} | ||
} | ||
|
||
function shiftAndReverseBits(uint256 val, uint8 offset) | ||
internal | ||
pure | ||
returns (uint256 ret) | ||
{ | ||
for (uint16 i = 0; i < 256 - offset; i++) { | ||
if (val & 1 == 1) { | ||
ret += (1 << (255 - i - offset)); | ||
} | ||
val >>= 1; | ||
} | ||
} | ||
|
||
//see https://ethereum.stackexchange.com/questions/83626/how-to-reverse-byte-order-in-uint256-or-bytes32 | ||
function swapBytes(uint256 input) internal pure returns (uint256 v) { | ||
v = input; | ||
|
||
// swap bytes | ||
v = | ||
((v & | ||
0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00) >> | ||
8) | | ||
((v & | ||
0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << | ||
8); | ||
|
||
// swap 2-byte long pairs | ||
v = | ||
((v & | ||
0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000) >> | ||
16) | | ||
((v & | ||
0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << | ||
16); | ||
|
||
// swap 4-byte long pairs | ||
v = | ||
((v & | ||
0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000) >> | ||
32) | | ||
((v & | ||
0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << | ||
32); | ||
|
||
// swap 8-byte long pairs | ||
v = | ||
((v & | ||
0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000) >> | ||
64) | | ||
((v & | ||
0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) << | ||
64); | ||
|
||
// swap 16-byte long pairs | ||
v = (v >> 128) | (v << 128); | ||
} | ||
|
||
// See comment at the top of this file for explanation of how this function works. | ||
// NOTE: theoretically possible overflow of (_start + 0x2) | ||
function bytesToUInt16(bytes memory _bytes, uint256 _start) | ||
internal | ||
pure | ||
returns (uint16 r) | ||
{ | ||
uint256 offset = _start + 0x2; | ||
require(_bytes.length >= offset, "T"); | ||
assembly { | ||
r := mload(add(_bytes, offset)) | ||
} | ||
} | ||
|
||
// NOTE: theoretically possible overflow of (_offset + 2) | ||
function readUInt16(bytes memory _data, uint256 _offset) | ||
internal | ||
pure | ||
returns (uint256 newOffset, uint16 r) | ||
{ | ||
newOffset = _offset + 2; | ||
r = bytesToUInt16(_data, _offset); | ||
} | ||
} |
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.
can we combine
shiftAndReverseBits16
,shiftAndReverseBits32
,shiftAndReverseBits64
,shiftAndReverseBits128
?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.
tried but failed. If we defined both foo(uint16) and foo(uint32), the calling of foo seems to be considered as ambiguous even you have specified the type of argument explicitly.