Skip to content

Commit

Permalink
Merge pull request #159 from futureversecom/SM-108-eth-auth-delegated…
Browse files Browse the repository at this point in the history
…-signer

SM-108 rename signing permission
  • Loading branch information
JCSanPedro authored Dec 11, 2023
2 parents c18ba42 + 62b5331 commit 334b827
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion common/enum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export enum Permission {
TicketSigning,
PersonalSign,
}
4 changes: 2 additions & 2 deletions contracts/AuthorizedAccounts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ contract AuthorizedAccounts is
* @param permission The permission needs to be verified with the authorized account
* @param atBlock The block number to check if the permission is valid between
* the permission's authorizedAt and unauthorizedAt period. It is added later to prevent
* the timing attack. E.g. If the main account authorizes the SigningTicket permission at
* the timing attack. E.g. If the main account authorizes the PersonalSign permission at
* block 1, creates a ticket at block 2, then unauthorizes the permission at block 3, the
* ticket will be invalid and cannot be redeemed. To avoid this, the `atBlock` param is
* needed to check if the permission is authorized between its authorizedAt and unauthorizedAt
Expand Down Expand Up @@ -299,7 +299,7 @@ contract AuthorizedAccounts is

function getAllPermissions() internal pure returns (Permission[] memory) {
Permission[] memory permissions = new Permission[](1);
permissions[0] = Permission.TicketSigning;
permissions[0] = Permission.PersonalSign;
return permissions;
}
}
6 changes: 3 additions & 3 deletions contracts/interfaces/IAuthorizedAccounts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pragma solidity ^0.8.18;

