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: non-upgradeable contracts #319

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions contracts/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
PRIVATE_KEY=
CREATE2_SALT=

### Roles
GUARDIAN=
PROVER=

### Guardian & Timelock
GUARDIAN_OWNERS=
MINIMUM_DELAY=
Expand Down
17 changes: 3 additions & 14 deletions contracts/script/deploy/SuccinctFeeVault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.16;
import "forge-std/console.sol";
import {BaseScript} from "../misc/Base.s.sol";
import {SuccinctFeeVault} from "../../src/payments/SuccinctFeeVault.sol";
import {Proxy} from "../../src/upgrades/Proxy.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

contract DeploySuccinctFeeVault is BaseScript {
Expand All @@ -14,24 +13,14 @@ contract DeploySuccinctFeeVault is BaseScript {
);

// Check inputs
address TIMELOCK = envAddress("TIMELOCK", block.chainid);
address GUARDIAN = envAddress("GUARDIAN", block.chainid);
bytes32 CREATE2_SALT = envBytes32("CREATE2_SALT");
bool UPGRADE = envBool("UPGRADE_VIA_EOA", false);
address GUARDIAN = envAddress("GUARDIAN", block.chainid);

// Deploy contract
SuccinctFeeVault vaultImpl = new SuccinctFeeVault{salt: CREATE2_SALT}();
SuccinctFeeVault vault;
if (!UPGRADE) {
vault = SuccinctFeeVault(address(new Proxy{salt: CREATE2_SALT}(address(vaultImpl), "")));
vault.initialize(TIMELOCK, GUARDIAN);
} else {
vault = SuccinctFeeVault(envAddress("SUCCINCT_FEE_VAULT", block.chainid));
vault.upgradeTo(address(vaultImpl));
}
SuccinctFeeVault vault = new SuccinctFeeVault{salt: CREATE2_SALT}();
vault.initialize(GUARDIAN);

// Write address
writeEnvAddress(DEPLOYMENT_FILE, "SUCCINCT_FEE_VAULT", address(vault));
writeEnvAddress(DEPLOYMENT_FILE, "SUCCINCT_FEE_VAULT_IMPL", address(vaultImpl));
}
}
21 changes: 5 additions & 16 deletions contracts/script/deploy/SuccinctGateway.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.16;
import "forge-std/console.sol";
import {BaseScript} from "../misc/Base.s.sol";
import {SuccinctGateway} from "../../src/SuccinctGateway.sol";
import {Proxy} from "../../src/upgrades/Proxy.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

contract DeploySuccinctGateway is BaseScript {
Expand All @@ -13,26 +12,16 @@ contract DeploySuccinctGateway is BaseScript {
"Deploying SuccinctGateway contract on chain %s", Strings.toString(block.chainid)
);

address SUCCINCT_FEE_VAULT = envAddress("SUCCINCT_FEE_VAULT", block.chainid);
address TIMELOCK = envAddress("TIMELOCK", block.chainid);
address GUARDIAN = envAddress("GUARDIAN", block.chainid);
bytes32 CREATE2_SALT = envBytes32("CREATE2_SALT");
bool UPGRADE = envBool("UPGRADE_VIA_EOA", false);
address GUARDIAN = envAddress("GUARDIAN", block.chainid);
address SUCCINCT_FEE_VAULT = envAddress("SUCCINCT_FEE_VAULT", block.chainid);
address PROVER = envAddress("PROVER", block.chainid);

// Deploy contract
SuccinctGateway gatewayImpl = new SuccinctGateway{salt: CREATE2_SALT}();
SuccinctGateway gateway;
if (!UPGRADE) {
gateway =
SuccinctGateway(address(new Proxy{salt: CREATE2_SALT}(address(gatewayImpl), "")));
gateway.initialize(SUCCINCT_FEE_VAULT, TIMELOCK, GUARDIAN);
} else {
gateway = SuccinctGateway(envAddress("SUCCINCT_GATEWAY", block.chainid));
gateway.upgradeTo(address(gatewayImpl));
}
SuccinctGateway gateway = new SuccinctGateway{salt: CREATE2_SALT}();
gateway.initialize(GUARDIAN, SUCCINCT_FEE_VAULT, PROVER);

// Write address
writeEnvAddress(DEPLOYMENT_FILE, "SUCCINCT_GATEWAY", address(gateway));
writeEnvAddress(DEPLOYMENT_FILE, "SUCCINCT_GATEWAY_IMPL", address(gatewayImpl));
}
}
41 changes: 19 additions & 22 deletions contracts/src/SuccinctGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ pragma solidity ^0.8.16;
import {ISuccinctGateway, WhitelistStatus} from "./interfaces/ISuccinctGateway.sol";
import {IFunctionVerifier} from "./interfaces/IFunctionVerifier.sol";
import {FunctionRegistry} from "./FunctionRegistry.sol";
import {TimelockedUpgradeable} from "./upgrades/TimelockedUpgradeable.sol";
import {IFeeVault} from "./payments/interfaces/IFeeVault.sol";

