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
16c5be68
Commit
16c5be68
authored
Jan 11, 2021
by
ben-chain
Committed by
GitHub
Jan 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix tainted memory bug in `Lib_BytesUtils.slice` (#171)
parent
59111a57
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
2 deletions
+46
-2
Lib_BytesUtils.sol
...ts/optimistic-ethereum/libraries/utils/Lib_BytesUtils.sol
+4
-0
TestLib_RLPWriter.sol
...tracts/contracts/test-libraries/rlp/TestLib_RLPWriter.sol
+1
-1
TestLib_BytesUtils.sol
...cts/contracts/test-libraries/utils/TestLib_BytesUtils.sol
+17
-0
Lib_RLPWriter.spec.ts
...tracts/test/contracts/libraries/rlp/Lib_RLPWriter.spec.ts
+1
-1
Lib_BytesUtils.spec.ts
...cts/test/contracts/libraries/utils/Lib_BytesUtils.spec.ts
+23
-0
No files found.
packages/contracts/contracts/optimistic-ethereum/libraries/utils/Lib_BytesUtils.sol
View file @
16c5be68
...
@@ -148,6 +148,10 @@ library Lib_BytesUtils {
...
@@ -148,6 +148,10 @@ library Lib_BytesUtils {
default {
default {
tempBytes := mload(0x40)
tempBytes := mload(0x40)
//zero out the 32 bytes slice we are about to return
//we need to do it because Solidity does not garbage collect
mstore(tempBytes, 0)
mstore(0x40, add(tempBytes, 0x20))
mstore(0x40, add(tempBytes, 0x20))
}
}
}
}
...
...
packages/contracts/contracts/test-libraries/rlp/TestLib_RLPWriter.sol
View file @
16c5be68
...
@@ -83,7 +83,7 @@ contract TestLib_RLPWriter {
...
@@ -83,7 +83,7 @@ contract TestLib_RLPWriter {
return Lib_RLPWriter.writeBool(_in);
return Lib_RLPWriter.writeBool(_in);
}
}
function writeAddressWith
Other
Memory(
function writeAddressWith
Tainted
Memory(
address _in
address _in
)
)
public
public
...
...
packages/contracts/contracts/test-libraries/utils/TestLib_BytesUtils.sol
View file @
16c5be68
...
@@ -4,6 +4,7 @@ pragma experimental ABIEncoderV2;
...
@@ -4,6 +4,7 @@ pragma experimental ABIEncoderV2;
/* Library Imports */
/* Library Imports */
import { Lib_BytesUtils } from "../../optimistic-ethereum/libraries/utils/Lib_BytesUtils.sol";
import { Lib_BytesUtils } from "../../optimistic-ethereum/libraries/utils/Lib_BytesUtils.sol";
import { TestERC20 } from "../../test-helpers/TestERC20.sol";
/**
/**
* @title TestLib_BytesUtils
* @title TestLib_BytesUtils
...
@@ -101,4 +102,20 @@ contract TestLib_BytesUtils {
...
@@ -101,4 +102,20 @@ contract TestLib_BytesUtils {
_other
_other
);
);
}
}
function sliceWithTaintedMemory(
bytes memory _bytes,
uint256 _start,
uint256 _length
)
public
returns (bytes memory)
{
new TestERC20();
return Lib_BytesUtils.slice(
_bytes,
_start,
_length
);
}
}
}
packages/contracts/test/contracts/libraries/rlp/Lib_RLPWriter.spec.ts
View file @
16c5be68
...
@@ -45,7 +45,7 @@ describe('Lib_RLPWriter', () => {
...
@@ -45,7 +45,7 @@ describe('Lib_RLPWriter', () => {
const
randomAddress
=
'
0x1234123412341234123412341234123412341234
'
const
randomAddress
=
'
0x1234123412341234123412341234123412341234
'
const
rlpEncodedRandomAddress
=
const
rlpEncodedRandomAddress
=
'
0x941234123412341234123412341234123412341234
'
'
0x941234123412341234123412341234123412341234
'
const
encoded
=
await
Lib_RLPWriter
.
callStatic
.
writeAddressWith
Other
Memory
(
const
encoded
=
await
Lib_RLPWriter
.
callStatic
.
writeAddressWith
Tainted
Memory
(
randomAddress
randomAddress
)
)
expect
(
encoded
).
to
.
eq
(
rlpEncodedRandomAddress
)
expect
(
encoded
).
to
.
eq
(
rlpEncodedRandomAddress
)
...
...
packages/contracts/test/contracts/libraries/utils/Lib_BytesUtils.spec.ts
View file @
16c5be68
...
@@ -2,8 +2,31 @@
...
@@ -2,8 +2,31 @@
import
{
Lib_BytesUtils_TEST_JSON
}
from
'
../../../data
'
import
{
Lib_BytesUtils_TEST_JSON
}
from
'
../../../data
'
import
{
runJsonTest
}
from
'
../../../helpers
'
import
{
runJsonTest
}
from
'
../../../helpers
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
}
from
'
ethers
'
import
{
expect
}
from
'
../../../setup
'
describe
(
'
Lib_BytesUtils
'
,
()
=>
{
describe
(
'
Lib_BytesUtils
'
,
()
=>
{
describe
(
'
JSON tests
'
,
()
=>
{
describe
(
'
JSON tests
'
,
()
=>
{
runJsonTest
(
'
TestLib_BytesUtils
'
,
Lib_BytesUtils_TEST_JSON
)
runJsonTest
(
'
TestLib_BytesUtils
'
,
Lib_BytesUtils_TEST_JSON
)
})
})
describe
(
'
Use of library with other memory-modifying operations
'
,
()
=>
{
let
TestLib_BytesUtils
:
Contract
before
(
async
()
=>
{
TestLib_BytesUtils
=
await
(
await
ethers
.
getContractFactory
(
'
TestLib_BytesUtils
'
)
).
deploy
()
})
it
(
'
should allow creation of a contract beforehand and still work
'
,
async
()
=>
{
const
slice
=
await
TestLib_BytesUtils
.
callStatic
.
sliceWithTaintedMemory
(
'
0x123412341234
'
,
0
,
0
)
expect
(
slice
).
to
.
eq
(
'
0x
'
)
})
})
})
})
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