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

refactor(protocol): improve MainnetSgxVerifier #17811

Merged
merged 6 commits into from
Jul 18, 2024
Merged
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
21 changes: 21 additions & 0 deletions packages/protocol/contracts/mainnet/MainnetRiscZeroVerifier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "../verifiers/RiscZeroVerifier.sol";
import "./LibRollupAddressCache.sol";

/// @title MainnetRiscZeroVerifier
/// @dev This contract shall be deployed to replace its parent contract on Ethereum for Taiko
/// mainnet to reduce gas cost.
/// @notice See the documentation in {RiscZeroVerifier}.
/// @custom:security-contact [email protected]
contract MainnetRiscZeroVerifier is RiscZeroVerifier {
function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) {
(bool found, address addr) = LibRollupAddressCache.getAddress(_chainId, _name);
return found ? addr : super._getAddress(_chainId, _name);
}

function taikoChainId() internal pure override returns (uint64) {
return LibNetwork.TAIKO_MAINNET;
}
}
4 changes: 4 additions & 0 deletions packages/protocol/contracts/mainnet/MainnetSgxVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ contract MainnetSgxVerifier is SgxVerifier {
(bool found, address addr) = LibRollupAddressCache.getAddress(_chainId, _name);
return found ? addr : super._getAddress(_chainId, _name);
}

function taikoChainId() internal pure override returns (uint64) {
return LibNetwork.TAIKO_MAINNET;
}
}
7 changes: 5 additions & 2 deletions packages/protocol/contracts/verifiers/RiscZeroVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ contract RiscZeroVerifier is EssentialContract, IVerifier {
revert RISC_ZERO_INVALID_IMAGE_ID();
}

uint64 chainId = ITaikoL1(resolve(LibStrings.B_TAIKO, false)).getConfig().chainId;
bytes32 hash = LibPublicInput.hashPublicInputs(
_tran, address(this), address(0), _ctx.prover, _ctx.metaHash, chainId
_tran, address(this), address(0), _ctx.prover, _ctx.metaHash, taikoChainId()
);

// journalDigest is the sha256 hash of the hashed public input
Expand All @@ -88,4 +87,8 @@ contract RiscZeroVerifier is EssentialContract, IVerifier {
revert RISC_ZERO_INVALID_PROOF();
}
}

function taikoChainId() internal view virtual returns (uint64) {
return ITaikoL1(resolve(LibStrings.B_TAIKO, false)).getConfig().chainId;
}
}
8 changes: 5 additions & 3 deletions packages/protocol/contracts/verifiers/SgxVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,9 @@ contract SgxVerifier is EssentialContract, IVerifier {
uint32 id = uint32(bytes4(_proof.data[:4]));
address newInstance = address(bytes20(_proof.data[4:24]));

uint64 chainId = ITaikoL1(resolve(LibStrings.B_TAIKO, false)).getConfig().chainId;

address oldInstance = ECDSA.recover(
LibPublicInput.hashPublicInputs(
_tran, address(this), newInstance, _ctx.prover, _ctx.metaHash, chainId
_tran, address(this), newInstance, _ctx.prover, _ctx.metaHash, taikoChainId()
),
_proof.data[24:]
);
Expand All @@ -171,6 +169,10 @@ contract SgxVerifier is EssentialContract, IVerifier {
}
}

function taikoChainId() internal view virtual returns (uint64) {
return ITaikoL1(resolve(LibStrings.B_TAIKO, false)).getConfig().chainId;
}

function _addInstances(
address[] memory _instances,
bool instantValid
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/deployments/mainnet-contract-logs-L1.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@
- Upgraded from `0x3f54067EF5d8B414Bdb1945cdF482BD158Aad175` to `0xf381868DD6B2aC8cca468D63B42F9040DE2257E9` @commit`b90b932` @tx`0x416560cd96dc75ccffebe889e8d1ab3e08b33f814dc4a2bf7c6f9555071d1f6f`
- Upgraded from `0xf381868DD6B2aC8cca468D63B42F9040DE2257E9` to `0xB0b782cf0fCEce896E0C041F8e54f86cA4cC8e9F` @commit`a3faee0` @tx`eth:0x40A2aCCbd92BCA938b02010E17A5b8929b49130D`
- Upgraded from `0xB0b782cf0fCEce896E0C041F8e54f86cA4cC8e9F` to `0xEE5F6648307319263FFBaE91f68ac700b188fF24` @commit`be34059` @tx`0x170617251f2345eda4bcbd29e316caa0b014602a44244c60b963382ac7da7748`
- todos:
- deploy again to enable caching of taikoChainId()

#### guardian_prover_minority

Expand Down