Skip to content

Commit

Permalink
chore(protocol): remove unused SGX code (#16390)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Mar 11, 2024
1 parent c64ec19 commit 1bea8b4
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 798 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,6 @@ pragma solidity 0.8.24;
/// @title ISigVerifyLib
/// @custom:security-contact security@taiko.xyz
interface ISigVerifyLib {
enum KeyType {
RSA,
ECDSA
}

struct PublicKey {
KeyType keyType;
// If RSA, pubKey = abi.encodePacked(exponent, modulus)
// If ECDSA, pubKey = abi.encodePacked(gx, gy)
bytes pubKey;
}

enum CertSigAlgorithm {
Sha256WithRSAEncryption,
Sha1WithRSAEncryption
}

struct Certificate {
// Asn.1 DER encoding of the to-be-signed certificate
bytes tbsCertificate;
PublicKey publicKey;
bytes signature;
CertSigAlgorithm sigAlg;
}

enum Algorithm {
RS256,
ES256,
RS1
}

function verifyAttStmtSignature(
bytes memory tbs,
bytes memory signature,
PublicKey memory publicKey,
Algorithm alg
)
external
view
returns (bool);

function verifyCertificateSignature(
bytes memory tbs,
bytes memory signature,
PublicKey memory publicKey,
CertSigAlgorithm alg
)
external
view
returns (bool);

function verifyRS256Signature(
bytes memory tbs,
bytes memory signature,
bytes memory publicKey
)
external
view
returns (bool sigValid);

function verifyRS1Signature(
bytes memory tbs,
bytes memory signature,
bytes memory publicKey
)
external
view
returns (bool sigValid);

function verifyES256Signature(
bytes memory tbs,
bytes memory signature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ library NodePtr {
function ixs(uint256 self) internal pure returns (uint256) {
return uint80(self);
}
// Unpack first content byte index

// Unpack first content byte index
function ixf(uint256 self) internal pure returns (uint256) {
return uint80(self >> 80);
}
// Unpack last content byte index

// Unpack last content byte index
function ixl(uint256 self) internal pure returns (uint256) {
return uint80(self >> 160);
}
Expand Down Expand Up @@ -48,16 +48,6 @@ library Asn1Decode {
return _readNodeLength(der, 0);
}

/*
* @dev Get the root node of an ASN1 structure that's within a bit string value
* @param der The DER-encoded ASN1 structure
* @return A pointer to the outermost node
*/
function rootOfBitStringAt(bytes memory der, uint256 ptr) internal pure returns (uint256) {
require(der[ptr.ixs()] == 0x03, "Not type BIT STRING");
return _readNodeLength(der, ptr.ixf() + 1);
}

/*
* @dev Get the root node of an ASN1 structure that's within an octet string value
* @param der The DER-encoded ASN1 structure
Expand Down Expand Up @@ -89,19 +79,6 @@ library Asn1Decode {
return _readNodeLength(der, ptr.ixf());
}

/*
* @dev Use for looping through children of a node (either i or j).
* @param i Pointer to an ASN1 node
* @param j Pointer to another ASN1 node of the same ASN1 structure
* @return true iff j is child of i or i is child of j.
*/
function isChildOf(uint256 i, uint256 j) internal pure returns (bool) {
return (
((i.ixf() <= j.ixs()) && (j.ixl() <= i.ixl()))
|| ((j.ixf() <= i.ixs()) && (i.ixl() <= j.ixl()))
);
}

/*
* @dev Extract value of node from DER-encoded structure
* @param der The der-encoded ASN1 structure
Expand All @@ -122,46 +99,6 @@ library Asn1Decode {
return der.substring(ptr.ixs(), ptr.ixl() + 1 - ptr.ixs());
}

/*
* @dev Extract value of node from DER-encoded structure
* @param der The DER-encoded ASN1 structure
* @param ptr Points to the indices of the current node
* @return Value bytes of node as bytes32
*/
function bytes32At(bytes memory der, uint256 ptr) internal pure returns (bytes32) {
return der.readBytesN(ptr.ixf(), ptr.ixl() + 1 - ptr.ixf());
}

/*
* @dev Extract value of node from DER-encoded structure
* @param der The der-encoded ASN1 structure
* @param ptr Points to the indices of the current node
* @return Uint value of node
*/
function uintAt(bytes memory der, uint256 ptr) internal pure returns (uint256) {
require(der[ptr.ixs()] == 0x02, "Not type INTEGER");
require(der[ptr.ixf()] & 0x80 == 0, "Not positive");
uint256 len = ptr.ixl() + 1 - ptr.ixf();
return uint256(der.readBytesN(ptr.ixf(), len) >> (32 - len) * 8);
}

/*
* @dev Extract value of a positive integer node from DER-encoded structure
* @param der The DER-encoded ASN1 structure
* @param ptr Points to the indices of the current node
* @return Value bytes of a positive integer node
*/
function uintBytesAt(bytes memory der, uint256 ptr) internal pure returns (bytes memory) {
require(der[ptr.ixs()] == 0x02, "Not type INTEGER");
require(der[ptr.ixf()] & 0x80 == 0, "Not positive");
uint256 valueLength = ptr.ixl() + 1 - ptr.ixf();
if (der[ptr.ixf()] == 0) {
return der.substring(ptr.ixf() + 1, valueLength - 1);
} else {
return der.substring(ptr.ixf(), valueLength);
}
}

function keccakOfBytesAt(bytes memory der, uint256 ptr) internal pure returns (bytes32) {
return der.keccak(ptr.ixf(), ptr.ixl() + 1 - ptr.ixf());
}
Expand All @@ -170,20 +107,6 @@ library Asn1Decode {
return der.keccak(ptr.ixs(), ptr.ixl() + 1 - ptr.ixs());
}

/*
* @dev Extract value of bitstring node from DER-encoded structure
* @param der The DER-encoded ASN1 structure
* @param ptr Points to the indices of the current node
* @return Value of bitstring converted to bytes
*/
function bitstringAt(bytes memory der, uint256 ptr) internal pure returns (bytes memory) {
require(der[ptr.ixs()] == 0x03, "ixs Not type BIT STRING 0x03");
// Only 00 padded bitstr can be converted to bytestr!
require(der[ptr.ixf()] == 0x00, "ixf Not 0");
uint256 valueLength = ptr.ixl() + 1 - ptr.ixf();
return der.substring(ptr.ixf() + 1, valueLength - 1);
}

function _readNodeLength(bytes memory der, uint256 ix) private pure returns (uint256) {
uint256 length;
uint80 ixFirstContentByte;
Expand Down
Loading

0 comments on commit 1bea8b4

Please sign in to comment.