Skip to content
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

chore: pack slot index and router address into single mapping to save… #57

Merged
merged 1 commit into from
Jun 6, 2024
Merged
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
28 changes: 18 additions & 10 deletions src/contracts/Executor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ contract Executor is Context {
uint8 public immutable _domainID;
IAccessControlSegregator public _accessControl;

// originDomainID => slot index number
mapping(uint8 => uint8) public _slotIndexes;
/* origin domainID => metadata:
uint8 slotIndex
address routerAddress
*/
mapping(uint8 => Metadata) public _originDomainIDMetadata;
// securityModel => state root storage contract addresses
mapping(uint8 => address[]) public _securityModels;
// origin domainID => nonces set => used deposit nonces
mapping(uint8 => mapping(uint256 => uint256)) public usedNonces;
// origin domainID => router address
mapping(uint8 => address) public _originDomainIDToRouter;

struct Proposal {
uint8 originDomainID;
Expand All @@ -41,6 +42,11 @@ contract Executor is Context {
bytes[] storageProof;
}

struct Metadata {
uint8 slotIndex;
address routerAddress;
}

event ProposalExecution(uint8 originDomainID, uint64 depositNonce, bytes handlerResponse);
event FeeRouterChanged(uint8 originDomainID, address newRouter);
event FailedHandlerExecution(bytes lowLevelData, uint8 originDomainID, uint64 depositNonce);
Expand Down Expand Up @@ -79,25 +85,25 @@ contract Executor is Context {
}

/**
@notice Maps the {originDomainID} to {router} in _originDomainIDToRouter.
@notice Maps the {originDomainID} to {router} in _originDomainIDMetadata.
@notice Only callable by address that has the right to call the specific function,
which is mapped in {functionAccess} in AccessControlSegregator contract.
@param newRouter Address of router that will be updated to.
*/
function adminChangeRouter(uint8 originDomainID, address newRouter) external onlyAllowed {
_originDomainIDToRouter[originDomainID] = newRouter;
_originDomainIDMetadata[originDomainID].routerAddress = newRouter;
emit FeeRouterChanged(originDomainID, newRouter);
}

/**
@notice Maps the {originDomainID} to {slotIndex} in _slotIndexes.
@notice Maps the {originDomainID} to {slotIndex} in _originDomainIDMetadata.
@notice Only callable by address that has the right to call the specific function,
which is mapped in {functionAccess} in AccessControlSegregator contract.
@param originDomainID domain from which the proposal originated.
@param slotIndex Index number to be used for the belonging origin domain ID in slot key calculation.
*/
function adminChangeSlotIndex(uint8 originDomainID, uint8 slotIndex) external onlyAllowed {
_slotIndexes[originDomainID] = slotIndex;
_originDomainIDMetadata[originDomainID].slotIndex = slotIndex;
}

/**
Expand Down Expand Up @@ -147,7 +153,7 @@ contract Executor is Context {
}
bytes32 expectedStateRoot;
bytes32 storageRoot;
address routerAddress = _originDomainIDToRouter[proposal.originDomainID];
address routerAddress = _originDomainIDMetadata[proposal.originDomainID].routerAddress;

IStateRootStorage checkingStateRootStorage = IStateRootStorage(
_securityModels[proposal.securityModel][0]
Expand Down Expand Up @@ -235,7 +241,9 @@ contract Executor is Context {
)
);
bytes32 slotKey = keccak256(abi.encode(keccak256(
abi.encode(proposal.depositNonce, keccak256(abi.encode(_domainID, _slotIndexes[proposal.originDomainID])))
abi.encode(proposal.depositNonce, keccak256(
abi.encode(_domainID, _originDomainIDMetadata[proposal.originDomainID].slotIndex))
)
)));

bytes32 slotValue = StorageProof.getStorageValue(slotKey, storageRoot, proposal.storageProof);
Expand Down
Loading