Skip to content

Commit

Permalink
Blacklist updates (part 1)
Browse files Browse the repository at this point in the history
* Rename blacklist mapping to _deprecatedBlacklisted

* Rename balances to balanceAndBlacklistStates

* Rename balances to balanceAndBlacklistStates

* Replace _deprecatedBlacklisted
  • Loading branch information
circle-aloychan committed Oct 19, 2023
1 parent ad75174 commit 1ed8f78
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 96 deletions.
10 changes: 5 additions & 5 deletions contracts/v1/Blacklistable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { Ownable } from "./Ownable.sol";
*/
contract Blacklistable is Ownable {
address public blacklister;
mapping(address => bool) internal blacklisted;
mapping(address => bool) internal _deprecatedBlacklisted;

event Blacklisted(address indexed _account);
event UnBlacklisted(address indexed _account);
Expand All @@ -55,7 +55,7 @@ contract Blacklistable is Ownable {
*/
modifier notBlacklisted(address _account) {
require(
!blacklisted[_account],
!_deprecatedBlacklisted[_account],
"Blacklistable: account is blacklisted"
);
_;
Expand All @@ -66,15 +66,15 @@ contract Blacklistable is Ownable {
* @param _account The address to check
*/
function isBlacklisted(address _account) external view returns (bool) {
return blacklisted[_account];
return _deprecatedBlacklisted[_account];
}

/**
* @dev Adds account to blacklist
* @param _account The address to blacklist
*/
function blacklist(address _account) external onlyBlacklister {
blacklisted[_account] = true;
_deprecatedBlacklisted[_account] = true;
emit Blacklisted(_account);
}

Expand All @@ -83,7 +83,7 @@ contract Blacklistable is Ownable {
* @param _account The address to remove from the blacklist
*/
function unBlacklist(address _account) external onlyBlacklister {
blacklisted[_account] = false;
_deprecatedBlacklisted[_account] = false;
emit UnBlacklisted(_account);
}

Expand Down
22 changes: 14 additions & 8 deletions contracts/v1/FiatTokenV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract FiatTokenV1 is AbstractFiatTokenV1, Ownable, Pausable, Blacklistable {
address public masterMinter;
bool internal initialized;

mapping(address => uint256) internal balances;
mapping(address => uint256) internal balanceAndBlacklistStates;
mapping(address => mapping(address => uint256)) internal allowed;
uint256 internal totalSupply_ = 0;
mapping(address => bool) internal minters;
Expand Down Expand Up @@ -128,7 +128,9 @@ contract FiatTokenV1 is AbstractFiatTokenV1, Ownable, Pausable, Blacklistable {
);

totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
balanceAndBlacklistStates[_to] = balanceAndBlacklistStates[_to].add(
_amount
);
minterAllowed[msg.sender] = mintingAllowedAmount.sub(_amount);
emit Mint(msg.sender, _to, _amount);
emit Transfer(address(0), _to, _amount);
Expand Down Expand Up @@ -195,7 +197,7 @@ contract FiatTokenV1 is AbstractFiatTokenV1, Ownable, Pausable, Blacklistable {
view
returns (uint256)
{
return balances[account];
return balanceAndBlacklistStates[account];
}

/**
Expand Down Expand Up @@ -295,12 +297,16 @@ contract FiatTokenV1 is AbstractFiatTokenV1, Ownable, Pausable, Blacklistable {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(
value <= balances[from],
value <= balanceAndBlacklistStates[from],
"ERC20: transfer amount exceeds balance"
);

balances[from] = balances[from].sub(value);
balances[to] = balances[to].add(value);
balanceAndBlacklistStates[from] = balanceAndBlacklistStates[from].sub(
value
);
balanceAndBlacklistStates[to] = balanceAndBlacklistStates[to].add(
value
);
emit Transfer(from, to, value);
}

Expand Down Expand Up @@ -350,12 +356,12 @@ contract FiatTokenV1 is AbstractFiatTokenV1, Ownable, Pausable, Blacklistable {
onlyMinters
notBlacklisted(msg.sender)
{
uint256 balance = balances[msg.sender];
uint256 balance = balanceAndBlacklistStates[msg.sender];
require(_amount > 0, "FiatToken: burn amount not greater than 0");
require(balance >= _amount, "FiatToken: burn amount exceeds balance");

totalSupply_ = totalSupply_.sub(_amount);
balances[msg.sender] = balance.sub(_amount);
balanceAndBlacklistStates[msg.sender] = balance.sub(_amount);
emit Burn(msg.sender, _amount);
emit Transfer(msg.sender, address(0), _amount);
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/v2/FiatTokenV2_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ contract FiatTokenV2_1 is FiatTokenV2 {
// solhint-disable-next-line reason-string
require(_initializedVersion == 1);

uint256 lockedAmount = balances[address(this)];
uint256 lockedAmount = balanceAndBlacklistStates[address(this)];
if (lockedAmount > 0) {
_transfer(address(this), lostAndFound, lockedAmount);
}
blacklisted[address(this)] = true;
_deprecatedBlacklisted[address(this)] = true;

_initializedVersion = 2;
}
Expand Down
16 changes: 8 additions & 8 deletions test/helpers/storageSlots.behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function usesOriginalStorageSlotPositions<
// slot 2 - blacklister
expect(parseAddress(slots[2])).to.equal(blacklister); // blacklister

// slot 3 - blacklisted (mapping, slot is unused)
// slot 3 - _deprecatedBlacklisted (mapping, slot is unused)
expect(slots[3]).to.equal("0");

// slot 4 - name
Expand All @@ -123,7 +123,7 @@ export function usesOriginalStorageSlotPositions<
expect(slots[8].slice(0, 2)).to.equal("01"); // initialized
expect(parseAddress(slots[8].slice(2))).to.equal(masterMinter); // masterMinter

// slot 9 - balances (mapping, slot is unused)
// slot 9 - balanceAndBlacklistStates (mapping, slot is unused)
expect(slots[9]).to.equal("0");

// slot 10 - allowed (mapping, slot is unused)
Expand Down Expand Up @@ -154,31 +154,31 @@ export function usesOriginalStorageSlotPositions<
});
}

it("retains original storage slots for blacklisted mapping", async () => {
// blacklisted[alice]
it("retains original storage slots for _deprecatedBlacklisted mapping", async () => {
// _deprecatedBlacklisted[alice]
let v = parseInt(
await readSlot(proxy.address, addressMappingSlot(alice, 3)),
16
);
expect(v).to.equal(0);

// blacklisted[charlie]
// _deprecatedBlacklisted[charlie]
v = parseInt(
await readSlot(proxy.address, addressMappingSlot(charlie, 3)),
16
);
expect(v).to.equal(1);
});

it("retains original storage slots for balances mapping", async () => {
// balance[alice]
it("retains original storage slots for balanceAndBlacklistStates mapping", async () => {
// balanceAndBlacklistStates[alice]
let v = parseInt(
await readSlot(proxy.address, addressMappingSlot(alice, 9)),
16
);
expect(v).to.equal(minted - transferred);

// balances[bob]
// balanceAndBlacklistStates[bob]
v = parseInt(
await readSlot(proxy.address, addressMappingSlot(bob, 9)),
16
Expand Down
2 changes: 1 addition & 1 deletion test/minting/MintControllerTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function run_tests(newToken) {
expectedTokenState.push(
{ variable: "isAccountMinter.minterAccount", expectedValue: true },
{
variable: "balances.arbitraryAccount",
variable: "balanceAndBlacklistStates.arbitraryAccount",
expectedValue: newBigNumber(amount),
},
{ variable: "totalSupply", expectedValue: newBigNumber(amount) }
Expand Down
10 changes: 8 additions & 2 deletions test/minting/MintP0_EndToEndTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,10 @@ async function run_MINT_tests(newToken, MintControllerArtifact) {
variable: "minterAllowance.minterAccount",
expectedValue: newBigNumber(5),
},
{ variable: "balances.arbitraryAccount", expectedValue: newBigNumber(5) },
{
variable: "balanceAndBlacklistStates.arbitraryAccount",
expectedValue: newBigNumber(5),
},
{ variable: "totalSupply", expectedValue: newBigNumber(5) }
);
await checkMINTp0(
Expand Down Expand Up @@ -643,7 +646,10 @@ async function run_MINT_tests(newToken, MintControllerArtifact) {
expectedMintControllerState.controllers.arbitraryAccount =
Accounts.minterAccount;
expectedTokenState.push(
{ variable: "balances.minterAccount", expectedValue: newBigNumber(5) },
{
variable: "balanceAndBlacklistStates.minterAccount",
expectedValue: newBigNumber(5),
},
{ variable: "totalSupply", expectedValue: newBigNumber(5) }
);
await checkMINTp0(
Expand Down
4 changes: 2 additions & 2 deletions test/v1/TokenTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function buildExpectedState(token, customVars) {
proxiedTokenAddress: token.proxiedTokenAddress,
initializedV1: trueInStorageFormat,
upgrader: proxyOwnerAccount,
balances: {
balanceAndBlacklistStates: {
arbitraryAccount: bigZero,
masterMinterAccount: bigZero,
minterAccount: bigZero,
Expand Down Expand Up @@ -537,7 +537,7 @@ async function getActualState(token) {
proxiedTokenAddress: hexToAddress(proxiedTokenAddress),
upgrader: hexToAddress(upgrader),
initializedV1,
balances: {
balanceAndBlacklistStates: {
arbitraryAccount: balancesA,
masterMinterAccount: balancesMM,
minterAccount: balancesM,
Expand Down
4 changes: 2 additions & 2 deletions test/v1/helpers/tokenTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function buildExpectedState(token, customVars) {
proxiedTokenAddress: token.proxiedTokenAddress,
initializedV1: trueInStorageFormat,
upgrader: proxyOwnerAccount,
balances: {
balanceAndBlacklistStates: {
arbitraryAccount: bigZero,
masterMinterAccount: bigZero,
minterAccount: bigZero,
Expand Down Expand Up @@ -626,7 +626,7 @@ async function getActualState(token) {
proxiedTokenAddress: hexToAddress(proxiedTokenAddress),
upgrader: hexToAddress(upgrader),
initializedV1,
balances: {
balanceAndBlacklistStates: {
arbitraryAccount: balancesA,
masterMinterAccount: balancesMM,
minterAccount: balancesM,
Expand Down
Loading

0 comments on commit 1ed8f78

Please sign in to comment.