Skip to content

Commit

Permalink
refactor(protocol): improve MainnetSgxVerifier (#17811)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Jul 18, 2024
1 parent 5b43df1 commit 4e7a421
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
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 security@taiko.xyz
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

0 comments on commit 4e7a421

Please sign in to comment.