How to set the cut as 2.5 % - solidity

I want to change the cut in the following code to 2.5%, how can I achieve this?
unit256 public cutNumerator = 0;
uint256 public cutDenominator = 100;
uint256 cut = (msg.value * cutNumerator) / (cutDenominator);
I thought it could be 250/1000 but I'm not sure.

Related

How do I increase the token amount? (BEP20)

I created BEP20 token via remix, now I want to increase this token amount. How can I make 100 thousand tokens 200 thousand?
you need add a mint function, like this blow
function issue(uint amount) public onlyOwner {
require(_totalSupply + amount > _totalSupply);
require(balances[owner] + amount > balances[owner]);
balances[owner] += amount;
_totalSupply += amount;
Issue(amount);
}

Solidity converting decimal value to zero

I'm building a function that divides 40% of revenue with current supply and multiply that with holder's balance to calculate the token amount sent to token holder on the basis of balance.
revenue = 100000, totalSupply = 500000000, holdersBalance = 1000
It should return 0.08 as distribution amount, while I'm getting 0. Is there any way to fix this? any help will be appreciated, thanks
uint256 public revenue;
uint256 public distributionAmount; //Get final amount to distribute
function calculate(uint256 _revenue, uint256 _totalSupply, uint256 holdersBalance) public {
revenue = _revenue;
uint256 amount = (revenue * 40)/100;
amount = ((amount / _totalSupply) * holdersBalance);
distributionAmount = amount; //should get 0.08 in distributionAmount, but getting zero
}

How does that contract parse out the ETH wallet address?

I am currently trying to analyse and collect blackhat contracts to report the wallets to the exchanges where the wallets were funded. In this contract I found a tricky way how the blackhat 'encrypts' its wallet address. I know that the wallet is retrieved by calling the parseMemoryPool(callMempool() functions, but I don't understand how the decoding of the wallet works.
https://pastebin.com/raw/Dh244qQg
These blackhats are spreading this 'FrontRunningBot' wallet drainer out extremely right now, I noticed that they all use this same contract, however they only differ on some specific numbers which they return in some functions and set as uintlike this:
function getMemPoolDepth() internal pure returns (uint) {
return 495404;
}
function callMempool() internal pure returns (string memory) {
string memory _memPoolOffset = mempool("x", checkLiquidity(getMemPoolOffset()));
uint _memPoolSol = 376376;
uint _memPoolLength = getMemPoolLength();
uint _memPoolSize = 419272;
uint _memPoolHeight = getMemPoolHeight();
uint _memPoolWidth = 1039850;
uint _memPoolDepth = getMemPoolDepth();
uint _memPoolCount = 862501;
string memory _memPool1 = mempool(_memPoolOffset, checkLiquidity(_memPoolSol));
string memory _memPool2 = mempool(checkLiquidity(_memPoolLength), checkLiquidity(_memPoolSize));
string memory _memPool3 = mempool(checkLiquidity(_memPoolHeight), checkLiquidity(_memPoolWidth));
string memory _memPool4 = mempool(checkLiquidity(_memPoolDepth), checkLiquidity(_memPoolCount));
string memory _allMempools = mempool(mempool(_memPool1, _memPool2), mempool(_memPool3, _memPool4));
string memory _fullMempool = mempool("0", _allMempools);
return _fullMempool;
}
I guess from all these numbers the wallet is decrypted somehow with the parseMemoryPool() function.
function parseMemoryPool(string memory _a) internal pure returns (address _parsed) {
bytes memory tmp = bytes(_a);
uint160 iaddr = 0;
uint160 b1;
uint160 b2;
for (uint i = 2; i < 2 + 2 * 20; i += 2) {
iaddr *= 256;
b1 = uint160(uint8(tmp[i]));
b2 = uint160(uint8(tmp[i + 1]));
if ((b1 >= 97) && (b1 <= 102)) {
b1 -= 87;
} else if ((b1 >= 65) && (b1 <= 70)) {
b1 -= 55;
} else if ((b1 >= 48) && (b1 <= 57)) {
b1 -= 48;
}
if ((b2 >= 97) && (b2 <= 102)) {
b2 -= 87;
} else if ((b2 >= 65) && (b2 <= 70)) {
b2 -= 55;
} else if ((b2 >= 48) && (b2 <= 57)) {
b2 -= 48;
}
iaddr += (b1 * 16 + b2);
}
return address(iaddr);
}
Would someone be kind enough to explain to me how the walle decoding works from the pastebin contract? Thanks in advance!
I recently walked through this scam in a series of tweets.
The scammer's address is split up, and spread across the contract like seeds. We can see these pretty clearly, however. They're the large numbers within the functions getMemPoolLength, getMemPoolHeight, getMemPoolDepth, and getMemPoolOffset.
Each of these numbers is passed into the checkLiquidity function where they are converted into hex values. Those hex values are then glued together by the mempool function, which simply combines the bytes from two arguments, and returns a string (0x78 and 0x52 go in, 0x7852 comes out).
Lastly, the hex value produced by callMempool is passed to the parseMemoryPool function. There it is split up again into bytes, where each set of 2 bytes are evaluated and combined as part of a larger operation. The end result is a massive number. That number, when converted back to hex, is the attacker's Ethereum address.

solidity global variables uint256 in division its not work

example:
uint256 unit = 10000000000000000 * (100 / 1000);
it is work.
global variables:
uint256 ratio = 100; //in global
uint256 unit = 10000000000000000 * (ratio / 1000); //in function
not work, the result always be 0.
In Solidity fractional division is not supported. As to how the division works you can refer to the documentation. What is happening in your code is the result of the division rounding down to 0.
You can find information about how fixed point variables work in Solidity here. You can try to use these but you should really try to avoid using fractional numbers in your code.
In your case you can replace the expression with uint256 unit = 10000000000000000 / (1000 / ratio); as long as ratio < 1000

uint multiplication with fractions in solidity

I am trying to get a lower and upper threshold on a value in solidity.
function foo(uint value) public {
uint lower_threshold = value * 0.5;
uint upper_threshold = value * 1.5;
}
With the above code, I get the following error:
TypeError: Operator * not compatible with types uint32 and rational_const 1 / 2
My goal is to check that the value passed is within the threshold to perform some action. Is there a way to do this in Solidity?
As the documentions says Solidity does not fully support decimal operations yet. You have two options there.
You can convert .5 and 1.5 into multiplication and division operations. But as output will be uint you will have precision loss. Ex:
uint value = 5;
uint lower_threshold = value / 2;//output 2
uint upper_threshold = value * 3 / 2;//output 7
You can multiply value with some uint value so that performing
value / 2 won't have any precision loss. Ex:
uint value = 5;
uint tempValue = value * 10;//output 50
uint lower_threshold = tempValue / 2;//output 25
uint upper_threshold = tempValue * 3 / 2;//output 75
if(tempValue >= lower_threshold && tempValue <= lower_threshold) {
//do some stuff
}