Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Feb 6, 2025
1 parent 3b527dd commit 9c8bc42
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ contract AutomataDcapV3Attestation is IAttestation, EssentialContract {
external
onlyOwner
{
for (uint256 i; i < serialNumBatch.length; ++i) {
uint256 size = serialNumBatch.length;
for (uint256 i; i < size; ++i) {
if (serialNumIsRevoked[index][serialNumBatch[i]]) {
continue;
}
Expand All @@ -108,7 +109,8 @@ contract AutomataDcapV3Attestation is IAttestation, EssentialContract {
external
onlyOwner
{
for (uint256 i; i < serialNumBatch.length; ++i) {
uint256 size = serialNumBatch.length;
for (uint256 i; i < size; ++i) {
if (!serialNumIsRevoked[index][serialNumBatch[i]]) {
continue;
}
Expand Down Expand Up @@ -208,7 +210,8 @@ contract AutomataDcapV3Attestation is IAttestation, EssentialContract {
bool isvprodidMatched = quoteEnclaveReport.isvProdId == enclaveId.isvprodid;

bool tcbFound;
for (uint256 i; i < enclaveId.tcbLevels.length; ++i) {
uint256 size = enclaveId.tcbLevels.length;
for (uint256 i; i < size; ++i) {
EnclaveIdStruct.TcbLevel memory tcb = enclaveId.tcbLevels[i];
if (tcb.tcb.isvsvn <= quoteEnclaveReport.isvSvn) {
tcbFound = true;
Expand All @@ -231,7 +234,8 @@ contract AutomataDcapV3Attestation is IAttestation, EssentialContract {
pure
returns (bool, TCBInfoStruct.TCBStatus status)
{
for (uint256 i; i < tcb.tcbLevels.length; ++i) {
uint256 size = tcb.tcbLevels.length;
for (uint256 i; i < size; ++i) {
TCBInfoStruct.TCBLevelObj memory current = tcb.tcbLevels[i];
bool pceSvnIsHigherOrGreater = pck.sgxExtension.pcesvn >= current.pcesvn;
bool cpuSvnsAreHigherOrGreater = _isCpuSvnHigherOrGreater(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ contract PEMCertChainLib is IPEMCertChainLib {
string memory contentSlice = LibString.slice(pemData, contentStart, endPos);
string[] memory split = LibString.split(contentSlice, string(delimiter));
string memory contentStr;
uint256 size = split.length;

for (uint256 i; i < split.length; ++i) {
for (uint256 i; i < size; ++i) {
contentStr = LibString.concat(contentStr, split[i]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ library V3Parser {
}

function littleEndianDecode(bytes memory encoded) private pure returns (uint256 decoded) {
for (uint256 i; i < encoded.length; ++i) {
uint256 size = encoded.length;
for (uint256 i; i < size; ++i) {
uint256 digits = uint256(uint8(bytes1(encoded[i])));
uint256 upperDigit = digits / 16;
uint256 lowerDigit = digits % 16;
Expand Down
3 changes: 2 additions & 1 deletion packages/protocol/contracts/layer1/hekla/HeklaTaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ contract HeklaTaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20Vo
returns (bool)
{
if (recipients.length != amounts.length) revert TT_INVALID_PARAM();
for (uint256 i; i < recipients.length; ++i) {
uint256 size = recipients.length;
for (uint256 i; i < size; ++i) {
_transfer(msg.sender, recipients[i], amounts[i]);
}
return true;
Expand Down
5 changes: 3 additions & 2 deletions packages/protocol/contracts/layer1/token/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ contract TaikoToken is TaikoTokenBase {
external
returns (bool)
{
if (recipients.length != amounts.length) revert TT_INVALID_PARAM();
for (uint256 i; i < recipients.length; ++i) {
uint256 size = recipients.length;
if (size != amounts.length) revert TT_INVALID_PARAM();
for (uint256 i; i < size; ++i) {
_transfer(msg.sender, recipients[i], amounts[i]);
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ contract Risc0Verifier is EssentialContract, IVerifier {
// First public input is the block proving program key
publicInputs[0] = blockImageId;
// All other inputs are the block program public inputs (a single 32 byte value)
for (uint256 i; i < _ctxs.length; ++i) {
uint256 size = _ctxs.length;
for (uint256 i; i < size; ++i) {
publicInputs[i + 1] = LibPublicInput.hashPublicInputs(
_ctxs[i].transition, address(this), address(0), _ctxs[i].metaHash, taikoChainId
);
Expand Down
4 changes: 3 additions & 1 deletion packages/protocol/contracts/layer1/verifiers/SP1Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ contract SP1Verifier is EssentialContract, IVerifier {
// First public input is the block proving program key
publicInputs[0] = blockProvingProgram;
// All other inputs are the block program public inputs (a single 32 byte value)
for (uint256 i; i < _ctxs.length; ++i) {

uint256 size = _ctxs.length;
for (uint256 i; i < size; ++i) {
publicInputs[i + 1] = LibPublicInput.hashPublicInputs(
_ctxs[i].transition, address(this), address(0), _ctxs[i].metaHash, taikoChainId
);
Expand Down
11 changes: 7 additions & 4 deletions packages/protocol/contracts/layer1/verifiers/SgxVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ contract SgxVerifier is EssentialContract, IVerifier {
external
onlyFromOwnerOrNamed(LibStrings.B_SGX_WATCHDOG)
{
for (uint256 i; i < _ids.length; ++i) {
uint256 size = _ids.length;
for (uint256 i; i < size; ++i) {
uint256 idx = _ids[i];

require(instances[idx].addr != address(0), SGX_INVALID_INSTANCE());
Expand Down Expand Up @@ -162,7 +163,8 @@ contract SgxVerifier is EssentialContract, IVerifier {
publicInputs[0] = bytes32(uint256(uint160(oldInstance)));
publicInputs[1] = bytes32(uint256(uint160(newInstance)));
// All other inputs are the block program public inputs (a single 32 byte value)
for (uint256 i; i < _ctxs.length; ++i) {
uint256 size = _ctxs.length;
for (uint256 i; i < size; ++i) {
// TODO(Yue): For now this assumes the new instance public key to remain the same
publicInputs[i + 2] = LibPublicInput.hashPublicInputs(
_ctxs[i].transition, address(this), newInstance, _ctxs[i].metaHash, taikoChainId
Expand All @@ -187,15 +189,16 @@ contract SgxVerifier is EssentialContract, IVerifier {
private
returns (uint256[] memory ids)
{
ids = new uint256[](_instances.length);
uint256 size = _instances.length;
ids = new uint256[](size);

uint64 validSince = uint64(block.timestamp);

if (!instantValid) {
validSince += INSTANCE_VALIDITY_DELAY;
}

for (uint256 i; i < _instances.length; ++i) {
for (uint256 i; i < size; ++i) {
require(!addressRegistered[_instances[i]], SGX_ALREADY_ATTESTED());

addressRegistered[_instances[i]] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ abstract contract SgxVerifierBase is EssentialContract {
external
onlyFromOwnerOrNamed(LibStrings.B_SGX_WATCHDOG)
{
for (uint256 i; i < _ids.length; ++i) {
uint256 size = _ids.length;
for (uint256 i; i < size; ++i) {
uint256 idx = _ids[i];

require(instances[idx].addr != address(0), SGX_INVALID_INSTANCE());
Expand All @@ -129,15 +130,16 @@ abstract contract SgxVerifierBase is EssentialContract {
internal
returns (uint256[] memory ids)
{
ids = new uint256[](_instances.length);
uint256 size = _instances.length;
ids = new uint256[](size);

uint64 validSince = uint64(block.timestamp);

if (!instantValid) {
validSince += INSTANCE_VALIDITY_DELAY;
}

for (uint256 i; i < _instances.length; ++i) {
for (uint256 i; i < size; ++i) {
require(!addressRegistered[_instances[i]], SGX_ALREADY_ATTESTED());

addressRegistered[_instances[i]] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ abstract contract ComposeVerifier is EssentialContract, IVerifier {
onlyFromNamed(LibStrings.B_TAIKO)
{
SubProof[] memory subProofs = abi.decode(_proof, (SubProof[]));
address[] memory verifiers = new address[](subProofs.length);
uint256 size = subProofs.length;
address[] memory verifiers = new address[](size);

address verifier;

for (uint256 i; i < subProofs.length; ++i) {
for (uint256 i; i < size; ++i) {
require(subProofs[i].verifier != address(0), CV_INVALID_SUB_VERIFIER());
require(subProofs[i].verifier > verifier, CV_INVALID_SUB_VERIFIER_ORDER());

Expand Down
10 changes: 7 additions & 3 deletions packages/protocol/contracts/shared/tokenvault/ERC1155Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable {
{
if (msg.value < _op.fee) revert VAULT_INSUFFICIENT_FEE();

for (uint256 i; i < _op.amounts.length; ++i) {
if (_op.amounts[i] == 0) revert VAULT_INVALID_AMOUNT();
{
uint256 size = _op.amounts.length;
for (uint256 i; i < size; ++i) {
if (_op.amounts[i] == 0) revert VAULT_INVALID_AMOUNT();
}
}
// Check token interface support
if (!_op.token.supportsInterface(type(IERC1155).interfaceId)) {
Expand Down Expand Up @@ -244,7 +247,8 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable {
IERC1155(_op.token).safeBatchTransferFrom(
msg.sender, address(this), _op.tokenIds, _op.amounts, ""
);
for (uint256 i; i < _op.tokenIds.length; ++i) {
uint256 size = _op.tokenIds.length;
for (uint256 i; i < size; ++i) {
IBridgedERC1155(_op.token).burn(_op.tokenIds[i], _op.amounts[i]);
}
} else {
Expand Down
18 changes: 12 additions & 6 deletions packages/protocol/contracts/shared/tokenvault/ERC721Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver {
{
if (msg.value < _op.fee) revert VAULT_INSUFFICIENT_FEE();

for (uint256 i; i < _op.tokenIds.length; ++i) {
if (_op.amounts[i] != 0) revert VAULT_INVALID_AMOUNT();
{
uint256 size = _op.tokenIds.length;
for (uint256 i; i < size; ++i) {
if (_op.amounts[i] != 0) revert VAULT_INVALID_AMOUNT();
}
}

if (!_op.token.supportsInterface(type(IERC721).interfaceId)) {
Expand Down Expand Up @@ -173,14 +176,15 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver {
private
returns (address token_)
{
uint256 size = _tokenIds.length;
if (_ctoken.chainId == block.chainid) {
token_ = _ctoken.addr;
for (uint256 i; i < _tokenIds.length; ++i) {
for (uint256 i; i < size; ++i) {
IERC721(token_).safeTransferFrom(address(this), _to, _tokenIds[i]);
}
} else {
token_ = _getOrDeployBridgedToken(_ctoken);
for (uint256 i; i < _tokenIds.length; ++i) {
for (uint256 i; i < size; ++i) {
IBridgedERC721(token_).mint(_to, _tokenIds[i]);
}
}
Expand All @@ -195,11 +199,13 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver {
private
returns (bytes memory msgData_, CanonicalNFT memory ctoken_)
{
uint256 size = _op.tokenIds.length;
unchecked {
CanonicalNFT storage _ctoken = bridgedToCanonical[_op.token];
if (_ctoken.addr != address(0)) {
ctoken_ = _ctoken;
for (uint256 i; i < _op.tokenIds.length; ++i) {

for (uint256 i; i < size; ++i) {
IERC721(_op.token).safeTransferFrom(msg.sender, address(this), _op.tokenIds[i]);
IBridgedERC721(_op.token).burn(_op.tokenIds[i]);
}
Expand All @@ -211,7 +217,7 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver {
name: safeName(_op.token)
});

for (uint256 i; i < _op.tokenIds.length; ++i) {
for (uint256 i; i < size; ++i) {
IERC721(_op.token).safeTransferFrom(msg.sender, address(this), _op.tokenIds[i]);
}
}
Expand Down

0 comments on commit 9c8bc42

Please sign in to comment.