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(protocol): adopt optimism new trie codebase #15608

Merged
merged 11 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
10 changes: 5 additions & 5 deletions packages/protocol/contracts/L1/verifiers/PseZkVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pragma solidity 0.8.24;

import "../../4844/Lib4844.sol";
import "../../common/EssentialContract.sol";
import "../../thirdparty/LibBytesUtils.sol";
import "../../thirdparty/optimism/Bytes.sol";
import "../TaikoData.sol";
import "./IVerifier.sol";

Expand Down Expand Up @@ -91,14 +91,14 @@ contract PseZkVerifier is EssentialContract, IVerifier {
}

// Validate the instance using bytes utilities.
bool verified = LibBytesUtils.equal(
LibBytesUtils.slice(zkProof.zkp, 0, 32), bytes.concat(bytes16(0), bytes16(instance))
bool verified = Bytes.equal(
Bytes.slice(zkProof.zkp, 0, 32), bytes.concat(bytes16(0), bytes16(instance))
);

if (!verified) revert L1_INVALID_PROOF();

verified = LibBytesUtils.equal(
LibBytesUtils.slice(zkProof.zkp, 32, 32),
verified = Bytes.equal(
Bytes.slice(zkProof.zkp, 32, 32),
bytes.concat(bytes16(0), bytes16(uint128(uint256(instance))))
);
if (!verified) revert L1_INVALID_PROOF();
Expand Down
7 changes: 3 additions & 4 deletions packages/protocol/contracts/L1/verifiers/SgxAndZkVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
pragma solidity 0.8.24;

import "../../common/EssentialContract.sol";
import "../../thirdparty/LibBytesUtils.sol";
import "../../thirdparty/optimism/Bytes.sol";
import "../TaikoData.sol";
import "./IVerifier.sol";

Expand Down Expand Up @@ -44,12 +44,11 @@ contract SgxAndZkVerifier is EssentialContract, IVerifier {
_proof.tier = proof.tier;

// Verify the SGX part
_proof.data = LibBytesUtils.slice(proof.data, 0, SGX_PROOF_SIZE);
_proof.data = Bytes.slice(proof.data, 0, SGX_PROOF_SIZE);
IVerifier(resolve("tier_sgx", false)).verifyProof(ctx, tran, _proof);

// Verify the ZK part
_proof.data =
LibBytesUtils.slice(proof.data, SGX_PROOF_SIZE, (proof.data.length - SGX_PROOF_SIZE));
_proof.data = Bytes.slice(proof.data, SGX_PROOF_SIZE, (proof.data.length - SGX_PROOF_SIZE));
IVerifier(resolve("tier_pse_zkevm", false)).verifyProof(ctx, tran, _proof);
}
}
8 changes: 4 additions & 4 deletions packages/protocol/contracts/L1/verifiers/SgxVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pragma solidity 0.8.24;

import "lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol";
import "../../common/EssentialContract.sol";
import "../../thirdparty/LibBytesUtils.sol";
import "../../thirdparty/optimism/Bytes.sol";
import "../ITaikoL1.sol";
import "./IVerifier.sol";

Expand Down Expand Up @@ -126,9 +126,9 @@ contract SgxVerifier is EssentialContract, IVerifier {
// 4 bytes + 20 bytes + 65 bytes (signature) = 89
if (proof.data.length != 89) revert SGX_INVALID_PROOF();

uint32 id = uint32(bytes4(LibBytesUtils.slice(proof.data, 0, 4)));
address newInstance = address(bytes20(LibBytesUtils.slice(proof.data, 4, 20)));
bytes memory signature = LibBytesUtils.slice(proof.data, 24);
uint32 id = uint32(bytes4(Bytes.slice(proof.data, 0, 4)));
address newInstance = address(bytes20(Bytes.slice(proof.data, 4, 20)));
bytes memory signature = Bytes.slice(proof.data, 24);

address oldInstance =
ECDSA.recover(getSignedHash(tran, newInstance, ctx.prover, ctx.metaHash), signature);
Expand Down
24 changes: 19 additions & 5 deletions packages/protocol/contracts/signal/SignalService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pragma solidity 0.8.24;
import "lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol";
import "../common/AuthorizableContract.sol";
import "../common/ICrossChainSync.sol";
import "../thirdparty/LibSecureMerkleTrie.sol";
import "../thirdparty/optimism/trie/SecureMerkleTrie.sol";
import "../thirdparty/optimism/rlp/RLPReader.sol";
import "./ISignalService.sol";

/// @title SignalService
Expand Down Expand Up @@ -87,6 +88,7 @@ contract SignalService is AuthorizableContract, ISignalService {
)
public
view
virtual
returns (bool)
{
if (skipProofCheck()) return true;
Expand Down Expand Up @@ -130,18 +132,19 @@ contract SignalService is AuthorizableContract, ISignalService {
hop.signalRootRelay,
hop.signalRoot // as a signal
);
bool verified = LibSecureMerkleTrie.verifyInclusionProof(
bytes.concat(slot), hex"01", hop.storageProof, signalRoot

bool verified = SecureMerkleTrie.verifyInclusionProof(
bytes.concat(slot), hex"01", _transcode(hop.storageProof), signalRoot
);
if (!verified) return false;

signalRoot = hop.signalRoot;
}

return LibSecureMerkleTrie.verifyInclusionProof(
return SecureMerkleTrie.verifyInclusionProof(
bytes.concat(getSignalSlot(srcChainId, app, signal)),
hex"01",
p.storageProof,
_transcode(p.storageProof),
signalRoot
);
}
Expand Down Expand Up @@ -170,6 +173,17 @@ contract SignalService is AuthorizableContract, ISignalService {
return false;
}

/// @notice Translate a RLP-encoded list of RLP-encoded TrieNodes into a list of LP-encoded
/// TrieNodes.
function _transcode(bytes memory proof) internal pure returns (bytes[] memory proofs) {
RLPReader.RLPItem[] memory nodes = RLPReader.readList(proof);
proofs = new bytes[](nodes.length);

for (uint256 i; i < nodes.length; ++i) {
proofs[i] = RLPReader.readBytes(nodes[i]);
}
}
dantaik marked this conversation as resolved.
Show resolved Hide resolved

function _authorizePause(address) internal pure override {
revert SS_UNSUPPORTED();
}
Expand Down
128 changes: 0 additions & 128 deletions packages/protocol/contracts/thirdparty/LibBytesUtils.sol

This file was deleted.

Loading
Loading