Skip to content

[TOB] DEV-3733: ID-3 #19

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

Merged
merged 2 commits into from
Feb 28, 2025
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
4 changes: 2 additions & 2 deletions script/automata/ConfigAutomataDao.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ contract ConfigAutomataDao is Script {
address enclaveIdentityHelper = vm.envAddress("ENCLAVE_IDENTITY_HELPER");
address fmspcTcbHelper = vm.envAddress("FMSPC_TCB_HELPER");

function updateStorageDao() public {
function grantDao(address dao) public {
vm.broadcast(privateKey);

AutomataDaoStorage pccsStorage = AutomataDaoStorage(pccsStorageAddr);
pccsStorage.updateDao(pcsDaoAddr, pckDaoAddr, fmspcTcbDaoAddr, enclaveIdDaoAddr);
pccsStorage.grantDao(dao);
}

function revokeDao(address dao) public {
Expand Down
6 changes: 5 additions & 1 deletion script/automata/DeployAutomataDao.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ contract DeployAutomataDao is P256Configuration {
new AutomataFmspcTcbDao(address(pccsStorage), simulateVerify(), address(pcsDao), fmspcTcbHelper, x509);
console.log("AutomataFmspcTcbDao deployed at: ", address(fmspcTcbDao));

pccsStorage.updateDao(address(pcsDao), address(pckDao), address(fmspcTcbDao), address(enclaveIdDao));
// grants the DAOs permission to write to storage
pccsStorage.grantDao(address(pcsDao));
pccsStorage.grantDao(address(pckDao));
pccsStorage.grantDao(address(enclaveIdDao));
pccsStorage.grantDao(address(fmspcTcbDao));
}

function deployStorage() public broadcastKey(privateKey) {
Expand Down
33 changes: 18 additions & 15 deletions src/automata_pccs/shared/AutomataDaoStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ contract AutomataDaoStorage is AutomataTCBManager, IDaoAttestationResolver, Paus
mapping(address => bool) _authorized_readers;
mapping(bytes32 attId => bytes collateral) _db;

event SetAuthorizedWriter(address caller, bool authorized);
event SetAuthorizedReader(address caller, bool authorized);

modifier onlyDao(address dao) {
require(_authorized_writers[dao], "FORBIDDEN");
_;
Expand All @@ -26,15 +29,15 @@ contract AutomataDaoStorage is AutomataTCBManager, IDaoAttestationResolver, Paus
_initializeOwner(msg.sender);

// adding address(0) as an authorized_reader to allow eth_call
_authorized_readers[address(0)] = true;
_setAuthorizedReader(address(0), true);
}

function isAuthorizedCaller(address caller) external view returns (bool) {
return _authorized_readers[caller];
}

function setCallerAuthorization(address caller, bool authorized) external onlyOwner {
_authorized_readers[caller] = authorized;
_setAuthorizedReader(caller, authorized);
}

function pauseCallerRestriction() external onlyOwner whenNotPaused {
Expand All @@ -45,15 +48,12 @@ contract AutomataDaoStorage is AutomataTCBManager, IDaoAttestationResolver, Paus
_unpause();
}

function updateDao(address _pcsDao, address _pckDao, address _fmspcTcbDao, address _enclaveIdDao)
external
onlyOwner
{
_updateDao(_pcsDao, _pckDao, _fmspcTcbDao, _enclaveIdDao);
function grantDao(address granted) external onlyOwner {
_setAuthorizedWriter(granted, true);
}

function revokeDao(address revoked) external onlyOwner {
_authorized_writers[revoked] = false;
_setAuthorizedWriter(revoked, false);
}

function collateralPointer(bytes32 key) external pure override returns (bytes32 collateralAttId) {
Expand Down Expand Up @@ -93,13 +93,6 @@ contract AutomataDaoStorage is AutomataTCBManager, IDaoAttestationResolver, Paus
}
}

function _updateDao(address _pcsDao, address _pckDao, address _fmspcTcbDao, address _enclaveIdDao) private {
_authorized_writers[_pcsDao] = true;
_authorized_writers[_pckDao] = true;
_authorized_writers[_fmspcTcbDao] = true;
_authorized_writers[_enclaveIdDao] = true;
}

/// Attestation ID Computation
bytes4 constant DATA_ATTESTATION_MAGIC = 0x54a09e9a;
bytes4 constant HASH_ATTESTATION_MAGIC = 0x628ab4d2;
Expand All @@ -109,6 +102,16 @@ contract AutomataDaoStorage is AutomataTCBManager, IDaoAttestationResolver, Paus
attestationId = keccak256(abi.encodePacked(magic, key));
}

function _setAuthorizedWriter(address caller, bool authorized) private {
_authorized_writers[caller] = authorized;
emit SetAuthorizedWriter(caller, authorized);
}

function _setAuthorizedReader(address caller, bool authorized) private {
_authorized_readers[caller] = authorized;
emit SetAuthorizedReader(caller, authorized);
}

/// TCB Management
using EnumerableSet for EnumerableSet.Bytes32Set;

Expand Down
6 changes: 5 additions & 1 deletion test/TestSetupBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ abstract contract TestSetupBase is Test {
pck =
new AutomataPckDao(address(pccsStorage), P256_VERIFIER, address(pcs), address(x509Lib), address(x509CrlLib));

pccsStorage.updateDao(address(pcs), address(pck), address(fmspcTcbDao), address(enclaveIdDao));
// grants dao permissions to write to the storage
pccsStorage.grantDao(address(pcs));
pccsStorage.grantDao(address(pck));
pccsStorage.grantDao(address(fmspcTcbDao));
pccsStorage.grantDao(address(enclaveIdDao));

// grants admin address permission to read collaterals
pccsStorage.setCallerAuthorization(admin, true);
Expand Down
2 changes: 1 addition & 1 deletion test/tcb/TCBMockTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract TcbMockTest is PCSSetupBase, TCBConstants {
);

vm.prank(admin);
pccsStorage.updateDao(address(pcs), address(pck), address(tcb), address(enclaveIdDao));
pccsStorage.grantDao(address(tcb));
}

function testMockFmspcTcbTdxV3() public {
Expand Down
Loading