Why did this txn not transfer balance, I passed the exact same string same hex as response set in question - solidity

I called https://etherscan.io/address/0x0c63bf5f9c1b31bd98eb2995e8ab5ba33fe31d22 contract's Try function by passing the same string which was passed in Start function. I checked hex. Can someone help me why Try function call https://etherscan.io/tx/0x096a060d64d833c55fd83b2ea4ec209578dc3316d863de3a3de63692e8476628
did not initiate balance transfer. Is there something, I am missing

The Quiz is a scam contract
The authors usually use a set of similar names ([a-z]{2}_quiz), but most of them contain the same code and act as a honeypot scam.
Read more about it:
https://medium.com/coinmonks/do-not-be-fooled-by-crypto-quiz-games-f38f72a53c78
https://ethereum.stackexchange.com/questions/62815/trying-to-figure-out-this-2-eth-smart-contract-quiz
How the scam works:
The attacker uses internal call from another contract (that doesn't appear on the honeypot "transactions" or "internal calls" lists) to call the New() function and set the hash to some garbage value.
This garbage value is not the hash of the string passed in the Start() function and most probably not even a hash of any string.
Then publicly calls the Start() function (see transaction), so that it looks like they are setting the hash, but it's not set because of this condition:
if(responseHash==0x0){ // it's not 0x0 anymore
responseHash = keccak256(abi.encode(_response));
question = _question;
}

Related

How to send EGLD value to smart contract endpoint?

I have a smart contract method that looks like this:
#[payable("EGLD")]
#[endpoint(myEndpoint)]
fn my_endpoint(&self, #[payment_amount] payment: BigUint, some_value: u64) { ... }
And I call it with 5 EGLD value in transaction along with tx data
myEndpoint#05#aa
but tx result returns me wrong number of arguments.
What am I doing wrong?
Payment args in EGLD are auto-filled from the call value you've already specified in the transaction, so you do not need to pass them as argument.
Therefore, your call data in this case would be myEndpoint#aa, without the payment arg.
As a side note, if this would've been an endpoint accepting another token than EGLD, you would've had to specify the token and amount in the data field, like:
ESDTNFTTransfer#TokenIdentifier_in_hex#TokenNonce_in_hex#TokenValue_in_hex#Contract_address_in_hex#myEndpoint_in_hex#aa.
The ESDTNFTTransfer function sends any type of ESDT token, with or without nonce. If the token doesn't have a nonce (fungible), you can either pass 00 as nonce or leave the nonce space empty, like #TokenName_in_hex##TokenValue_in_hex.
Mind the fact that in order to use this function, you would have to compose a transaction with the destination set as yourself. The actual address of the destination would be contained in the data field in place ofContract_address_in_hex, making it a parameter of the ESDTNFTTransfer function.
If the endpoint accepted two tokens for example, then you could've used MultiESDTNFTTransfer#Contract_address_in_hex#02#Token1Identifier_in_hex#Token1Nonce_in_hex#Token1Value_in_hex#Token2Identifier_in_hex#Token2Nonce_in_hex#Token2Value_in_hex#myEndpoint_in_hex.
And yeah, you can always check the Elrond docs on ESDT Tokens / NFT Tokens for more details.

Why do I have to store the result of a function in a variable?

Is it because some functions will change the object and some don't so you have to store the returned value in a variable? I'm sure there's a better way to ask the question, but I hope that makes sense.
Example case: Why doesn't thisString stay capitalized? What happens to the output of the toUpperCase() function when I call it on thisString? Is there a name for this behavior?
var thisString: String = "this string"
var thatString: String = "that string"
thisString.toUpperCase()
thatString = thatString.toUpperCase()
println(thisString)
println(thatString)
which prints:
this string
THAT STRING
By convention if a function starts with the word to or a past participle, it always returns a new object and does not mutate the object it's called on. But that's not exclusively true. Functions that begin with a verb may or may not mutate the object, so you have to check the documentation to know for sure.
A mutable object might still have functions that return new objects. You have to check the documentation for the function you call.
For a function that returns a new object, if you don't do anything with the returned result or store it in a variable, it is lost to the garbage collector and you can never retrieve it.
String is an immutable class, so none of the functions you call on it will ever modify the original object. Immutable classes are generally less error-prone to work with because you can't accidentally modify an instance that's still being used somewhere else.
All the primitives are also immutable. If all the properties of a class are read-only vals and all the class types they reference are also immutable classes, then the class is immutable.
If you want an mutable alternative to String, you can use StringBuilder, StringBuffer, CharArray, or MutableList<Char>, depending on your needs. They all have different pros and cons.
Why doesn't thisString stay capitalized?
Because that's how the function was coded (emphasis mine):
"Returns a copy of this string converted to upper case using the rules of the default locale."
What happens to the output of the toUpperCase() function when I call it on thisString?
Nothing. If you don't assign it to a variable (save a reference to it) it's discarded.
Is there a name for this behavior?
AFAIK, this is simply "ignoring the return value".
Hope that helps.

C# to Vb.NET code convert

below code is c#
ctx.CreateStreamResponse(stream => new Session(_Sessions, stream).Process(),"video/mp4");
and i need to this code as VB.NET code. am converting as below
ctx.CreateStreamResponse(Function(stream) New Session(_Sessions, stream).Process(), "video/mp4")
But getting error
overload resolution failed because no accessible
"CreateStreamResponse" can be called with these arguments.
CreateStreamResponse needs 2 parameters
Stream (as my sample Function(stream) New Session(_Sessions, stream).Process())
content type (as my sample "video/mp4")
Anyone can help me, please
I believe the issue seems to be that the method which you pass into CreateStreamResponse should be a Sub not a Function. i.e:
ctx.CreateStreamResponse(Sub(stream) New Session(_Sessions, stream).Process(), "video/mp4")
CreateStreamResponse takes an Action(Of Stream) delegate as the first argument and a contentType of String as the second argument.
Thus you need to use Sub rather than a Function as in this case an Action delegate can only encapsulate methods that return void (sub procedures). Also, ensure that the Process method being invoked is also a Sub procedure.
If the problem persists then as suggested by Microsoft docs:
Review all the overloads for the method and determine which one you
want to call.
In your calling statement, make the data types of the arguments
match the data types of the parameters defined for the desired
overload. You might have to use the CType Function to convert one or
more data types to the defined types.
for more information see here

c++ CLI: get HKEY from SafeRegistryHandle

I work with the registry and use the function RegNotifyChangeKeyValue. The first option requires registry key handle (HKEY), but I have RegistryKey, from which I can get SafeRegistryKey (key->Handle).
RegistryKey^ key = myKey;
RegNotifyChangeKeyValue(key->Handle, true, dwFilter, events[i], true);
Error: "argument of type "Microsoft::Win32::SafeHandles::SafeRegistryHandle" is incompatible with parameter of type "HKEY""
How do I get HKEY?
A conversion is required to get from the wrapped IntPtr in the safe-handle class to the native handle. It looks like this:
HKEY handle = (HKEY)key->Handle->DangerousGetHandle().ToPointer();
You do get to fret over the word "Dangerous" in the method name, it is aptly named. There is nothing that the CLR can do to ensure that the handle stays valid until you no longer need the change notifications. It is now your job to ensure that the key object reference stays visible and the garbage collector won't collect it too early.
It cannot be a local variable, it could be a member of a class but that in turn requires the class object to stay referenced. Storing it in a static variable is the safest way, calling GCHandle::Alloc() is the next best way, maybe you need gcroot<>. There's no context in the question to make the call.

Is there a way to use default arguments that are the result of a function call in VB.NET?

I have a whole slew of database access functions which assume a particular connection string. Within my application I call
myList = DB_MyTable.GetTableItems()
and within GetTableItems() I have something like
Dim connection As SqlConnection = MyDB.GetConnection
So the connection string is in one place in the code, and I call a method to get it.
What I'm running into now is I want to reuse the same database functions, but with a different connection string. I can rewrite all of the functions like DB_MyTable.GetTableItems() easily because they're generated from a script, but within the main application code I'll need to take care of every function call that now needs to know what connection string I want to use.
I tried changing the arguments to GetTableItems() like this:
Public Shared Function GetTableItems(Optional ByVal useThisString as String = MyDB.GetConnection) As List(Of MyItems)
in hopes of being able to pass in, by default, the string I'm already using in most of the code, but I got an error saying that the default value had to be a constant expression. This would mean peppering a specific connection string everywhere, which I don't want to do.
Is there a way to accomplish what I'm after, or do I need to make the connection string a required argument and change all of the calls in my application to match the new signature?
Thanks as always!
Can you make your default value an empty string? Then, in your functions, if the useThisString variable is blank, then use default, else use the one you passed in? A littler dirtier, but just barely.