Skip to content
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

feat: stealth-relayer #17

Draft
wants to merge 1 commit into
base: feat/hooks
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions solidity/contracts/hooks/StealthTxHooks.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.19;

import {IStealthVault} from '@interfaces/external/IStealthVault.sol';
import {IStealthRelayer} from '@interfaces/external/IStealthRelayer.sol';

contract StealthTxYearnHooks {
IStealthVault public stealthVault;
IStealthRelayer public stealthRelayer;

constructor(IStealthVault _stealthVault, IStealthRelayer _stealthRelayer) {
stealthVault = _stealthVault;
stealthRelayer = _stealthRelayer;
}

// todo: impossible to set caller = msg.sender
// todo: need to perform call with value
// todo: need find a way to make paymnets for block.coinbase
function validateCall(

Check warning on line 19 in solidity/contracts/hooks/StealthTxHooks.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Return value 'bytes' in function 'validateCall' must be named
address _job,
address _caller,
bytes memory _calldata,
bytes32 _hash,
uint256 _blockNumber,
uint256 _penalty
) external payable returns (bytes memory) {
// check if the job in the job list
address[] memory _jobs = stealthRelayer.jobs();
for (uint256 i = 0; i < _jobs.length; i++) {

Check warning on line 29 in solidity/contracts/hooks/StealthTxHooks.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

'i' should start with _
if (_jobs[i] == _job) {
break;
}
if (i == _jobs.length - 1) {
revert('SR: invalid job');

Check warning on line 34 in solidity/contracts/hooks/StealthTxHooks.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Use Custom Errors instead of revert statements
}
}

bool _isValidHash = stealthVault.validateHash(_caller, _hash, _penalty);
require(_isValidHash, 'ST: invalid stealth hash');

Check warning on line 39 in solidity/contracts/hooks/StealthTxHooks.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Use Custom Errors instead of require statements

require(block.number == _blockNumber, 'ST: wrong block');

Check warning on line 41 in solidity/contracts/hooks/StealthTxHooks.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Use Custom Errors instead of require statements

return _calldata;
}

function validateCallWithoutBlock(

Check warning on line 46 in solidity/contracts/hooks/StealthTxHooks.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Return value 'bytes' in function 'validateCallWithoutBlock' must be named
address _job,
address _caller,
bytes memory _calldata,
bytes32 _hash,
uint256 _penalty
) external payable returns (bytes memory) {
// check if the job in the job list
address[] memory _jobs = stealthRelayer.jobs();
for (uint256 i = 0; i < _jobs.length; i++) {

Check warning on line 55 in solidity/contracts/hooks/StealthTxHooks.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

'i' should start with _
if (_jobs[i] == _job) {
break;
}
if (i == _jobs.length - 1) {
revert('SR: invalid job');

Check warning on line 60 in solidity/contracts/hooks/StealthTxHooks.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Use Custom Errors instead of revert statements
}
}

bool _isValidHash = stealthVault.validateHash(_caller, _hash, _penalty);
require(_isValidHash, 'ST: invalid stealth hash');

Check warning on line 65 in solidity/contracts/hooks/StealthTxHooks.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Use Custom Errors instead of require statements

require(!stealthRelayer.forceBlockProtection(), 'SR: block protection required');

Check warning on line 67 in solidity/contracts/hooks/StealthTxHooks.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Use Custom Errors instead of require statements

return _calldata;
}
}
48 changes: 48 additions & 0 deletions solidity/interfaces/external/IStealthRelayer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface IStealthRelayer {
function caller() external view returns (address _caller);

function forceBlockProtection() external view returns (bool _forceBlockProtection);

function jobs() external view returns (address[] memory _jobsList);

function setForceBlockProtection(bool _forceBlockProtection) external;

function addJobs(address[] calldata _jobsList) external;

function addJob(address _job) external;

function removeJobs(address[] calldata _jobsList) external;

function removeJob(address _job) external;

function execute(
address _address,
bytes memory _callData,
bytes32 _stealthHash,
uint256 _blockNumber
) external payable returns (bytes memory _returnData);

function executeAndPay(
address _address,
bytes memory _callData,
bytes32 _stealthHash,
uint256 _blockNumber,
uint256 _payment
) external payable returns (bytes memory _returnData);

function executeWithoutBlockProtection(
address _address,
bytes memory _callData,
bytes32 _stealthHash
) external payable returns (bytes memory _returnData);

function executeWithoutBlockProtectionAndPay(
address _job,
bytes memory _callData,
bytes32 _stealthHash,
uint256 _payment
) external payable returns (bytes memory _returnData);
}
77 changes: 77 additions & 0 deletions solidity/interfaces/external/IStealthVault.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface IStealthVault {
//events
event Bonded(address indexed _caller, uint256 _amount, uint256 _finalBond);
event Unbonded(address indexed _caller, uint256 _amount, uint256 _finalBond);
event ReportedHash(bytes32 _hash, address _reportedBy);
event PenaltyApplied(bytes32 _hash, address _caller, uint256 _penalty, address _reportedBy);
event ValidatedHash(bytes32 _hash, address _caller, uint256 _penalty);

event StealthContractEnabled(address indexed _caller, address _contract);

event StealthContractsEnabled(address indexed _caller, address[] _contracts);

event StealthContractDisabled(address indexed _caller, address _contract);

event StealthContractsDisabled(address indexed _caller, address[] _contracts);

function isStealthVault() external pure returns (bool);

// getters
function callers() external view returns (address[] memory _callers);

function callerContracts(address _caller) external view returns (address[] memory _contracts);

// global bond
function gasBuffer() external view returns (uint256 _gasBuffer);

function totalBonded() external view returns (uint256 _totalBonded);

function bonded(address _caller) external view returns (uint256 _bond);

function canUnbondAt(address _caller) external view returns (uint256 _canUnbondAt);

// global caller
function caller(address _caller) external view returns (bool _enabled);

function callerStealthContract(address _caller, address _contract) external view returns (bool _enabled);

// global hash
function hashReportedBy(bytes32 _hash) external view returns (address _reportedBy);

// governor
function setGasBuffer(uint256 _gasBuffer) external;

function transferGovernorBond(address _caller, uint256 _amount) external;

function transferBondToGovernor(address _caller, uint256 _amount) external;

// caller
function bond() external payable;

function startUnbond() external;

function cancelUnbond() external;

function unbondAll() external;

function unbond(uint256 _amount) external;

function enableStealthContract(address _contract) external;

function enableStealthContracts(address[] calldata _contracts) external;

function disableStealthContract(address _contract) external;

function disableStealthContracts(address[] calldata _contracts) external;

// stealth-contract
function validateHash(address _caller, bytes32 _hash, uint256 _penalty) external returns (bool);

// watcher
function reportHash(bytes32 _hash) external;

function reportHashAndPay(bytes32 _hash) external payable;
}
Loading