contract SuccinctGateway is ISuccinctGateway, FunctionRegistry, TimelockedUpgradeable {
import {Initializable} from "@openzeppelin-upgradeable/contracts/proxy/utils/Initializable.sol";
import {OwnableUpgradeable} from "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol";

contract SuccinctGateway is
ISuccinctGateway,
FunctionRegistry,
Initializable,
OwnableUpgradeable
{
/// @notice The address of the fee vault.
address public feeVault;

Expand Down Expand Up @@ -61,22 +67,17 @@ contract SuccinctGateway is ISuccinctGateway, FunctionRegistry, TimelockedUpgrad
_;
}

/// @dev Version of the contract, used for tracking upgrades.
function VERSION() external pure override returns (string memory) {
return "1.0.1";
}

/// @notice Initializes the contract.
/// @notice Initializes the contract. Only callable once, and only callable by deployer.
/// @param _owner The address of the owner of the contract.
/// @param _feeVault The address of the fee vault.
/// @param _timelock The address of the timelock contract.
/// @param _guardian The address of the guardian.
function initialize(address _feeVault, address _timelock, address _guardian)
/// @param _defaultProver The address of the default prover.
function initialize(address _owner, address _feeVault, address _defaultProver)
external
initializer
{
_transferOwnership(_owner);
feeVault = _feeVault;
isCallback = false;
__TimelockedUpgradeable_init(_timelock, _guardian);
allowedProvers[bytes32(0)][_defaultProver] = true;
}

/// @notice Creates a onchain request for a proof. The output and proof is fulfilled asynchronously
Expand Down Expand Up @@ -320,29 +321,29 @@ contract SuccinctGateway is ISuccinctGateway, FunctionRegistry, TimelockedUpgrad

/// @notice Add a default prover.
/// @param _prover The address of the prover to add.
function addDefaultProver(address _prover) external onlyGuardian {
function addDefaultProver(address _prover) external onlyOwner {
allowedProvers[bytes32(0)][_prover] = true;
emit ProverUpdated(bytes32(0), _prover, true);
}

/// @notice Remove a default prover.
/// @param _prover The address of the prover to remove.
function removeDefaultProver(address _prover) external onlyGuardian {
function removeDefaultProver(address _prover) external onlyOwner {
delete allowedProvers[bytes32(0)][_prover];
emit ProverUpdated(bytes32(0), _prover, false);
}

/// @notice Sets the fee vault to a new address. Can be set to address(0) to disable fees.
/// @param _feeVault The address of the fee vault.
function setFeeVault(address _feeVault) external onlyGuardian {
function setFeeVault(address _feeVault) external onlyOwner {
emit SetFeeVault(feeVault, _feeVault);
feeVault = _feeVault;
}

/// @notice Recovers stuck ETH from the contract.
/// @param _to The address to send the ETH to.
/// @param _amount The wei amount of ETH to send.
function recover(address _to, uint256 _amount) external onlyGuardian {
function recover(address _to, uint256 _amount) external onlyOwner {
(bool success,) = _to.call{value: _amount}("");
if (!success) {
revert RecoverFailed();
Expand Down Expand Up @@ -394,8 +395,4 @@ contract SuccinctGateway is ISuccinctGateway, FunctionRegistry, TimelockedUpgrad
revert InvalidProof(address(verifier), _inputHash, _outputHash, _proof);
}
}

/// @dev This empty reserved space to add new variables without shifting down storage.
/// See: https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
uint256[49] private __gap;
}
31 changes: 11 additions & 20 deletions contracts/src/payments/SuccinctFeeVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
pragma solidity ^0.8.16;

import {IFeeVault} from "./interfaces/IFeeVault.sol";
import {TimelockedUpgradeable} from "../upgrades/TimelockedUpgradeable.sol";
import {Initializable} from "@openzeppelin-upgradeable/contracts/proxy/utils/Initializable.sol";
import {OwnableUpgradeable} from "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

Expand All @@ -18,7 +19,7 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
/// Any overspent fees will be used for future requests, so it may be more suitable to
/// make a bulk deposit.
/// @dev Address(0) is used to represent native currency in places where token address is specified.
contract SuccinctFeeVault is IFeeVault, TimelockedUpgradeable {
contract SuccinctFeeVault is IFeeVault, Initializable, OwnableUpgradeable {
using SafeERC20 for IERC20;

/// @notice Tracks the amount of active balance that an account has for Succinct services.
Expand All @@ -35,27 +36,21 @@ contract SuccinctFeeVault is IFeeVault, TimelockedUpgradeable {
_;
}

/// @dev Version of the contract, used for tracking upgrades.
function VERSION() external pure override returns (string memory) {
return "1.0.1";
}

/// @dev Initializes the contract.
/// @param _timelock The address of the timelock contract.
/// @param _guardian The address of the guardian.
function initialize(address _timelock, address _guardian) external initializer {
__TimelockedUpgradeable_init(_timelock, _guardian);
/// @notice Initializes the contract.
/// @param _owner The address of the owner of the contract.
function initialize(address _owner) external initializer {
_transferOwnership(_owner);
}

/// @notice Add the specified deductor.
/// @param _deductor The address of the deductor to add.
function addDeductor(address _deductor) external onlyGuardian {
function addDeductor(address _deductor) external onlyOwner {
allowedDeductors[_deductor] = true;
}

/// @notice Remove the specified deductor.
/// @param _deductor The address of the deductor to remove.
function removeDeductor(address _deductor) external onlyGuardian {
function removeDeductor(address _deductor) external onlyOwner {
allowedDeductors[_deductor] = false;
}

Expand Down Expand Up @@ -136,7 +131,7 @@ contract SuccinctFeeVault is IFeeVault, TimelockedUpgradeable {
/// @notice Collect the specified amount of native currency.
/// @param _to The address to send the collected native currency to.
/// @param _amount The amount of native currency to collect.
function collectNative(address _to, uint256 _amount) external onlyGuardian {
function collectNative(address _to, uint256 _amount) external onlyOwner {
if (address(this).balance < _amount) {
revert InsufficientBalance(address(0), _amount);
}
Expand All @@ -153,7 +148,7 @@ contract SuccinctFeeVault is IFeeVault, TimelockedUpgradeable {
/// @param _to The address to send the collected tokens to.
/// @param _token The address of the token to collect.
/// @param _amount The amount of the token to collect.
function collect(address _to, address _token, uint256 _amount) external onlyGuardian {
function collect(address _to, address _token, uint256 _amount) external onlyOwner {
if (_token == address(0)) {
revert InvalidToken(_token);
}
Expand All @@ -165,8 +160,4 @@ contract SuccinctFeeVault is IFeeVault, TimelockedUpgradeable {

emit Collected(_to, _token, _amount);
}

/// @dev This empty reserved space to add new variables without shifting down storage.
/// See: https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
uint256[50] private __gap;
}
Loading
Loading