Skip to content

Commit

Permalink
no hardcoded values in setUseZK
Browse files Browse the repository at this point in the history
  • Loading branch information
zobront committed Jul 25, 2024
1 parent 1fa6b80 commit 0a98735
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 508 deletions.
3 changes: 2 additions & 1 deletion packages/contracts-bedrock/scripts/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,8 @@ contract Deploy is Deployer {
cfg.finalizationPeriodSeconds(),
cfg.l2ChainID(),
cfg.zkVKey(),
cfg.l2OutputOracleStartingOutputRoot()
cfg.l2OutputOracleStartingOutputRoot(),
cfg.verifierGateway()
)
)
});
Expand Down
23 changes: 18 additions & 5 deletions packages/contracts-bedrock/scripts/DeployConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ address public superchainConfigGuardian;
bool public useZK;
bytes32 public zkVKey;
bytes32 public l2OutputOracleStartingOutputRoot;
address public verifierGateway;

bool public useCustomGasToken;
address public customGasTokenAddress;
Expand Down Expand Up @@ -142,6 +143,7 @@ address public superchainConfigGuardian;
useZK = _readOr(_json, "$.useZK", false);
zkVKey = _readOr(_json, "$.zkVKey", bytes32(0));
l2OutputOracleStartingOutputRoot = _readOr(_json, "$.l2OutputOracleStartingOutputRoot", bytes32(0));
verifierGateway = _readOr(_json, "$.verifierGateway", 0x3B6041173B80E77f038f3F2C0f9744f04837185e);

faultGameAbsolutePrestate = stdJson.readUint(_json, "$.faultGameAbsolutePrestate");
faultGameMaxDepth = stdJson.readUint(_json, "$.faultGameMaxDepth");
Expand Down Expand Up @@ -212,15 +214,26 @@ address public superchainConfigGuardian;
}

/// @notice Allow the `useZK` config to be overridden in testing environments
function setUseZK(bool _useZK, bytes32 _zkVKey, bytes32 _startingL2OutputRoot) public {
function setUseZK(
bool _useZK,
bytes32 _zkVKey,
bytes32 _startingL2OutputRoot,
uint256 _startingL2OutputTimestamp,
uint256 _startingL2OutputBlockNumber,
uint256 _submissionInterval,
address _verifierGateway
) public {
useZK = _useZK;
zkVKey = _zkVKey;

l2OutputOracleStartingOutputRoot = _startingL2OutputRoot;
finalizationPeriodSeconds = 0;
l2OutputOracleSubmissionInterval = 900;
_l2OutputOracleStartingTimestamp = 1721925325;
l2OutputOracleStartingBlockNumber = 123163274;
_l2OutputOracleStartingTimestamp = int256(_startingL2OutputTimestamp);
l2OutputOracleStartingBlockNumber = _startingL2OutputBlockNumber;

l2OutputOracleSubmissionInterval = _submissionInterval;
verifierGateway = _verifierGateway;

finalizationPeriodSeconds = 0;
}

/// @notice Allow the `fundDevAccounts` config to be overridden.
Expand Down
44 changes: 20 additions & 24 deletions packages/contracts-bedrock/src/L1/ZKL2OutputOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract ZKL2OutputOracle is Initializable, ISemver {
uint public chainId;

bytes32 public vkey;
SP1VerifierGateway public verifier;
SP1VerifierGateway public verifierGateway;

mapping (uint => bytes32) public historicBlockHashes;

Expand Down Expand Up @@ -88,7 +88,8 @@ contract ZKL2OutputOracle is Initializable, ISemver {
_finalizationPeriodSeconds: 0,
_chainId: 0,
_vkey: bytes32(0),
_startingOutputRoot: bytes32(0)
_startingOutputRoot: bytes32(0),
_verifierGateway: address(0)
});
}

Expand All @@ -105,16 +106,17 @@ contract ZKL2OutputOracle is Initializable, ISemver {
/// @param _vkey The verification key of the SP1 program.
/// @param _startingOutputRoot The output root of the starting block.
function initialize(
uint256 _submissionInterval, // 1800 = once per hour
uint256 _l2BlockTime, // 2
uint256 _startingBlockNumber, // ecotone genesis?
uint256 _startingTimestamp, // ecotone genesis?
address _proposer, // set to addr 0 to make permissionless
address _challenger, // set to addr 0 to remove safeguard
uint256 _finalizationPeriodSeconds, // 0
uint256 _chainId, // 10
uint256 _submissionInterval,
uint256 _l2BlockTime,
uint256 _startingBlockNumber,
uint256 _startingTimestamp,
address _proposer,
address _challenger,
uint256 _finalizationPeriodSeconds,
uint256 _chainId,
bytes32 _vkey,
bytes32 _startingOutputRoot
bytes32 _startingOutputRoot,
address _verifierGateway
)
public
initializer
Expand All @@ -135,6 +137,7 @@ contract ZKL2OutputOracle is Initializable, ISemver {
finalizationPeriodSeconds = _finalizationPeriodSeconds;
chainId = _chainId;
vkey = _vkey;
verifierGateway = SP1VerifierGateway(_verifierGateway);

l2Outputs.push(
Types.OutputProposal({
Expand All @@ -145,11 +148,6 @@ contract ZKL2OutputOracle is Initializable, ISemver {
);
}

function upgradeVerifier(SP1VerifierGateway _newVerifier) external {
require(msg.sender == proposer, "L2OutputOracle: only the proposer address can upgrade the verifier");
verifier = _newVerifier;
}

/// @notice Getter for the submissionInterval.
/// Public getter is legacy and will be removed in the future. Use `submissionInterval` instead.
/// @return Submission interval.
Expand Down Expand Up @@ -235,9 +233,7 @@ contract ZKL2OutputOracle is Initializable, ISemver {
external
payable
{
if (proposer != address(0)) {
require(msg.sender == proposer, "L2OutputOracle: only the proposer address can propose new outputs");
}
require(msg.sender == proposer || proposer == address(0), "L2OutputOracle: only the proposer address can propose new outputs");

require(
_l2BlockNumber == nextBlockNumber(),
Expand All @@ -257,14 +253,14 @@ contract ZKL2OutputOracle is Initializable, ISemver {
);

PublicValuesStruct memory publicValues = PublicValuesStruct({
l1Head: _l1BlockHash, // either current
l2PreRoot: l2Outputs[nextOutputIndex() - 1].outputRoot, // last one submitted
claimRoot: _outputRoot, // anything they want
claimBlockNum: _l2BlockNumber, // constrained to last block number + 1800
l1Head: _l1BlockHash,
l2PreRoot: l2Outputs[nextOutputIndex() - 1].outputRoot,
claimRoot: _outputRoot,
claimBlockNum: _l2BlockNumber,
chainId: chainId
});

verifier.verifyProof(vkey, abi.encode(publicValues), _proof);
verifierGateway.verifyProof(vkey, abi.encode(publicValues), _proof);

emit OutputProposed(_outputRoot, nextOutputIndex(), _l2BlockNumber, block.timestamp);

Expand Down
Loading

0 comments on commit 0a98735

Please sign in to comment.