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
2a94e198
Unverified
Commit
2a94e198
authored
Jun 19, 2023
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cannon: fix Oracle.sol lint
parent
b5492f9c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
15 deletions
+31
-15
Oracle.sol
packages/contracts-bedrock/contracts/cannon/Oracle.sol
+31
-15
No files found.
packages/contracts-bedrock/contracts/cannon/Oracle.sol
View file @
2a94e198
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
pragma solidity 0.8.15;
contract Oracle {
contract Oracle {
mapping(bytes32 => uint256) public preimageLengths;
mapping(bytes32 => mapping(uint256 => bytes32)) public preimageParts;
mapping(bytes32 => mapping(uint256 => bool)) public preimagePartOk;
mapping (bytes32 => uint256) public preimageLengths;
function readPreimage(bytes32 key, uint256 offset)
mapping (bytes32 => mapping(uint256 => bytes32)) preimageParts;
external
mapping (bytes32 => mapping(uint256 => bool)) preimagePartOk;
view
returns (bytes32 dat, uint256 datLen)
function readPreimage(bytes32 key, uint256 offset) external view returns (bytes32 dat, uint256 datLen)
{
{
require(preimagePartOk[key][offset], "preimage must exist");
require(preimagePartOk[key][offset], "preimage must exist");
datLen = 32;
datLen = 32;
uint256 length = preimageLengths[key];
uint256 length = preimageLengths[key];
if(offset + 32 >= length + 8) { // add 8 for the length-prefix part
// add 8 for the length-prefix part
if (offset + 32 >= length + 8) {
datLen = length + 8 - offset;
datLen = length + 8 - offset;
}
}
dat = preimageParts[key][offset];
dat = preimageParts[key][offset];
}
}
// TODO: we need to mix-in the ID of the dispute for local-type keys to avoid collisions,
// TODO(CLI-4104):
// we need to mix-in the ID of the dispute for local-type keys to avoid collisions,
// and restrict local pre-image insertion to the dispute-managing contract.
// and restrict local pre-image insertion to the dispute-managing contract.
// For now we permit anyone to write any pre-image unchecked, to make testing easy.
// For now we permit anyone to write any pre-image unchecked, to make testing easy.
// This method is DANGEROUS. And NOT FOR PRODUCTION.
// This method is DANGEROUS. And NOT FOR PRODUCTION.
function cheat(uint256 partOffset, bytes32 key, bytes32 part, uint256 size) external {
function cheat(
uint256 partOffset,
bytes32 key,
bytes32 part,
uint256 size
) external {
preimagePartOk[key][partOffset] = true;
preimagePartOk[key][partOffset] = true;
preimageParts[key][partOffset] = part;
preimageParts[key][partOffset] = part;
preimageLengths[key] = size;
preimageLengths[key] = size;
...
@@ -35,19 +44,26 @@ contract Oracle {
...
@@ -35,19 +44,26 @@ contract Oracle {
bytes32 key;
bytes32 key;
bytes32 part;
bytes32 part;
assembly {
assembly {
size := calldataload(0x44) // len(sig) + len(partOffset) + len(preimage offset) = 4 + 32 + 32 = 0x44
// len(sig) + len(partOffset) + len(preimage offset) = 4 + 32 + 32 = 0x44
if iszero(lt(partOffset, add(size, 8))) { // revert if part offset >= size+8 (i.e. parts must be within bounds)
size := calldataload(0x44)
// revert if part offset >= size+8 (i.e. parts must be within bounds)
if iszero(lt(partOffset, add(size, 8))) {
revert(0, 0)
revert(0, 0)
}
}
let ptr := 0x80 // we leave solidity slots 0x40 and 0x60 untouched, and everything after as scratch-memory.
// we leave solidity slots 0x40 and 0x60 untouched,
mstore(ptr, shl(192, size)) // put size as big-endian uint64 at start of pre-image
// and everything after as scratch-memory.
let ptr := 0x80
// put size as big-endian uint64 at start of pre-image
mstore(ptr, shl(192, size))
ptr := add(ptr, 8)
ptr := add(ptr, 8)
calldatacopy(ptr, preimage.offset, size) // copy preimage payload into memory so we can hash and read it.
// copy preimage payload into memory so we can hash and read it.
calldatacopy(ptr, preimage.offset, size)
// Note that it includes the 8-byte big-endian uint64 length prefix.
// Note that it includes the 8-byte big-endian uint64 length prefix.
// this will be zero-padded at the end, since memory at end is clean.
// this will be zero-padded at the end, since memory at end is clean.
part := mload(add(sub(ptr, 8), partOffset))
part := mload(add(sub(ptr, 8), partOffset))
let h := keccak256(ptr, size) // compute preimage keccak256 hash
let h := keccak256(ptr, size) // compute preimage keccak256 hash
key := or(and(h, not(shl(248, 0xFF))), shl(248, 2)) // mask out prefix byte, replace with type 2 byte
// mask out prefix byte, replace with type 2 byte
key := or(and(h, not(shl(248, 0xFF))), shl(248, 2))
}
}
preimagePartOk[key][partOffset] = true;
preimagePartOk[key][partOffset] = true;
preimageParts[key][partOffset] = part;
preimageParts[key][partOffset] = part;
...
...
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