Skip to content

Commit

Permalink
Rename lock argument to warn (matching semantics).
Browse files Browse the repository at this point in the history
  • Loading branch information
saurik committed Mar 16, 2021
1 parent 3104580 commit af9fda7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
30 changes: 15 additions & 15 deletions lot-ethereum/lottery1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ contract OrchidLottery1 {
}
}

function edit(IERC20 token, uint256 amount, address signer, int256 adjust, int256 lock, uint256 retrieve) external {
function edit(IERC20 token, uint256 amount, address signer, int256 adjust, int256 warn, uint256 retrieve) external {
require(token != IERC20(0));
(bool success, bytes memory result) = address(token).call(
abi.encodeWithSignature("transferFrom(address,address,uint256)", msg.sender, this, amount));
require(success && abi.decode(result, (bool)));

edit_(msg.sender, token, amount, signer, adjust, lock, retrieve);
edit_(msg.sender, token, amount, signer, adjust, warn, retrieve);
send_(msg.sender, token, retrieve);
}

Expand All @@ -75,10 +75,10 @@ contract OrchidLottery1 {

if (false) {
} else if (selector == bytes4(keccak256("edit(address,int256,int256,uint256)"))) {
address signer; int256 adjust; int256 lock; uint256 retrieve;
(signer, adjust, lock, retrieve) = abi.decode(data[4:],
address signer; int256 adjust; int256 warn; uint256 retrieve;
(signer, adjust, warn, retrieve) = abi.decode(data[4:],
(address, int256, int256, uint256));
edit_(sender, IERC20(msg.sender), amount, signer, adjust, lock, retrieve);
edit_(sender, IERC20(msg.sender), amount, signer, adjust, warn, retrieve);
send_(sender, IERC20(msg.sender), retrieve);
} else require(false);
}
Expand All @@ -88,16 +88,16 @@ contract OrchidLottery1 {
return true;
}

function edit(address signer, int256 adjust, int256 lock, uint256 retrieve) external payable {
edit_(msg.sender, IERC20(0), msg.value, signer, adjust, lock, retrieve);
function edit(address signer, int256 adjust, int256 warn, uint256 retrieve) external payable {
edit_(msg.sender, IERC20(0), msg.value, signer, adjust, warn, retrieve);

if (retrieve != 0) {
(bool success,) = msg.sender.call{value: retrieve}("");
require(success);
}
}

function edit_(address funder, IERC20 token, uint256 amount, address signer, int256 adjust, int256 lock, uint256 retrieve) private {
function edit_(address funder, IERC20 token, uint256 amount, address signer, int256 adjust, int256 warn, uint256 retrieve) private {
bytes32 key = keccak256(abi.encodePacked(token, funder, signer));
Account storage account = accounts_[key];

Expand All @@ -116,18 +116,18 @@ contract OrchidLottery1 {
uint256 warned;
uint256 unlock;

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

if (lock > 0) {
if (warn > 0) {
unlock = block.timestamp + day_;

warned += uint256(lock);
require(warned >= uint256(lock));
warned += uint256(warn);
require(warned >= uint256(warn));
}

if (adjust < 0) {
Expand All @@ -150,9 +150,9 @@ contract OrchidLottery1 {
escrow += transfer;
}

if (lock < 0) {
uint256 decrease = uint256(-lock);
require(int256(decrease) != lock);
if (warn < 0) {
uint256 decrease = uint256(-warn);
require(int256(decrease) != warn);

require(decrease <= warned);
warned -= decrease;
Expand Down
10 changes: 5 additions & 5 deletions lot-ethereum/seller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ contract OrchidSeller {
return accounts_[signer].packed_;
}

function edit_(address sender, uint8 v, bytes32 r, bytes32 s, uint64 nonce, IERC20 token, uint256 amount, int256 adjust, int256 lock, uint256 retrieve, uint128 refill) private returns (address) {
function edit_(address sender, uint8 v, bytes32 r, bytes32 s, uint64 nonce, IERC20 token, uint256 amount, int256 adjust, int256 warn, uint256 retrieve, uint128 refill) private returns (address) {
execute_(token, sender, amount, retrieve);

bytes32 digest; assembly { digest := chainid() }
digest = keccak256(abi.encodePacked(byte(0x19), byte(0x00), this,
digest, nonce, token, amount, adjust, lock, retrieve, refill));
digest, nonce, token, amount, adjust, warn, retrieve, refill));
address signer = ecrecover(digest, v, r, s);

Account storage account = accounts_[signer];
Expand All @@ -117,9 +117,9 @@ contract OrchidSeller {
}


function edit(address signer, uint8 v, bytes32 r, bytes32 s, uint64 nonce, int256 adjust, int256 lock, uint256 retrieve, uint128 refill) external payable {
require(signer == edit_(msg.sender, v, r, s, nonce, IERC20(0), msg.value, adjust, lock, retrieve, refill));
lottery_.edit{value: msg.value}(signer, adjust, lock, retrieve);
function edit(address signer, uint8 v, bytes32 r, bytes32 s, uint64 nonce, int256 adjust, int256 warn, uint256 retrieve, uint128 refill) external payable {
require(signer == edit_(msg.sender, v, r, s, nonce, IERC20(0), msg.value, adjust, warn, retrieve, refill));
lottery_.edit{value: msg.value}(signer, adjust, warn, retrieve);

if (retrieve != 0) {
(bool success,) = msg.sender.call{value: retrieve}("");
Expand Down
12 changes: 6 additions & 6 deletions tst-ethereum/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,30 +367,30 @@ struct Tester {
#endif

#if 1
co_await Test1("erc20", lottery1, [&](const Executor &sender, const Address &lottery, const uint256_t &value, const Address &signer, const checked_int256_t &adjust, const checked_int256_t &lock, const uint256_t &retrieve) -> task<void> {
co_await Test1("erc20", lottery1, [&](const Executor &sender, const Address &lottery, const uint256_t &value, const Address &signer, const checked_int256_t &adjust, const checked_int256_t &warn, const uint256_t &retrieve) -> task<void> {
static Selector<void, Address, uint256_t, Address, checked_int256_t, checked_int256_t, uint256_t> edit("edit");
if (value != 0)
co_await Audit("approve", co_await sender.Send(chain_, {}, token, 0, approve(lottery, value)));
co_await Audit("edit", co_await sender.Send(chain_, {}, lottery, 0, edit(token, value, signer, adjust, lock, retrieve)));
co_await Audit("edit", co_await sender.Send(chain_, {}, lottery, 0, edit(token, value, signer, adjust, warn, retrieve)));
}, token);
#endif

#if 1
Log() << std::dec << co_await balanceOf.Call(chain_, "latest", token, 90000, lottery1) << std::endl;
co_await Test1("erc677", lottery1, [&](const Executor &sender, const Address &lottery, const uint256_t &value, const Address &signer, const checked_int256_t &adjust, const checked_int256_t &lock, const uint256_t &retrieve) -> task<void> {
co_await Test1("erc677", lottery1, [&](const Executor &sender, const Address &lottery, const uint256_t &value, const Address &signer, const checked_int256_t &adjust, const checked_int256_t &warn, const uint256_t &retrieve) -> task<void> {
Log() << std::dec << co_await balanceOf.Call(chain_, "latest", token, 90000, lottery1) << std::endl;
static Selector<void, Address, checked_int256_t, checked_int256_t, uint256_t> edit("edit");
co_await Audit("edit", co_await sender.Send(chain_, {}, token, 0, transferAndCall(lottery, value, Beam(edit(signer, adjust, lock, retrieve)))));
co_await Audit("edit", co_await sender.Send(chain_, {}, token, 0, transferAndCall(lottery, value, Beam(edit(signer, adjust, warn, retrieve)))));
Log() << std::dec << co_await balanceOf.Call(chain_, "latest", token, 90000, lottery1) << std::endl;
}, token);
Log() << std::dec << co_await balanceOf.Call(chain_, "latest", token, 90000, lottery1) << std::endl;
#endif
#endif

#if 1
co_await Test1("ether", lottery1, [&](const Executor &sender, const Address &lottery, const uint256_t &value, const Address &signer, const checked_int256_t &adjust, const checked_int256_t &lock, const uint256_t &retrieve) -> task<void> {
co_await Test1("ether", lottery1, [&](const Executor &sender, const Address &lottery, const uint256_t &value, const Address &signer, const checked_int256_t &adjust, const checked_int256_t &warn, const uint256_t &retrieve) -> task<void> {
static Selector<void, Address, checked_int256_t, checked_int256_t, uint256_t> edit("edit");
co_await Audit("edit", co_await sender.Send(chain_, {}, lottery, value, edit(signer, adjust, lock, retrieve)));
co_await Audit("edit", co_await sender.Send(chain_, {}, lottery, value, edit(signer, adjust, warn, retrieve)));
}, 0);
#endif
}
Expand Down

0 comments on commit af9fda7

Please sign in to comment.