Skip to content

Commit

Permalink
Fixed issue in sendProof + small fixes with parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
branarakic committed Feb 12, 2024
1 parent 27dd74e commit 7899cd7
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 214 deletions.
24 changes: 17 additions & 7 deletions contracts/v1/HubController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ contract HubController is Named, Versioned, ContractStatus, Ownable {
) external onlyOwnerOrMultiSigOwner {
if (hub.isContract(contractName)) {
address oldContractAddress = hub.getContractAddress(contractName);
if (_isContract(oldContractAddress))
if (_isContract(oldContractAddress)) {
// solhint-disable-next-line no-empty-blocks
try ContractStatus(hub.getContractAddress(contractName)).setStatus(false) {} catch {}
}
}
hub.setContractAddress(contractName, newContractAddress);
if (_isContract(newContractAddress))
if (_isContract(newContractAddress)) {
// solhint-disable-next-line no-empty-blocks
try ContractStatus(newContractAddress).setStatus(true) {} catch {}
}
}

function setAssetStorageAddress(
Expand All @@ -118,14 +120,16 @@ contract HubController is Named, Versioned, ContractStatus, Ownable {
for (uint i; i < newContracts.length; ) {
if (hub.isContract(newContracts[i].name)) {
address oldContractAddress = hub.getContractAddress(newContracts[i].name);
if (_isContract(oldContractAddress))
if (_isContract(oldContractAddress)) {
// solhint-disable-next-line no-empty-blocks
try ContractStatus(oldContractAddress).setStatus(false) {} catch {}
}
}
hub.setContractAddress(newContracts[i].name, newContracts[i].addr);
if (_isContract(newContracts[i].addr))
if (_isContract(newContracts[i].addr)) {
// solhint-disable-next-line no-empty-blocks
try ContractStatus(newContracts[i].addr).setStatus(true) {} catch {}
}
unchecked {
i++;
}
Expand Down Expand Up @@ -178,7 +182,9 @@ contract HubController is Named, Versioned, ContractStatus, Ownable {
}

function _setHashFunctions(address[] calldata newHashFunctions) internal {
if (newHashFunctions.length == 0) return;
if (newHashFunctions.length == 0) {
return;
}
HashingProxy hashingProxy = HashingProxy(hub.getContractAddress("HashingProxy"));
for (uint i; i < newHashFunctions.length; ) {
hashingProxy.setContractAddress(Indexable(newHashFunctions[i]).id(), newHashFunctions[i]);
Expand All @@ -189,7 +195,9 @@ contract HubController is Named, Versioned, ContractStatus, Ownable {
}

function _setScoreFunctions(address[] calldata newScoreFunctions) internal {
if (newScoreFunctions.length == 0) return;
if (newScoreFunctions.length == 0) {
return;
}
ScoringProxy scoringProxy = ScoringProxy(hub.getContractAddress("ScoringProxy"));
for (uint i; i < newScoreFunctions.length; ) {
scoringProxy.setContractAddress(Indexable(newScoreFunctions[i]).id(), newScoreFunctions[i]);
Expand All @@ -210,7 +218,9 @@ contract HubController is Named, Versioned, ContractStatus, Ownable {
function _isMultiSigOwner(address multiSigAddress) internal view returns (bool) {
try ICustodian(multiSigAddress).getOwners() returns (address[] memory multiSigOwners) {
for (uint i = 0; i < multiSigOwners.length; i++) {
if (msg.sender == multiSigOwners[i]) return true;
if (msg.sender == multiSigOwners[i]) {
return true;
}
} // solhint-disable-next-line no-empty-blocks
} catch {}

Expand Down
4 changes: 3 additions & 1 deletion contracts/v1/Identity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ contract Identity is Named, Versioned, ContractStatus, Initializable {

ids.removeKey(identityId, key);

if (purpose == OPERATIONAL_KEY) ids.removeOperationalKeyIdentityId(key);
if (purpose == OPERATIONAL_KEY) {
ids.removeOperationalKeyIdentityId(key);
}
}

function addOperationalWallets(uint72 identityId, address[] calldata operationalWallets) external onlyContracts {
Expand Down
65 changes: 43 additions & 22 deletions contracts/v1/Profile.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,33 @@ contract Profile is Named, Versioned, ContractStatus, Initializable {
ProfileStorage ps = profileStorage;
Identity id = identityContract;

if (ids.getIdentityId(msg.sender) != 0)
if (ids.getIdentityId(msg.sender) != 0) {
revert ProfileErrors.IdentityAlreadyExists(ids.getIdentityId(msg.sender), msg.sender);
if (operationalWallets.length > parametersStorage.opWalletsLimitOnProfileCreation())
}
if (operationalWallets.length > parametersStorage.opWalletsLimitOnProfileCreation()) {
revert ProfileErrors.TooManyOperationalWallets(
parametersStorage.opWalletsLimitOnProfileCreation(),
uint16(operationalWallets.length)
);
if (nodeId.length == 0) revert ProfileErrors.EmptyNodeId();
if (ps.nodeIdsList(nodeId)) revert ProfileErrors.NodeIdAlreadyExists(nodeId);
if (keccak256(abi.encodePacked(sharesTokenName)) == keccak256(abi.encodePacked("")))
}
if (nodeId.length == 0) {
revert ProfileErrors.EmptyNodeId();
}
if (ps.nodeIdsList(nodeId)) {
revert ProfileErrors.NodeIdAlreadyExists(nodeId);
}
if (keccak256(abi.encodePacked(sharesTokenName)) == keccak256(abi.encodePacked(""))) {
revert ProfileErrors.EmptySharesTokenName();
if (keccak256(abi.encodePacked(sharesTokenSymbol)) == keccak256(abi.encodePacked("")))
}
if (keccak256(abi.encodePacked(sharesTokenSymbol)) == keccak256(abi.encodePacked(""))) {
revert ProfileErrors.EmptySharesTokenSymbol();
if (ps.sharesNames(sharesTokenName)) revert ProfileErrors.SharesTokenNameAlreadyExists(sharesTokenName);
if (ps.sharesSymbols(sharesTokenSymbol)) revert ProfileErrors.SharesTokenSymbolAlreadyExists(sharesTokenSymbol);

}
if (ps.sharesNames(sharesTokenName)) {
revert ProfileErrors.SharesTokenNameAlreadyExists(sharesTokenName);
}
if (ps.sharesSymbols(sharesTokenSymbol)) {
revert ProfileErrors.SharesTokenSymbolAlreadyExists(sharesTokenSymbol);
}
uint72 identityId = id.createIdentity(msg.sender, adminWallet);
id.addOperationalWallets(identityId, operationalWallets);

Expand All @@ -122,8 +133,9 @@ contract Profile is Named, Versioned, ContractStatus, Initializable {
}

function setAsk(uint72 identityId, uint96 ask) external onlyIdentityOwner(identityId) {
if (ask == 0) revert ProfileErrors.ZeroAsk();

if (ask == 0) {
revert ProfileErrors.ZeroAsk();
}
ProfileStorage ps = profileStorage;
ps.setAsk(identityId, ask);

Expand Down Expand Up @@ -154,8 +166,9 @@ contract Profile is Named, Versioned, ContractStatus, Initializable {
ProfileStorage ps = profileStorage;

uint96 accumulatedOperatorFee = ps.getAccumulatedOperatorFee(identityId);
if (accumulatedOperatorFee == 0) revert ProfileErrors.NoOperatorFees(identityId);

if (accumulatedOperatorFee == 0) {
revert ProfileErrors.NoOperatorFees(identityId);
}
ps.setAccumulatedOperatorFee(identityId, 0);
stakingContract.addStake(msg.sender, identityId, accumulatedOperatorFee);
}
Expand All @@ -165,8 +178,9 @@ contract Profile is Named, Versioned, ContractStatus, Initializable {

uint96 accumulatedOperatorFee = ps.getAccumulatedOperatorFee(identityId);

if (accumulatedOperatorFee == 0) revert ProfileErrors.NoOperatorFees(identityId);

if (accumulatedOperatorFee == 0) {
revert ProfileErrors.NoOperatorFees(identityId);
}
ps.setAccumulatedOperatorFee(identityId, 0);
ps.setAccumulatedOperatorFeeWithdrawalAmount(
identityId,
Expand All @@ -183,13 +197,15 @@ contract Profile is Named, Versioned, ContractStatus, Initializable {

uint96 withdrawalAmount = ps.getAccumulatedOperatorFeeWithdrawalAmount(identityId);

if (withdrawalAmount == 0) revert StakingErrors.WithdrawalWasntInitiated();
if (ps.getAccumulatedOperatorFeeWithdrawalTimestamp(identityId) >= block.timestamp)
if (withdrawalAmount == 0) {
revert StakingErrors.WithdrawalWasntInitiated();
}
if (ps.getAccumulatedOperatorFeeWithdrawalTimestamp(identityId) >= block.timestamp) {
revert StakingErrors.WithdrawalPeriodPending(
block.timestamp,
ps.getAccumulatedOperatorFeeWithdrawalTimestamp(identityId)
);

}
ps.setAccumulatedOperatorFeeWithdrawalAmount(identityId, 0);
ps.setAccumulatedOperatorFeeWithdrawalTimestamp(identityId, 0);
ps.transferAccumulatedOperatorFee(msg.sender, withdrawalAmount);
Expand All @@ -199,22 +215,27 @@ contract Profile is Named, Versioned, ContractStatus, Initializable {
if (
!identityStorage.keyHasPurpose(identityId, keccak256(abi.encodePacked(msg.sender)), ADMIN_KEY) &&
!identityStorage.keyHasPurpose(identityId, keccak256(abi.encodePacked(msg.sender)), OPERATIONAL_KEY)
) revert GeneralErrors.OnlyProfileAdminOrOperationalAddressesFunction(msg.sender);
) {
revert GeneralErrors.OnlyProfileAdminOrOperationalAddressesFunction(msg.sender);
}
}

function _checkAdmin(uint72 identityId) internal view virtual {
if (!identityStorage.keyHasPurpose(identityId, keccak256(abi.encodePacked(msg.sender)), ADMIN_KEY))
if (!identityStorage.keyHasPurpose(identityId, keccak256(abi.encodePacked(msg.sender)), ADMIN_KEY)) {
revert GeneralErrors.OnlyProfileAdminFunction(msg.sender);
}
}

function _checkOperational(uint72 identityId) internal view virtual {
if (!identityStorage.keyHasPurpose(identityId, keccak256(abi.encodePacked(msg.sender)), OPERATIONAL_KEY))
if (!identityStorage.keyHasPurpose(identityId, keccak256(abi.encodePacked(msg.sender)), OPERATIONAL_KEY)) {
revert GeneralErrors.OnlyProfileOperationalWalletFunction(msg.sender);
}
}

function _checkWhitelist() internal view virtual {
WhitelistStorage ws = whitelistStorage;
if (ws.whitelistingEnabled() && !ws.whitelisted(msg.sender))
if (ws.whitelistingEnabled() && !ws.whitelisted(msg.sender)) {
revert GeneralErrors.OnlyWhitelistedAddressesFunction(msg.sender);
}
}
}
24 changes: 12 additions & 12 deletions contracts/v1/ProofManagerV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ contract ProofManagerV1 is Named, Versioned, ContractStatus, Initializable {
function isProofWindowOpen(bytes32 agreementId, uint16 epoch) public view returns (bool) {
ServiceAgreementStorageProxy sasProxy = serviceAgreementStorageProxy;

if (!sasProxy.agreementV1Exists(agreementId))
if (!sasProxy.agreementV1Exists(agreementId)) {
revert ServiceAgreementErrorsV1.ServiceAgreementDoesntExist(agreementId);

}
uint256 startTime = sasProxy.getAgreementStartTime(agreementId);

if (epoch >= sasProxy.getAgreementEpochsNumber(agreementId))
if (epoch >= sasProxy.getAgreementEpochsNumber(agreementId)) {
revert ServiceAgreementErrorsV1.ServiceAgreementHasBeenExpired(
agreementId,
startTime,
sasProxy.getAgreementEpochsNumber(agreementId),
sasProxy.getAgreementEpochLength(agreementId)
);

}
uint256 timeNow = block.timestamp;
uint128 epochLength = sasProxy.getAgreementEpochLength(agreementId);
uint8 proofWindowOffsetPerc = sasProxy.getAgreementProofWindowOffsetPerc(agreementId);
Expand Down Expand Up @@ -119,9 +119,9 @@ contract ProofManagerV1 is Named, Versioned, ContractStatus, Initializable {
abi.encodePacked(args.assetContract, args.tokenId, args.keyword)
);

if (!sasProxy.agreementV1Exists(agreementId))
if (!sasProxy.agreementV1Exists(agreementId)) {
revert ServiceAgreementErrorsV1.ServiceAgreementDoesntExist(agreementId);

}
if (!reqs[0] && !isProofWindowOpen(agreementId, args.epoch)) {
uint128 epochLength = sasProxy.getAgreementEpochLength(agreementId);

Expand All @@ -143,14 +143,14 @@ contract ProofManagerV1 is Named, Versioned, ContractStatus, Initializable {
if (
!reqs[1] &&
(sasProxy.getCommitSubmissionScore(keccak256(abi.encodePacked(agreementId, args.epoch, identityId))) == 0)
)
) {
revert ServiceAgreementErrorsV1.NodeAlreadyRewarded(
agreementId,
args.epoch,
identityId,
profileStorage.getNodeId(identityId)
);

}
bytes32 nextCommitId = sasProxy.getV1AgreementEpochSubmissionHead(agreementId, args.epoch);
uint32 r0 = parametersStorage.r0();
uint8 i;
Expand All @@ -163,23 +163,23 @@ contract ProofManagerV1 is Named, Versioned, ContractStatus, Initializable {
}
}

if (!reqs[2] && (i >= r0))
if (!reqs[2] && (i >= r0)) {
revert ServiceAgreementErrorsV1.NodeNotAwarded(
agreementId,
args.epoch,
identityId,
profileStorage.getNodeId(identityId),
i
);

}
bytes32 merkleRoot;
uint256 challenge;
(merkleRoot, challenge) = getChallenge(msg.sender, args.assetContract, args.tokenId, args.epoch);

if (
!reqs[3] &&
!MerkleProof.verify(args.proof, merkleRoot, keccak256(abi.encodePacked(args.chunkHash, challenge)))
)
) {
revert ServiceAgreementErrorsV1.WrongMerkleProof(
agreementId,
args.epoch,
Expand All @@ -190,7 +190,7 @@ contract ProofManagerV1 is Named, Versioned, ContractStatus, Initializable {
args.chunkHash,
challenge
);

}
emit ProofSubmitted(
args.assetContract,
args.tokenId,
Expand Down
24 changes: 12 additions & 12 deletions contracts/v1/ProofManagerV1U1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ contract ProofManagerV1U1 is Named, Versioned, ContractStatus, Initializable {
function isProofWindowOpen(bytes32 agreementId, uint16 epoch) public view returns (bool) {
ServiceAgreementStorageProxy sasProxy = serviceAgreementStorageProxy;

if (sasProxy.agreementV1Exists(agreementId) || !sasProxy.agreementV1U1Exists(agreementId))
if (sasProxy.agreementV1Exists(agreementId) || !sasProxy.agreementV1U1Exists(agreementId)) {
revert ServiceAgreementErrorsV1.ServiceAgreementDoesntExist(agreementId);

}
uint256 startTime = sasProxy.getAgreementStartTime(agreementId);

if (epoch >= sasProxy.getAgreementEpochsNumber(agreementId))
if (epoch >= sasProxy.getAgreementEpochsNumber(agreementId)) {
revert ServiceAgreementErrorsV1.ServiceAgreementHasBeenExpired(
agreementId,
startTime,
sasProxy.getAgreementEpochsNumber(agreementId),
sasProxy.getAgreementEpochLength(agreementId)
);

}
uint256 timeNow = block.timestamp;
uint128 epochLength = sasProxy.getAgreementEpochLength(agreementId);
uint8 proofWindowOffsetPerc = sasProxy.getAgreementProofWindowOffsetPerc(agreementId);
Expand Down Expand Up @@ -111,9 +111,9 @@ contract ProofManagerV1U1 is Named, Versioned, ContractStatus, Initializable {
abi.encodePacked(args.assetContract, args.tokenId, args.keyword)
);

if (sasProxy.agreementV1Exists(agreementId) || !sasProxy.agreementV1U1Exists(agreementId))
if (sasProxy.agreementV1Exists(agreementId) || !sasProxy.agreementV1U1Exists(agreementId)) {
revert ServiceAgreementErrorsV1.ServiceAgreementDoesntExist(agreementId);

}
uint256 latestFinalizedStateIndex = AbstractAsset(args.assetContract).getAssertionIdsLength(args.tokenId) - 1;

if (!reqs[0] && !isProofWindowOpen(agreementId, args.epoch)) {
Expand All @@ -140,15 +140,15 @@ contract ProofManagerV1U1 is Named, Versioned, ContractStatus, Initializable {
uint72 identityId = ids.getIdentityId(msg.sender);
bytes32 commitId = keccak256(abi.encodePacked(agreementId, args.epoch, latestFinalizedStateIndex, identityId));

if (!reqs[1] && (sasProxy.getCommitSubmissionScore(commitId) == 0))
if (!reqs[1] && (sasProxy.getCommitSubmissionScore(commitId) == 0)) {
revert ServiceAgreementErrorsV1U1.NodeAlreadyRewarded(
agreementId,
args.epoch,
latestFinalizedStateIndex,
identityId,
profileStorage.getNodeId(identityId)
);

}
bytes32 nextCommitId = sasProxy.getV1U1AgreementEpochSubmissionHead(
agreementId,
args.epoch,
Expand All @@ -170,7 +170,7 @@ contract ProofManagerV1U1 is Named, Versioned, ContractStatus, Initializable {
}
}

if (!reqs[2] && (i >= r0))
if (!reqs[2] && (i >= r0)) {
revert ServiceAgreementErrorsV1U1.NodeNotAwarded(
agreementId,
args.epoch,
Expand All @@ -179,15 +179,15 @@ contract ProofManagerV1U1 is Named, Versioned, ContractStatus, Initializable {
profileStorage.getNodeId(identityId),
i
);

}
bytes32 merkleRoot;
uint256 challenge;
(merkleRoot, challenge) = _getChallenge(msg.sender, args.assetContract, args.tokenId, args.epoch);

if (
!reqs[3] &&
!MerkleProof.verify(args.proof, merkleRoot, keccak256(abi.encodePacked(args.chunkHash, challenge)))
)
) {
revert ServiceAgreementErrorsV1U1.WrongMerkleProof(
agreementId,
args.epoch,
Expand All @@ -199,7 +199,7 @@ contract ProofManagerV1U1 is Named, Versioned, ContractStatus, Initializable {
args.chunkHash,
challenge
);

}
emit ProofSubmitted(
args.assetContract,
args.tokenId,
Expand Down
Loading

0 comments on commit 7899cd7

Please sign in to comment.