Skip to content

Commit

Permalink
Merge pull request #45 from KintoXYZ/increase-coverage
Browse files Browse the repository at this point in the history
Increase coverage
  • Loading branch information
fedealconada authored Jan 16, 2024
2 parents 7612b56 + 7a9a72c commit 17335f3
Show file tree
Hide file tree
Showing 18 changed files with 554 additions and 538 deletions.
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ignore:
- "script" # ignore scripts/ folder
- "lib" # ignore libs/ folder
- "src/libraries" # ignore src/libraries/ folder since coverage is not yet supported
- "src/sample" # ignore src/sample/ folder

comment:
layout: " diff, flags, files"
Expand Down
18 changes: 9 additions & 9 deletions script/migrations/12-create_engen_app.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,37 +75,37 @@ contract KintoMigration12DeployScript is ArtifactsReader, UserOp {
flags[0] = true;
flags[1] = true;

userOps[0] = this.createUserOperation(
userOps[0] = _createUserOperation(
block.chainid,
address(_kintoWallet),
nonce,
privateKeys,
address(_kintoWallet),
0,
nonce,
privateKeys,
abi.encodeWithSelector(IKintoWallet.whitelistApp.selector, apps, flags),
address(_paymaster)
);

// call initialise on KintoRegistryApp
userOps[1] = this.createUserOperation(
userOps[1] = _createUserOperation(
block.chainid,
address(_kintoWallet),
nonce + 1,
privateKeys,
address(_kintoAppRegistry),
0,
nonce + 1,
privateKeys,
abi.encodeWithSelector(KintoAppRegistry.initialize.selector),
address(_paymaster)
);

// register Engen Credits app into the registry
userOps[2] = this.createUserOperation(
userOps[2] = _createUserOperation(
block.chainid,
address(_kintoWallet),
nonce + 2,
privateKeys,
address(_kintoAppRegistry),
0,
nonce + 2,
privateKeys,
abi.encodeWithSignature(
"registerApp(string,address,address[],uint256[4])",
"Engen",
Expand Down
1 change: 1 addition & 0 deletions script/migrations/14-factory_v3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ contract KintoMigration14DeployScript is Create2Helper, ArtifactsReader {
bytecode = abi.encodePacked(type(KintoIDV4).creationCode);
_kintoIDImpl =
KintoIDV4(payable(_walletFactory.deployContract(vm.envAddress("LEDGER_ADMIN"), 0, bytecode, bytes32(0))));

vm.stopBroadcast();
// Start admin
vm.startBroadcast();
Expand Down
18 changes: 9 additions & 9 deletions script/migrations/15-faucet_v2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,38 +88,38 @@ contract KintoMigration15DeployScript is Create2Helper, ArtifactsReader, UserOp
bool[] memory flags = new bool[](1);
flags[0] = true;

userOps[0] = this.createUserOperation(
userOps[0] = _createUserOperation(
block.chainid,
_from,
nonce,
privateKeys,
_from,
0,
nonce,
privateKeys,
abi.encodeWithSelector(IKintoWallet.whitelistApp.selector, apps, flags),
_getChainDeployment("SponsorPaymaster")
);
}

// (2). initialise faucet
userOps[1] = this.createUserOperation(
userOps[1] = _createUserOperation(
block.chainid,
_from,
nonce + 1,
privateKeys,
_faucet,
0,
nonce + 1,
privateKeys,
abi.encodeWithSelector(Faucet.initialize.selector),
_getChainDeployment("SponsorPaymaster")
);

// (3). call startFaucet
userOps[2] = this.createUserOperation(
userOps[2] = _createUserOperation(
block.chainid,
_from,
nonce + 2,
privateKeys,
_faucet,
1 ether,
nonce + 2,
privateKeys,
abi.encodeWithSelector(Faucet.startFaucet.selector),
_getChainDeployment("SponsorPaymaster")
);
Expand Down
6 changes: 3 additions & 3 deletions script/migrations/17-faucet_v3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ contract KintoMigration15DeployScript is Create2Helper, ArtifactsReader, UserOp
uint256[] memory privateKeys = new uint256[](1);
privateKeys[0] = _signerPk;
UserOperation[] memory userOps = new UserOperation[](1);
userOps[0] = this.createUserOperation(
userOps[0] = _createUserOperation(
block.chainid,
adminWallet,
nonce,
privateKeys,
faucetProxy,
0,
nonce,
privateKeys,
abi.encodeWithSelector(UUPSUpgradeable.upgradeTo.selector, address(_newFaucetImpl)),
_getChainDeployment("SponsorPaymaster")
);
Expand Down
16 changes: 8 additions & 8 deletions script/test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,16 @@ contract KintoDeployTestCounter is AASetup, KYCSignature, UserOp {
console.log("Counter already has balance to pay for tx", computed);
}
// Let's send a transaction to the counter contract through our wallet
uint256 startingNonce = _newWallet.getNonce();
uint256 nonce = _newWallet.getNonce();
uint256[] memory privateKeys = new uint256[](1);
privateKeys[0] = deployerPrivateKey;
UserOperation memory userOp = this.createUserOperation(
UserOperation memory userOp = _createUserOperation(
block.chainid,
address(_newWallet),
startingNonce,
privateKeys,
address(counter),
0,
nonce,
privateKeys,
abi.encodeWithSignature("increment()"),
address(_sponsorPaymaster),
[uint256(5000000), 3, 3]
Expand Down Expand Up @@ -218,16 +218,16 @@ contract KintoDeployETHPriceIsRight is AASetup, KYCSignature, UserOp {
console.log("ETHPriceIsRight already has balance to pay for tx", computed);
}
// Let's send a transaction to the counter contract through our wallet
uint256 startingNonce = _newWallet.getNonce();
uint256 nonce = _newWallet.getNonce();
uint256[] memory privateKeys = new uint256[](1);
privateKeys[0] = deployerPrivateKey;
UserOperation memory userOp = this.createUserOperation(
UserOperation memory userOp = _createUserOperation(
block.chainid,
address(_newWallet),
startingNonce,
privateKeys,
address(ethpriceisright),
0,
nonce,
privateKeys,
abi.encodeWithSignature("enterGuess(uint256)", 7000),
address(_sponsorPaymaster),
[uint256(5000000), 3, 3]
Expand Down
32 changes: 13 additions & 19 deletions src/KintoID.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,32 +168,21 @@ contract KintoID is

/* ============ Burn ============ */

/**
* @dev Burns a KYC token.
* @param _signatureData Signature data
*/
function burnKYC(SignatureData calldata _signatureData) external override {
require(balanceOf(_signatureData.signer) > 0, "Nothing to burn");

_burnp(tokenOfOwnerByIndex(_signatureData.signer, 0), _signatureData);
}

function burn(uint256 /* tokenId */ ) public pure override {
require(false, "Use burnKYC instead");
}

/**
* @dev Burns a token.
* @param _tokenId Token ID to be burned
* @dev Burns a KYC token.
* @param _signatureData Signature data
*/
function _burnp(uint256 _tokenId, SignatureData calldata _signatureData)
private
onlySignerVerified(_signatureData)
{
function burnKYC(SignatureData calldata _signatureData) external override onlySignerVerified(_signatureData) {
require(balanceOf(_signatureData.signer) > 0, "Nothing to burn");

nonces[_signatureData.signer] += 1;
_burn(_tokenId);
_burn(tokenOfOwnerByIndex(_signatureData.signer, 0));
require(balanceOf(_signatureData.signer) == 0, "Balance after burn must be 0");

// Update metadata after burning the token
Metadata storage meta = _kycmetas[_signatureData.signer];
meta.mintedAt = 0;
Expand All @@ -218,8 +207,12 @@ contract KintoID is
{
require(_accounts.length == _traitsAndSanctions.length, "Length mismatch");
require(_accounts.length <= 200, "Too many accounts to monitor at once");

uint256 time = block.timestamp;

for (uint256 i = 0; i < _accounts.length; i += 1) {
Metadata storage meta = _kycmetas[_accounts[i]];

if (balanceOf(_accounts[i]) == 0) {
continue;
}
Expand All @@ -237,8 +230,9 @@ contract KintoID is
}
}
}
lastMonitoredAt = block.timestamp;
emit AccountsMonitoredAt(msg.sender, _accounts.length, block.timestamp);

lastMonitoredAt = time;
emit AccountsMonitoredAt(msg.sender, _accounts.length, time);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/paymasters/SponsorPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,19 @@ contract SponsorPaymaster is Initializable, BasePaymaster, UUPSUpgradeable, Reen
bytes4 selector = bytes4(callData[:4]); // function selector
if (selector == IKintoWallet.executeBatch.selector) {
// decode callData for executeBatch
(address[] memory targetContracts,,) = abi.decode(callData[4:], (address[], uint256[], bytes[]));
sponsor = appRegistry.getSponsor(targetContracts[targetContracts.length - 1]);
(address[] memory targets,,) = abi.decode(callData[4:], (address[], uint256[], bytes[]));
sponsor = appRegistry.getSponsor(targets[targets.length - 1]);

// last contract must be a contract app
for (uint256 i = 0; i < targetContracts.length - 1; i++) {
if (!appRegistry.isContractSponsored(sponsor, targetContracts[i]) && targetContracts[i] != sender) {
for (uint256 i = 0; i < targets.length - 1; i++) {
if (!appRegistry.isContractSponsored(sponsor, targets[i]) && targets[i] != sender) {
revert("SP: executeBatch targets must be sponsored by the contract or be the sender wallet");
}
}
} else if (selector == IKintoWallet.execute.selector) {
// decode callData for execute
(address targetContract,,) = abi.decode(callData[4:], (address, uint256, bytes));
sponsor = appRegistry.getSponsor(targetContract);
(address target,,) = abi.decode(callData[4:], (address, uint256, bytes));
sponsor = appRegistry.getSponsor(target);
} else {
// handle unknown function or error
revert("SP: Unknown function selector");
Expand Down
14 changes: 7 additions & 7 deletions src/wallet/KintoWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -360,24 +360,24 @@ contract KintoWallet is Initializable, BaseAccount, TokenCallbackHandler, IKinto
// Compare the selector with the known function selectors
if (selector == IKintoWallet.executeBatch.selector) {
// Decode callData for executeBatch
(address[] memory targetContracts,,) = abi.decode(callData[4:], (address[], uint256[], bytes[]));
address lastTargetContract = appRegistry.getSponsor(targetContracts[targetContracts.length - 1]);
for (uint256 i = 0; i < targetContracts.length; i++) {
(address[] memory targets,,) = abi.decode(callData[4:], (address[], uint256[], bytes[]));
address lastTargetContract = appRegistry.getSponsor(targets[targets.length - 1]);
for (uint256 i = 0; i < targets.length; i++) {
// App signer should only be valid for the app itself and its children
// It is important that wallet calls are not allowed through the app signer
if (!appRegistry.isContractSponsored(lastTargetContract, targetContracts[i])) {
if (!appRegistry.isContractSponsored(lastTargetContract, targets[i])) {
return address(0);
}
}
return lastTargetContract;
} else if (selector == IKintoWallet.execute.selector) {
// Decode callData for execute
(address targetContract,,) = abi.decode(callData[4:], (address, uint256, bytes));
(address target,,) = abi.decode(callData[4:], (address, uint256, bytes));
// Do not allow txs to the wallet via app key
if (targetContract == address(this)) {
if (target == address(this)) {
return address(0);
}
return targetContract;
return target;
}
return address(0);
}
Expand Down
Loading

0 comments on commit 17335f3

Please sign in to comment.