Skip to content

Commit 38594f3

Browse files
RuteriMelvillian
authored andcommitted
remove xfam + tdAttributes bitmasking logic, and add upgrade script + documentation for v1 block builder policy migration
This PR introduces the V1BlockBuilderPolicy contract and corresponding upgrade script to migrate from the initial policy version that contained buggy xFAM and td attributes bit masking logic. The upgrade provides a cleaner implementation without bit masking, following the bug fix completed in the previous commit. Documentation is added to the README explaining the upgrade rationale and deployment commands.
1 parent 53735ea commit 38594f3

File tree

5 files changed

+378
-105
lines changed

5 files changed

+378
-105
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,23 @@ Then, to execute, run:
259259
```
260260
forge script --chain 1301 script/Interactions.s.sol:AddWorkloadToPolicyScript --rpc-url $RPC_URL --broadcast --verify --interactives 1 -vvvv
261261
```
262+
263+
## Upgrade
264+
265+
### UpgradeBlockBuilderFromV1
266+
267+
#### Reason For Upgrade
268+
269+
This is nearly identical to the latest version of the policy contract located at src/BlockBuilderPolicy contract, except in the latest has had the logic around the xfam and tdattributes bit masking removed. This was done because there was a bug in the bit masking logic, and we want to fix the bug and simplify the contract by removing the bit masking logic.
270+
271+
#### Deploy Command
272+
273+
Run the command below, then paste in the private key of the address you want to use to pay for gas and execute the deployment:
274+
275+
```
276+
forge script script/UpgradeBlockBuilderFromV1.s.sol:UpgradeBlockBuilderPolicyV1 \
277+
--sig "run(address)" <POLICY_PROXY_ADDRESS> \
278+
--rpc-url <RPC_URL> \
279+
-vvvvv --verify --broadcast --interactives 1
280+
```
281+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import {Script, console} from "forge-std/Script.sol";
5+
import {Upgrades, Options} from "openzeppelin-foundry-upgrades/Upgrades.sol";
6+
import {BlockBuilderPolicy} from "../src/BlockBuilderPolicy.sol";
7+
8+
/**
9+
* @title UpgradeBlockBuilderFromV1
10+
* @notice Upgrade script for BlockBuilderPolicy contract from V1 (the original version of the contract)
11+
* @notice This is nearly identical to the latest version of the policy contract located at
12+
* src/BlockBuilderPolicy contract, except in the latest has had the logic around the xfam and tdattributes bit
13+
* masking removed. This was done because there was a bug in the bit masking logic, and we want to fix the bug
14+
* and simplify the contract by removing the bit masking logic
15+
* @dev This script does not require any reinitialization of the contract, as the the only changes to
16+
* the contract are removing constant variables and changing the workloadIdForTDRegistration function logic
17+
* @dev This script:
18+
* 1. Deploys a new BlockBuilderPolicy implementation contract
19+
* 2. Upgrades the existing UUPS proxy to point to the new implementation
20+
*/
21+
contract UpgradeBlockBuilderPolicyV1 is Script {
22+
/**
23+
* @notice uses environment variables to get the proxy address of the BlockBuilderPolicy contract
24+
* @dev the BLOCK_BUILDER_POLICY_PROXY_ADDRESS env var is the address of the proxy contract for the BlockBuilderPolicy contract
25+
*/
26+
function run() external {
27+
address proxyAddress = vm.envAddress("BLOCK_BUILDER_POLICY_PROXY_ADDRESS");
28+
run(proxyAddress);
29+
}
30+
31+
function run(address proxyAddress) public {
32+
console.log("=== UpgradeBlockBuilderFromV1 Configuration ===");
33+
console.log("Proxy address:", proxyAddress);
34+
console.log("");
35+
36+
// Spot check the proxy contract by calling the registry function
37+
// This is a safety check to ensure the contract at the proxy address
38+
// implements IBlockBuilderPolicy as expected
39+
address proxyRegistry = BlockBuilderPolicy(proxyAddress).registry();
40+
require(proxyRegistry != address(0), "proxyAddress is not a BlockBuilderPolicy contract");
41+
42+
vm.startBroadcast();
43+
44+
// Upgrade the proxy to the new implementation
45+
Options memory opts;
46+
opts.referenceContract = "V1BlockBuilderPolicy.sol:V1BlockBuilderPolicy";
47+
Upgrades.upgradeProxy(proxyAddress, "BlockBuilderPolicy.sol", bytes(""), opts);
48+
49+
vm.stopBroadcast();
50+
51+
console.log("=== Upgrade Complete ===");
52+
console.log("");
53+
}
54+
}

src/BlockBuilderPolicy.sol

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,6 @@ contract BlockBuilderPolicy is
4747
bytes32 public constant VERIFY_BLOCK_BUILDER_PROOF_TYPEHASH =
4848
keccak256("VerifyBlockBuilderProof(uint8 version,bytes32 blockContentHash,uint256 nonce)");
4949

50-
// ============ TDX workload constants ============
51-
52-
/// @dev See section 11.5.3 in TDX Module v1.5 Base Architecture Specification https://www.intel.com/content/www/us/en/content-details/733575/intel-tdx-module-v1-5-base-architecture-specification.html
53-
/// @notice Enabled FPU (always enabled)
54-
bytes8 constant TD_XFAM_FPU = 0x0000000000000001;
55-
/// @notice Enabled SSE (always enabled)
56-
bytes8 constant TD_XFAM_SSE = 0x0000000000000002;
57-
58-
/// @dev See section 3.4.1 in TDX Module ABI specification https://cdrdv2.intel.com/v1/dl/getContent/733579
59-
/// @notice Allows disabling of EPT violation conversion to #VE on access of PENDING pages. Needed for Linux
60-
bytes8 constant TD_TDATTRS_VE_DISABLED = 0x0000000010000000;
61-
/// @notice Enabled Supervisor Protection Keys (PKS)
62-
bytes8 constant TD_TDATTRS_PKS = 0x0000000040000000;
63-
/// @notice Enabled Key Locker (KL)
64-
bytes8 constant TD_TDATTRS_KL = 0x0000000080000000;
65-
6650
// ============ Storage Variables ============
6751

6852
/// @notice Mapping from workloadId to its metadata (commit hash and source locators)
@@ -227,12 +211,6 @@ contract BlockBuilderPolicy is
227211
override
228212
returns (WorkloadId)
229213
{
230-
// We expect FPU and SSE xfam bits to be set, and anything else should be handled by explicitly allowing the workloadid
231-
bytes8 expectedXfamBits = TD_XFAM_FPU | TD_XFAM_SSE;
232-
233-
// We don't mind VE_DISABLED, PKS, and KL tdattributes bits being set either way, anything else requires explicitly allowing the workloadid
234-
bytes8 ignoredTdAttributesBitmask = TD_TDATTRS_VE_DISABLED | TD_TDATTRS_PKS | TD_TDATTRS_KL;
235-
236214
return WorkloadId.wrap(
237215
keccak256(
238216
bytes.concat(
@@ -243,8 +221,8 @@ contract BlockBuilderPolicy is
243221
registration.parsedReportBody.rtMr3,
244222
// VMM configuration
245223
registration.parsedReportBody.mrConfigId,
246-
registration.parsedReportBody.xFAM ^ expectedXfamBits,
247-
registration.parsedReportBody.tdAttributes & ~ignoredTdAttributesBitmask
224+
registration.parsedReportBody.xFAM,
225+
registration.parsedReportBody.tdAttributes
248226
)
249227
)
250228
);

0 commit comments

Comments
 (0)