forked from ensdomains/evmgateway
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change from transparent-proxy to immutable with external trie hooks a…
…nd machine, add OP_LENGTH, OP_STACK_SIZE, add chain SHAPE, change all gateway proofs to tuples
- Loading branch information
Showing
69 changed files
with
2,693 additions
and
2,006 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,58 +1,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import {IGatewayProofVerifier} from "./IGatewayProofVerifier.sol"; | ||
import {IGatewayVerifier} from "./IGatewayVerifier.sol"; | ||
import {IProverHooks} from "./IProverHooks.sol"; | ||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; | ||
import {StorageSlot} from "@openzeppelin/contracts/utils/StorageSlot.sol"; | ||
|
||
abstract contract AbstractVerifier is IGatewayProofVerifier { | ||
|
||
event GatewayChanged(); | ||
abstract contract AbstractVerifier is IGatewayVerifier, Ownable { | ||
|
||
bytes32 constant SLOT_urls = keccak256("unruggable.gateway.urls"); | ||
bytes32 constant SLOT_window = keccak256("unruggable.gateway.window"); | ||
event GatewayURLsChanged(); | ||
|
||
modifier onlyOwner() { | ||
require(msg.sender == _owner(), "not admin owner"); | ||
_; | ||
} | ||
string[] _urls; | ||
uint256 immutable _window; | ||
IProverHooks immutable _hooks; | ||
|
||
function _owner() internal view returns (address) { | ||
return Ownable(ERC1967Utils.getAdmin()).owner(); | ||
} | ||
|
||
function owner() external view returns (address) { | ||
return _owner(); | ||
constructor(string[] memory urls, uint256 window, IProverHooks hooks) Ownable(msg.sender) { | ||
_urls = urls; | ||
_window = window; | ||
_hooks = hooks; | ||
} | ||
|
||
function setGatewayURLs(string[] calldata urls) external onlyOwner { | ||
StorageSlot.getBytesSlot(SLOT_urls).value = abi.encode(urls); | ||
emit GatewayChanged(); | ||
function setGatewayURLs(string[] memory urls) external onlyOwner { | ||
_urls = urls; | ||
emit GatewayURLsChanged(); | ||
} | ||
|
||
function gatewayURLs() external view returns (string[] memory) { | ||
bytes memory storedValue = StorageSlot.getBytesSlot(SLOT_urls).value; | ||
// Check if the stored value is empty or not set | ||
if (storedValue.length == 0) { | ||
return new string[](0); | ||
} | ||
return abi.decode(storedValue, (string[])); | ||
} | ||
|
||
function setWindow(uint256 window) external onlyOwner { | ||
StorageSlot.getUint256Slot(SLOT_window).value = window; | ||
emit GatewayChanged(); | ||
return _urls; | ||
} | ||
|
||
function getWindow() external view returns (uint256) { | ||
return StorageSlot.getUint256Slot(SLOT_window).value; | ||
return _window; | ||
} | ||
|
||
function _checkWindow(uint256 latest, uint256 got) internal view { | ||
uint256 window = StorageSlot.getUint256Slot(SLOT_window).value; | ||
if (got + window < latest) revert("too old"); | ||
if (got + _window < latest) revert("too old"); | ||
if (got > latest) revert("too new"); | ||
} | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -1,42 +1,74 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import {GatewayRequest} from "./GatewayProtocol.sol"; | ||
import {IGatewayProofVerifier} from "./IGatewayProofVerifier.sol"; | ||
import {IGatewayProver} from "./IGatewayProver.sol"; | ||
import {IGatewayVerifier} from './IGatewayVerifier.sol'; | ||
import {GatewayRequest} from './GatewayRequest.sol'; | ||
import {IGatewayProver} from './IGatewayProver.sol'; | ||
|
||
error OffchainLookup(address from, string[] urls, bytes request, bytes4 callback, bytes carry); | ||
error OffchainLookup( | ||
address from, | ||
string[] urls, | ||
bytes request, | ||
bytes4 callback, | ||
bytes carry | ||
); | ||
|
||
abstract contract GatewayFetchTarget { | ||
struct Session { | ||
IGatewayVerifier verifier; | ||
bytes context; | ||
GatewayRequest req; | ||
bytes4 callback; | ||
bytes carry; | ||
} | ||
|
||
struct Session { | ||
IGatewayProofVerifier verifier; | ||
bytes context; | ||
GatewayRequest req; | ||
bytes4 callback; | ||
bytes carry; | ||
} | ||
function fetch( | ||
IGatewayVerifier verifier, | ||
GatewayRequest memory req, | ||
bytes4 callback | ||
) internal view { | ||
fetch(verifier, req, callback, '', new string[](0)); | ||
} | ||
|
||
function fetch(IGatewayProofVerifier verifier, GatewayRequest memory req, bytes4 callback, bytes memory carry) internal view { | ||
bytes memory context = verifier.getLatestContext(); | ||
revert OffchainLookup( | ||
address(this), | ||
verifier.gatewayURLs(), | ||
abi.encodeCall(IGatewayProver.proveRequest, (context, req)), | ||
this.fetchCallback.selector, | ||
abi.encode(Session(verifier, context, req, callback, carry)) | ||
); | ||
} | ||
|
||
function fetchCallback(bytes calldata response, bytes calldata carry) external view { | ||
Session memory ses = abi.decode(carry, (Session)); | ||
(bytes[] memory values, uint8 exitCode) = ses.verifier.getStorageValues(ses.context, ses.req, response); | ||
(bool ok, bytes memory ret) = address(this).staticcall(abi.encodeWithSelector(ses.callback, values, exitCode, ses.carry)); | ||
if (ok) { | ||
assembly { return(add(ret, 32), mload(ret)) } | ||
} else { | ||
assembly { revert(add(ret, 32), mload(ret)) } | ||
} | ||
} | ||
function fetch( | ||
IGatewayVerifier verifier, | ||
GatewayRequest memory req, | ||
bytes4 callback, | ||
bytes memory carry, | ||
string[] memory urls | ||
) internal view { | ||
bytes memory context = verifier.getLatestContext(); | ||
if (urls.length == 0) urls = verifier.gatewayURLs(); | ||
revert OffchainLookup( | ||
address(this), | ||
urls, | ||
abi.encodeCall(IGatewayProver.proveRequest, (context, req)), | ||
this.fetchCallback.selector, | ||
abi.encode(Session(verifier, context, req, callback, carry)) | ||
); | ||
} | ||
|
||
function fetchCallback( | ||
bytes calldata response, | ||
bytes calldata carry | ||
) external view { | ||
Session memory ses = abi.decode(carry, (Session)); | ||
(bytes[] memory values, uint8 exitCode) = ses.verifier.getStorageValues( | ||
ses.context, | ||
ses.req, | ||
response | ||
); | ||
(bool ok, bytes memory ret) = address(this).staticcall( | ||
abi.encodeWithSelector(ses.callback, values, exitCode, ses.carry) | ||
); | ||
if (ok) { | ||
assembly { | ||
return(add(ret, 32), mload(ret)) | ||
} | ||
} else { | ||
assembly { | ||
revert(add(ret, 32), mload(ret)) | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.