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

Nullify authorization before transferring [L03] #305

Merged
merged 1 commit into from
Jul 17, 2020
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
8 changes: 4 additions & 4 deletions contracts/v2/GasAbstraction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ abstract contract GasAbstraction is AbstractFiatTokenV2, EIP712Domain {
);
EIP712.verifySignature(DOMAIN_SEPARATOR, from, v, r, s, data);

_transfer(from, to, value);
_markAuthorizationAsUsed(from, nonce);
_transfer(from, to, value);
}

/**
Expand Down Expand Up @@ -147,9 +147,9 @@ abstract contract GasAbstraction is AbstractFiatTokenV2, EIP712Domain {
nonce
);
EIP712.verifySignature(DOMAIN_SEPARATOR, owner, v, r, s, data);
_increaseAllowance(owner, spender, increment);

_markAuthorizationAsUsed(owner, nonce);
_increaseAllowance(owner, spender, increment);
}

/**
Expand Down Expand Up @@ -188,9 +188,9 @@ abstract contract GasAbstraction is AbstractFiatTokenV2, EIP712Domain {
nonce
);
EIP712.verifySignature(DOMAIN_SEPARATOR, owner, v, r, s, data);
_decreaseAllowance(owner, spender, decrement);

_markAuthorizationAsUsed(owner, nonce);
_decreaseAllowance(owner, spender, decrement);
}

/**
Expand Down Expand Up @@ -229,8 +229,8 @@ abstract contract GasAbstraction is AbstractFiatTokenV2, EIP712Domain {
);
EIP712.verifySignature(DOMAIN_SEPARATOR, owner, v, r, s, data);

_approve(owner, spender, value);
_markAuthorizationAsUsed(owner, nonce);
_approve(owner, spender, value);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions test/v2/GasAbstraction/testApproveWithAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ export function testApproveWithAuthorization({
value
);

// check that Approval event is emitted
const log0 = result.logs[0] as Truffle.TransactionLog<Approval>;
expect(log0.event).to.equal("Approval");
// check that AuthorizationUsed event is emitted
const log0 = result.logs[0] as Truffle.TransactionLog<AuthorizationUsed>;
expect(log0.event).to.equal("AuthorizationUsed");
expect(log0.args[0]).to.equal(owner);
expect(log0.args[1]).to.equal(spender);
expect(log0.args[2].toNumber()).to.equal(value);
expect(log0.args[1]).to.equal(nonce);

// check that AuthorizationUsed event is emitted
const log1 = result.logs[1] as Truffle.TransactionLog<AuthorizationUsed>;
expect(log1.event).to.equal("AuthorizationUsed");
// check that Approval event is emitted
const log1 = result.logs[1] as Truffle.TransactionLog<Approval>;
expect(log1.event).to.equal("Approval");
expect(log1.args[0]).to.equal(owner);
expect(log1.args[1]).to.equal(nonce);
expect(log1.args[1]).to.equal(spender);
expect(log1.args[2].toNumber()).to.equal(value);

// check that the authorization state is now 1 = Used
expect(
Expand Down
36 changes: 18 additions & 18 deletions test/v2/GasAbstraction/testDecreaseAllowanceWithAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,18 @@ export function testDecreaseAllowanceWithAuthorization({
newAllowance
);

// check that Approval event is emitted
let log0 = result.logs[0] as Truffle.TransactionLog<Approval>;
expect(log0.event).to.equal("Approval");
// check that AuthorizationUsed event is emitted
let log0 = result.logs[0] as Truffle.TransactionLog<AuthorizationUsed>;
expect(log0.event).to.equal("AuthorizationUsed");
expect(log0.args[0]).to.equal(owner);
expect(log0.args[1]).to.equal(spender);
expect(log0.args[2].toNumber()).to.equal(newAllowance);
expect(log0.args[1]).to.equal(nonce);

// check that AuthorizationUsed event is emitted
let log1 = result.logs[1] as Truffle.TransactionLog<AuthorizationUsed>;
expect(log1.event).to.equal("AuthorizationUsed");
// check that Approval event is emitted
let log1 = result.logs[1] as Truffle.TransactionLog<Approval>;
expect(log1.event).to.equal("Approval");
expect(log1.args[0]).to.equal(owner);
expect(log1.args[1]).to.equal(nonce);
expect(log1.args[1]).to.equal(spender);
expect(log1.args[2].toNumber()).to.equal(newAllowance);

// check that the authorization state is now 1 = Used
expect(
Expand Down Expand Up @@ -196,18 +196,18 @@ export function testDecreaseAllowanceWithAuthorization({
newAllowance
);

// check that Approval event is emitted
log0 = result.logs[0] as Truffle.TransactionLog<Approval>;
expect(log0.event).to.equal("Approval");
// check that AuthorizationUsed event is emitted
log0 = result.logs[0] as Truffle.TransactionLog<AuthorizationUsed>;
expect(log0.event).to.equal("AuthorizationUsed");
expect(log0.args[0]).to.equal(owner);
expect(log0.args[1]).to.equal(spender);
expect(log0.args[2].toNumber()).to.equal(newAllowance);
expect(log0.args[1]).to.equal(nonce2);

// check that AuthorizationUsed event is emitted
log1 = result.logs[1] as Truffle.TransactionLog<AuthorizationUsed>;
expect(log1.event).to.equal("AuthorizationUsed");
// check that Approval event is emitted
log1 = result.logs[1] as Truffle.TransactionLog<Approval>;
expect(log1.event).to.equal("Approval");
expect(log1.args[0]).to.equal(owner);
expect(log1.args[1]).to.equal(nonce2);
expect(log1.args[1]).to.equal(spender);
expect(log1.args[2].toNumber()).to.equal(newAllowance);

// check that the authorization state is now 1 = Used
expect(
Expand Down
36 changes: 18 additions & 18 deletions test/v2/GasAbstraction/testIncreaseAllowanceWithAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,18 @@ export function testIncreaseAllowanceWithAuthorization({
newAllowance
);

// check that Approval event is emitted
let log0 = result.logs[0] as Truffle.TransactionLog<Approval>;
expect(log0.event).to.equal("Approval");
// check that AuthorizationUsed event is emitted
let log0 = result.logs[0] as Truffle.TransactionLog<AuthorizationUsed>;
expect(log0.event).to.equal("AuthorizationUsed");
expect(log0.args[0]).to.equal(owner);
expect(log0.args[1]).to.equal(spender);
expect(log0.args[2].toNumber()).to.equal(newAllowance);
expect(log0.args[1]).to.equal(nonce);

// check that AuthorizationUsed event is emitted
let log1 = result.logs[1] as Truffle.TransactionLog<AuthorizationUsed>;
expect(log1.event).to.equal("AuthorizationUsed");
// check that Approval event is emitted
let log1 = result.logs[1] as Truffle.TransactionLog<Approval>;
expect(log1.event).to.equal("Approval");
expect(log1.args[0]).to.equal(owner);
expect(log1.args[1]).to.equal(nonce);
expect(log1.args[1]).to.equal(spender);
expect(log1.args[2].toNumber()).to.equal(newAllowance);

// create another signed authorization to increase the allowance by
// another 2e6
Expand Down Expand Up @@ -161,18 +161,18 @@ export function testIncreaseAllowanceWithAuthorization({
newAllowance
);

// check that Approval event is emitted
log0 = result.logs[0] as Truffle.TransactionLog<Approval>;
expect(log0.event).to.equal("Approval");
// check that AuthorizationUsed event is emitted
log0 = result.logs[0] as Truffle.TransactionLog<AuthorizationUsed>;
expect(log0.event).to.equal("AuthorizationUsed");
expect(log0.args[0]).to.equal(owner);
expect(log0.args[1]).to.equal(spender);
expect(log0.args[2].toNumber()).to.equal(newAllowance);
expect(log0.args[1]).to.equal(nonce2);

// check that AuthorizationUsed event is emitted
log1 = result.logs[1] as Truffle.TransactionLog<AuthorizationUsed>;
expect(log1.event).to.equal("AuthorizationUsed");
// check that Approval event is emitted
log1 = result.logs[1] as Truffle.TransactionLog<Approval>;
expect(log1.event).to.equal("Approval");
expect(log1.args[0]).to.equal(owner);
expect(log1.args[1]).to.equal(nonce2);
expect(log1.args[1]).to.equal(spender);
expect(log1.args[2].toNumber()).to.equal(newAllowance);

// check that the authorization state is now 1 = Used
expect(
Expand Down
18 changes: 9 additions & 9 deletions test/v2/GasAbstraction/testTransferWithAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,18 @@ export function testTransferWithAuthorization({
);
expect((await fiatToken.balanceOf(to)).toNumber()).to.equal(value);

// check that Transfer event is emitted
const log0 = result.logs[0] as Truffle.TransactionLog<Transfer>;
expect(log0.event).to.equal("Transfer");
// check that AuthorizationUsed event is emitted
const log0 = result.logs[0] as Truffle.TransactionLog<AuthorizationUsed>;
expect(log0.event).to.equal("AuthorizationUsed");
expect(log0.args[0]).to.equal(from);
expect(log0.args[1]).to.equal(to);
expect(log0.args[2].toNumber()).to.equal(value);
expect(log0.args[1]).to.equal(nonce);

// check that AuthorizationUsed event is emitted
const log1 = result.logs[1] as Truffle.TransactionLog<AuthorizationUsed>;
expect(log1.event).to.equal("AuthorizationUsed");
// check that Transfer event is emitted
const log1 = result.logs[1] as Truffle.TransactionLog<Transfer>;
expect(log1.event).to.equal("Transfer");
expect(log1.args[0]).to.equal(from);
expect(log1.args[1]).to.equal(nonce);
expect(log1.args[1]).to.equal(to);
expect(log1.args[2].toNumber()).to.equal(value);

// check that the authorization state is now 1 = Used
expect(
Expand Down