interface IAuthorizedAccounts {
enum Permission {
// TicketSigning permission allows the authorized account to
// sign tickets for ticketing redemption.
TicketSigning
// PersonalSign permission allows the authorized account to
// sign on behalf of the sending account.
PersonalSign
}

/**
Expand Down
24 changes: 12 additions & 12 deletions contracts/payments/SyloTicketing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ contract SyloTicketing is ISyloTicketing, Initializable, Ownable2StepUpgradeable
error PenaltyAmountCannotBeZero();
error UnlockDurationCannotBeZero();
error AccountCannotBeZeroAddress();
error InvalidSenderTicketSigningPermission();
error InvalidReceiverTicketSigningPermission();
error InvalidSenderSigningPermission();
error InvalidReceiverSigningPermission();

error TicketNotWinning();
error MissingFuturepassAccount(address receiver);
Expand Down Expand Up @@ -515,11 +515,11 @@ contract SyloTicketing is ISyloTicketing, Initializable, Ownable2StepUpgradeable
revert RedeemerCommitMismatch();
}

if (!hasTicketSigningPermission(ticket.sender, ticket.generationBlock)) {
revert InvalidSenderTicketSigningPermission();
if (!hasSigningPermission(ticket.sender, ticket.generationBlock)) {
revert InvalidSenderSigningPermission();
}
if (!hasTicketSigningPermission(ticket.receiver, ticket.generationBlock)) {
revert InvalidReceiverTicketSigningPermission();
if (!hasSigningPermission(ticket.receiver, ticket.generationBlock)) {
revert InvalidReceiverSigningPermission();
}

if (!isValidTicketSig(ticket.sender, senderSig, ticketHash)) {
Expand Down Expand Up @@ -599,11 +599,11 @@ contract SyloTicketing is ISyloTicketing, Initializable, Ownable2StepUpgradeable
revert RedeemerCommitMismatch();
}

if (!hasTicketSigningPermission(ticket.sender, ticket.generationBlock)) {
revert InvalidSenderTicketSigningPermission();
if (!hasSigningPermission(ticket.sender, ticket.generationBlock)) {
revert InvalidSenderSigningPermission();
}
if (!hasTicketSigningPermission(receiver, ticket.generationBlock)) {
revert InvalidReceiverTicketSigningPermission();
if (!hasSigningPermission(receiver, ticket.generationBlock)) {
revert InvalidReceiverSigningPermission();
}

if (!isValidTicketSig(ticket.sender, senderSig, ticketHash)) {
Expand All @@ -628,15 +628,15 @@ contract SyloTicketing is ISyloTicketing, Initializable, Ownable2StepUpgradeable
return (ticketHash, ticketReceiverHash);
}

function hasTicketSigningPermission(
function hasSigningPermission(
User memory user,
uint256 generationBlock
) internal view returns (bool) {
if (user.delegated == address(0)) {
return true;
}

IAuthorizedAccounts.Permission permission = IAuthorizedAccounts.Permission.TicketSigning;
IAuthorizedAccounts.Permission permission = IAuthorizedAccounts.Permission.PersonalSign;
return
_authorizedAccounts.validatePermission(
user.main,
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export async function authorizeAccount(
) {
await contracts.authorizedAccounts
.connect(main)
.authorizeAccount(authorized, [Permission.TicketSigning], {
.authorizeAccount(authorized, [Permission.PersonalSign], {
gasLimit: 1_000_000,
});
}
Expand Down
58 changes: 29 additions & 29 deletions test/authorizedAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Authorized Accounts', () => {
let authAccountsConnectMain: AuthorizedAccounts;
let contracts: SyloContracts;

const permissionList: Permission[] = [Permission.TicketSigning];
const permissionList: Permission[] = [Permission.PersonalSign];

before(async () => {
accounts = await ethers.getSigners();
Expand Down Expand Up @@ -312,7 +312,7 @@ describe('Authorized Accounts', () => {

it('can add permission for authorized account', async () => {
const permission: Permission[] = [];
const newPermission: Permission[] = [Permission.TicketSigning];
const newPermission: Permission[] = [Permission.PersonalSign];
await authAccountsConnectMain.authorizeAccount(
delegatedAccount1,
permission,
Expand Down Expand Up @@ -347,16 +347,16 @@ describe('Authorized Accounts', () => {
assert.equal(accounts[0].permissions.length, 1);
assert.equal(
accounts[0].permissions[0].permission,
BigInt(Permission.TicketSigning),
BigInt(Permission.PersonalSign),
);
assert.equal(accounts[0].permissions[0].authorizedAt, await currentBlock());
});

it('can add multiple permissions (with duplicated permissions) for authorized account', async () => {
const permission: Permission[] = [];
const newPermissions: Permission[] = [
Permission.TicketSigning,
Permission.TicketSigning,
Permission.PersonalSign,
Permission.PersonalSign,
];
await authAccountsConnectMain.authorizeAccount(
delegatedAccount1,
Expand Down Expand Up @@ -388,13 +388,13 @@ describe('Authorized Accounts', () => {
});

it('can remove multiple permissions (with duplicated permissions) for authorized account', async () => {
const permissionsToAdd: Permission[] = [Permission.TicketSigning];
const permissionsToAdd: Permission[] = [Permission.PersonalSign];
const permissionsToRemove: Permission[] = [
Permission.TicketSigning,
Permission.TicketSigning,
Permission.PersonalSign,
Permission.PersonalSign,
];
const emptyPermissions: Permission[] = [];
const permission2: Permission[] = [Permission.TicketSigning];
const permission2: Permission[] = [Permission.PersonalSign];

await authAccountsConnectMain.authorizeAccount(
delegatedAccount1,
Expand Down Expand Up @@ -450,7 +450,7 @@ describe('Authorized Accounts', () => {
assert.equal(accounts[0].permissions.length, 1);
assert.equal(
accounts[0].permissions[0].permission,
BigInt(Permission.TicketSigning),
BigInt(Permission.PersonalSign),
);
assert.equal(accounts[0].permissions[0].authorizedAt, authorizedAtBlock);
assert.equal(
Expand Down Expand Up @@ -565,7 +565,7 @@ describe('Authorized Accounts', () => {

it('cannot validate permission with invalid main address ', async () => {
const main = ethers.ZeroAddress;
const permission = Permission.TicketSigning;
const permission = Permission.PersonalSign;
await expect(
authAccountsConnectMain.validatePermission(
main,
Expand All @@ -581,7 +581,7 @@ describe('Authorized Accounts', () => {

it('cannot validate permission with invalid authorized address ', async () => {
const authorizedAddress = ethers.ZeroAddress;
const permission = Permission.TicketSigning;
const permission = Permission.PersonalSign;
await expect(
authAccountsConnectMain.validatePermission(
mainAccountAddress,
Expand Down Expand Up @@ -617,7 +617,7 @@ describe('Authorized Accounts', () => {
const validate = await authAccountsConnectMain.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
await currentBlock(),
);
assert.equal(validate, false);
Expand All @@ -632,7 +632,7 @@ describe('Authorized Accounts', () => {
const validate = await authAccountsConnectMain.validatePermission(
mainAccountAddress,
delegatedAccount2,
Permission.TicketSigning,
Permission.PersonalSign,
await currentBlock(),
);

Expand All @@ -649,7 +649,7 @@ describe('Authorized Accounts', () => {
const validate = await authAccountsConnectMain.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
await currentBlock(),
);

Expand All @@ -670,7 +670,7 @@ describe('Authorized Accounts', () => {
let validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
1000,
);
assert.equal(validate, false);
Expand All @@ -682,7 +682,7 @@ describe('Authorized Accounts', () => {
validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
1000,
);
assert.equal(validate, true);
Expand All @@ -695,7 +695,7 @@ describe('Authorized Accounts', () => {
validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
(await currentBlock()) - 3n,
);
assert.equal(validate, true);
Expand All @@ -704,7 +704,7 @@ describe('Authorized Accounts', () => {
validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
authBlock,
);
assert.equal(validate, true);
Expand All @@ -713,7 +713,7 @@ describe('Authorized Accounts', () => {
validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
authBlock - 1n,
);
assert.equal(validate, false);
Expand All @@ -722,7 +722,7 @@ describe('Authorized Accounts', () => {
validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
unauthBlock + 1n,
);
assert.equal(validate, false);
Expand All @@ -731,7 +731,7 @@ describe('Authorized Accounts', () => {
validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
unauthBlock + 123n,
);
assert.equal(validate, false);
Expand All @@ -743,7 +743,7 @@ describe('Authorized Accounts', () => {
validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
authBlock,
);
assert.equal(validate, true);
Expand All @@ -752,7 +752,7 @@ describe('Authorized Accounts', () => {
validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
authBlock + 10n,
);
assert.equal(validate, true);
Expand All @@ -761,7 +761,7 @@ describe('Authorized Accounts', () => {
validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
authBlock - 3n,
);
assert.equal(validate, false);
Expand All @@ -776,7 +776,7 @@ describe('Authorized Accounts', () => {
validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
authBlock - 3n,
);
assert.equal(validate, false);
Expand All @@ -785,7 +785,7 @@ describe('Authorized Accounts', () => {
validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
authBlock + 3n,
);
assert.equal(validate, true);
Expand All @@ -794,7 +794,7 @@ describe('Authorized Accounts', () => {
validate = await authContract.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
authBlock - 1n,
);
assert.equal(validate, false);
Expand All @@ -809,7 +809,7 @@ describe('Authorized Accounts', () => {
const validate = await authAccountsConnectMain.validatePermission(
mainAccountAddress,
delegatedAccount1,
Permission.TicketSigning,
Permission.PersonalSign,
(await currentBlock()) + 1n,
);

Expand Down
4 changes: 2 additions & 2 deletions test/payments/multiReceiverTicketing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ describe('MultiReceiverTicketing', () => {
),
).to.be.revertedWithCustomError(
syloTicketing,
'InvalidSenderTicketSigningPermission',
'InvalidSenderSigningPermission',
);

await expect(
Expand All @@ -265,7 +265,7 @@ describe('MultiReceiverTicketing', () => {
),
).to.be.revertedWithCustomError(
syloTicketing,
'InvalidReceiverTicketSigningPermission',
'InvalidReceiverSigningPermission',
);

const malformedSig =
Expand Down
Loading

0 comments on commit 334b827

Please sign in to comment.