Skip to content
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
27 changes: 2 additions & 25 deletions src/BlockBuilderPolicy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,18 @@ contract BlockBuilderPolicy is Initializable, UUPSUpgradeable, OwnableUpgradeabl
/// @notice Address of the FlashtestationRegistry contract that verifies TEE quotes
address public registry;

/// @notice Array of supported flashtestation protocol versions
/// @dev Only v1 supported for now, but this will change with a contract upgrade
/// Note: we have to use a non-constant array because solidity only supports constant arrays
/// of value or bytes type. This means in future upgrades the upgrade logic will need to
/// account for adding new versions to the array
uint256[] public SUPPORTED_VERSIONS;

/// @notice Tracks nonces for EIP-712 signatures to prevent replay attacks
mapping(address => uint256) public nonces;

/// @dev Storage gap to allow for future storage variable additions in upgrades
/// @dev This reserves 46 storage slots (out of 50 total - 4 used for approvedWorkloads, registry, SUPPORTED_VERSIONS and nonces)
uint256[46] __gap;
/// @dev This reserves 45 storage slots (out of 50 total - 4 used for approvedWorkloads, registry and nonces)
uint256[45] __gap;

// ============ Errors ============

error WorkloadAlreadyInPolicy();
error WorkloadNotInPolicy();
error UnauthorizedBlockBuilder(address caller); // the teeAddress is not associated with a valid TEE workload
error UnsupportedVersion(uint8 version); // see SUPPORTED_VERSIONS for supported versions
error InvalidNonce(uint256 expected, uint256 provided);
error CommitHashLengthError(uint256 length);

Expand Down Expand Up @@ -124,7 +116,6 @@ contract BlockBuilderPolicy is Initializable, UUPSUpgradeable, OwnableUpgradeabl
__Ownable_init(_initialOwner);
__EIP712_init("BlockBuilderPolicy", "1");
registry = _registry;
SUPPORTED_VERSIONS.push(1);
emit RegistrySet(_registry);
}

Expand Down Expand Up @@ -185,8 +176,6 @@ contract BlockBuilderPolicy is Initializable, UUPSUpgradeable, OwnableUpgradeabl
/// @dev This function is internal because it is only used by the permitVerifyBlockBuilderProof function
/// and it is not needed to be called by other contracts
function _verifyBlockBuilderProof(address teeAddress, uint8 version, bytes32 blockContentHash) internal {
require(isSupportedVersion(version), UnsupportedVersion(version));

// Check if the caller is an authorized TEE block builder for our Policy
(bool allowed, WorkloadId workloadId) = isAllowedPolicy(teeAddress);
require(allowed, UnauthorizedBlockBuilder(teeAddress));
Expand All @@ -203,18 +192,6 @@ contract BlockBuilderPolicy is Initializable, UUPSUpgradeable, OwnableUpgradeabl
emit BlockBuilderProofVerified(teeAddress, workloadId, block.number, version, blockContentHash, commitHash);
}

/// @notice Helper function to check if a given version is supported by this Policy
/// @param version The version to check
/// @return True if the version is supported, false otherwise
function isSupportedVersion(uint8 version) public view returns (bool) {
for (uint256 i = 0; i < SUPPORTED_VERSIONS.length; ++i) {
if (SUPPORTED_VERSIONS[i] == version) {
return true;
}
}
return false;
}

/// @notice Check if this TEE-controlled address has registered a valid TEE workload with the registry, and
/// if the workload is approved under this policy
/// @param teeAddress The TEE-controlled address
Expand Down
28 changes: 0 additions & 28 deletions test/BlockBuilderPolicy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,6 @@ contract BlockBuilderPolicyTest is Test {
);
}

function test_verifyBlockBuilderProof_fails_with_incorrect_version() public {
_registerTEE(mockf200);

// Get actual workloadId and add to policy
(, IFlashtestationRegistry.RegisteredTEE memory registration) = registry.getRegistration(mockf200.teeAddress);
WorkloadId actualWorkloadId = policy.workloadIdForTDRegistration(registration);
policy.addWorkloadToPolicy(actualWorkloadId, mockf200.commitHash, mockf200.sourceLocators);

// Try with unsupported version 2
vm.prank(mockf200.teeAddress);
vm.expectRevert(abi.encodeWithSelector(BlockBuilderPolicy.UnsupportedVersion.selector, 2));
policy.verifyBlockBuilderProof(2, bytes32(0));
}

function test_verifyBlockBuilderProof_fails_with_unregistered_tee() public {
// Add workload to policy but don't register TEE
policy.addWorkloadToPolicy(mockf200.workloadId, mockf200.commitHash, mockf200.sourceLocators);
Expand Down Expand Up @@ -594,18 +580,4 @@ contract BlockBuilderPolicyTest is Test {
vm.expectRevert(abi.encodeWithSelector(BlockBuilderPolicy.InvalidNonce.selector, 1, 0));
policy.permitVerifyBlockBuilderProof(version, blockContentHash, 0, signature);
}

function test_permitVerifyBlockBuilderProof_reverts_with_unsupported_version() public {
bytes32 blockContentHash = Helper.computeFlashtestationBlockContentHash();

// Create signature with unsupported version
uint8 unsupportedVersion = 2;
bytes32 structHash = policy.computeStructHash(unsupportedVersion, blockContentHash, 0);
bytes32 digest = policy.getHashedTypeDataV4(structHash);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(mock46f6.privateKey, digest);
bytes memory signature = abi.encodePacked(r, s, v);

vm.expectRevert(abi.encodeWithSelector(BlockBuilderPolicy.UnsupportedVersion.selector, unsupportedVersion));
policy.permitVerifyBlockBuilderProof(unsupportedVersion, blockContentHash, 0, signature);
}
}