Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
007e4fa3
Commit
007e4fa3
authored
Dec 11, 2020
by
Alina
Committed by
GitHub
Dec 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OZ L09 Remove unnecessary use of assembly (#121)
* abi.encodePacked * rm _malloc
parent
3e5fe501
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
36 deletions
+6
-36
Lib_RLPWriter.sol
...racts/optimistic-ethereum/libraries/rlp/Lib_RLPWriter.sol
+6
-36
No files found.
packages/contracts/contracts/optimistic-ethereum/libraries/rlp/Lib_RLPWriter.sol
View file @
007e4fa3
...
...
@@ -89,16 +89,7 @@ library Lib_RLPWriter {
bytes memory _out
)
{
_malloc(0x20);
bytes memory inputBytes;
assembly {
let m := mload(0x40)
mstore(add(m, 20), xor(0x140000000000000000000000000000000000000000, _in))
mstore(0x40, add(m, 52))
inputBytes := m
}
return writeBytes(inputBytes);
return writeBytes(abi.encodePacked(_in));
}
/**
...
...
@@ -188,7 +179,7 @@ library Lib_RLPWriter {
* @return _binary RLP encoded bytes.
*/
function _toBinary(
uint _x
uint
256
_x
)
private
pure
...
...
@@ -196,12 +187,9 @@ library Lib_RLPWriter {
bytes memory _binary
)
{
bytes memory b = new bytes(32);
assembly {
mstore(add(b, 32), _x)
}
bytes memory b = abi.encodePacked(_x);
uint i = 0;
uint
256
i = 0;
for (; i < 32; i++) {
if (b[i] != 0) {
break;
...
...
@@ -209,7 +197,7 @@ library Lib_RLPWriter {
}
bytes memory res = new bytes(32 - i);
for (uint j = 0; j < res.length; j++) {
for (uint
256
j = 0; j < res.length; j++) {
res[j] = b[i++];
}
...
...
@@ -292,22 +280,4 @@ library Lib_RLPWriter {
return flattened;
}
/**
* Clears memory wherever the free memory is pointing.
* @param _numBytes Number of bytes to clear out (will be rounded up to nearest word).
*/
function _malloc(
uint _numBytes
)
private
pure
{
assembly {
let free_mem := mload(0x40)
for { let offset := 0x00 } lt(offset, _numBytes) { offset := add(offset, 0x20) } {
mstore(add(free_mem, offset), 0x00)
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment