Skip to content

Commit

Permalink
Protect prepaid access credits from kill switches.
Browse files Browse the repository at this point in the history
  • Loading branch information
saurik committed Mar 14, 2021
1 parent 7f3b5d0 commit f0013f0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
16 changes: 13 additions & 3 deletions lot-ethereum/lottery1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@ contract OrchidLottery1 {
amount += uint128(backup);
}
{
uint256 marked;
uint256 warned;
uint256 unlock;

if (adjust < 0 || lock != 0) {
warned = pot.unlock_warned_;
unlock = warned >> 128;
marked = warned >> 192;
unlock = uint64(warned >> 128);
warned = uint128(warned);
}

Expand Down Expand Up @@ -187,7 +189,7 @@ contract OrchidLottery1 {
}

if (unlock != 0) {
uint256 cache = (warned == 0 ? 0 : unlock << 128 | warned);
uint256 cache = marked << 192 | (warned == 0 ? 0 : unlock << 128 | warned);
pot.unlock_warned_ = cache;
emit Delete(account, cache);
}
Expand Down Expand Up @@ -228,6 +230,14 @@ contract OrchidLottery1 {
return lottery.merchants_[recipient];
}

function mark(IERC20 token, address signer) external {
Pot storage pot = lotteries_[msg.sender].pots_[signer][token];
uint256 cache = pot.unlock_warned_;
cache = block.timestamp << 192 | uint192(cache);
pot.unlock_warned_ = cache;
emit Delete(keccak256(abi.encodePacked(token, msg.sender, signer)), cache);
}


/*struct Track {
uint96 expire;
Expand Down Expand Up @@ -306,7 +316,7 @@ contract OrchidLottery1 {
Pot storage pot = lottery.pots_[signer][token];

if (lottery.closed_ - 1 < block.timestamp)
if (lottery.merchants_[recipient] <= block.timestamp)
if (lottery.merchants_[recipient] <= pot.unlock_warned_ >> 192)
return 0;
{
Track storage track = tracks_[keccak256(abi.encodePacked(digest, signer))];
Expand Down
3 changes: 3 additions & 0 deletions lot-ethereum/seller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ contract OrchidSeller {
require(account.nonce_ == nonce);
account.nonce_ = nonce + 1;

if (amount > retrieve)
lottery_.mark(token, signer);

return signer;
}

Expand Down
6 changes: 3 additions & 3 deletions tst-ethereum/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ struct Tester {
//Log() << std::dec << uint128_t(escrow_balance) << " " << uint128_t(escrow_balance >> 128) << std::endl;
orc_assert(uint128_t(escrow_balance) == account.balance_);
orc_assert(uint128_t(escrow_balance >> 128) == account.escrow_);
if (unlock_warned != 0) {
const auto warned((uint128_t(unlock_warned)));
if (unlock_warned << 64 != 0) {
const auto warned((uint64_t(unlock_warned)));
const auto unlock(uint128_t(unlock_warned >> 128));
Log() << std::dec << warned << " " << unlock << std::endl;
}
Expand Down Expand Up @@ -270,7 +270,7 @@ struct Tester {

static const auto update(
EVM_STORE_GET+EVM_STORE_SET+
EVM_EVENT_IDX*2+EVM_EVENT_ARG*3+
EVM_EVENT_IDX*2+EVM_EVENT_ARG*2+
0);

static const unsigned perp(
Expand Down

0 comments on commit f0013f0

Please sign in to comment.