Tjaden Hess
  • Member for 5 years, 10 months
  • Last seen this week
1 answers
5 votes
646 views
Storing hardcoded calldata in a Solidity contract
Accepted answer
6 votes

The issue is that when you use a string literal like bytes public hardcodedCallData = "...

View answer
3 answers
59 votes
15k views
Why can't contracts make API calls?
Accepted answer
76 votes

The Ethereum blockchain was designed to be entirely deterministic. This means, that if I took the whole history of the network, then replayed it on my computer, I should always end up with the correct ...

View answer
20 answers
196 votes
69k views
How can I securely generate a random number in my smart contract?
Accepted answer
157 votes

There are a few trade-offs and key points to keep in mind in this area. Any decision that a user makes which affects the outcome gives that user an unfair advantage. Examples include: Using a ...

View answer
9 answers
10 votes
6k views
Logarithm math operation in Solidity
13 votes

Here's a very efficient (< 700 gas) way to calculate the ceiling of log_2: function log2(uint x) returns (uint y){ assembly { let arg := x x := sub(x,1) x := or(x, div(x,...

View answer
1 answers
0 votes
519 views
How do I add 7 years to a current time expressed as a block.timestamp?
Accepted answer
1 votes

If you are OK with being overly simplistic and ignoring leap seconds and leap years, you can simply do uint timeInSevenYearsFromNow = now + 7 * 365 days; In older versions of solidity you could use ...

View answer
2 answers
3 votes
1k views
Avoid using "now"
6 votes

The use of block.timestamp (which is what now is an alias of) is often discouraged because it is somewhat manipulable by miners. This is only an issue if you need the time to be precise to within ~90 ...

View answer
13 answers
170 votes
45k views
Upgradeable smart contracts
139 votes

Once a contract is in the blockchain, it is final and cannot be changed. Certain parameters, of course, can be changed if they are allowed to change via the original code. One method of updating ...

View answer
1 answers
3 votes
33 views
Cipher Suites - open source?
Accepted answer
3 votes

Both Geth and Parity use libsecp256k1 for ECDSA. libsecp256k1 was developed originally for and continues to be used by Bitcoin Core. This library is actively maintained and has been the basis of all ...

View answer
3 answers
6 votes
2k views
Is it possible to make multiple function calls in a single transaction?
Accepted answer
3 votes

There is no way to do this without using a contract. In general, due to Ethereum's "no features" design principle, anything more complex than a simple transaction will require a smart contract. In ...

View answer
2 answers
3 votes
312 views
Where is the contract bytecode stored when a contract creates a contract?
2 votes

The code of a contract is part of it's account state. Every account in ethereum has a state which consists of it's balance, code, storage, and nonce. The tree consisting of the states of every ...

View answer
6 answers
16 votes
13k views
How to convert an address to bytes in Solidity?
Accepted answer
22 votes

To be even more efficient: function toBytes(address a) public pure returns (bytes memory b){ assembly { let m := mload(0x40) a := and(a, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)...

View answer
1 answers
1 votes
287 views
Method to verify an address nonce within a contract?
1 votes

The nonce of an account is not directly accessible through the EVM. In general, the state of arbitrary accounts is not accessible within the EVM. One (costly and cumbersome) way to prove that an ...

View answer
1 answers
8 votes
223 views
Why does adding a view function make write functions cost more gas?
Accepted answer
8 votes

As @smarx said, the increasing gas cost is because of the larger function dispatch table. You can verify this in Remix by stepping through the execution in the debugger. Here's a screenshot of the ...

View answer
1 answers
13 votes
4k views
How do I construct a call to another contract using inline assembly?
Accepted answer
13 votes

The error was due to an unhandled item on the stack that was left by the call opcode. The working and optimized relevant code is here: assembly { let x := mload(0x40) //Find empty ...

View answer
2 answers
2 votes
783 views
Error: Failed account unlock attempt, is this an attack?
2 votes

This is a brute-force attack against your password. Besides potentially stealing all of your ETH, descryption is relatively expensive computationally and could be a DOS vector. You should never ...

View answer
2 answers
4 votes
367 views
Why are transaction tries in Ethereum not plain Merkle Tries?
Accepted answer
4 votes

First, it should be noted that there is no such thing as a "plain Merkle Trie". The Merkle tree found in Bitcoin is not a radix tree (trie). The main reason Ethereum uses a Patricia Trie for ...

View answer
1 answers
1 votes
664 views
Decoding parameters with inline assembly in Solidity
Accepted answer
1 votes

Yes, this is available in Solidity as abi.decode. You can see the documentation here https://solidity.readthedocs.io/en/v0.5.3/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-...

View answer
5 answers
1 votes
902 views
Can I easily generate a public address which has no private key?
Accepted answer
5 votes

TLDR: Use address 0. Depending on your definition of a private key, then yes or no. The public key is generated from the private key by scalar elliptic curve multiplication. P = k * G We know that ...

View answer
6 answers
38 votes
25k views
How can I debug a smart contract?
Accepted answer
22 votes

The Remix IDE has a great integrated block-by-block simulator and debugger. Ganache allows fast contract testing without the hassle of running a node. Once the contract is live, the etherscan.io ...

View answer
2 answers
3 votes
2k views
Best practices for generating a random uint256
1 votes

While Shawn is on the right track, I think that is very important to make a clear distinction between arbitrarily manipulable randomness used for convenience and pseudorandomness with guarantees on ...

View answer
2 answers
2 votes
62 views
Unlocking function after time - is it safe?
1 votes

The timestamp in a block is required by the protocol to be at most 900 seconds ahead of a node's current clock time, see the block protocol wiki. So yes, it is safe to do what you are suggesting, and ...

View answer
1 answers
1 votes
299 views
How to check uncle block when listening to new block?
Accepted answer
2 votes

You can never be 100% sure that any given block will be in the long term chain, but as more blocks are added on top of it, the chance that a given block will become an uncle decreases exponentially. ...

View answer
1 answers
1 votes
118 views
Why is delete on arrays implemented in an energy and gas wasting way?
2 votes

For storage arrays, there is some use in deleting elements. Every storage address that is set to zero from a nonzero value produces a gas refund of 15000 gas, which can offset the costs of other ...

View answer
1 answers
1 votes
226 views
Why does it cost 21000 gas to send a transaction
Accepted answer
1 votes

The calculations for the original gas costs can be found in this spreadsheet. The costs are based on a weighted average of approximate costs (compute time, history size increase, state size increase). ...

View answer
1 answers
6 votes
694 views
Can a message hash be recovered from a signature?
Accepted answer
6 votes

No, you cannot recover the message hash from an ECDSA signature. The siagnture is calculated by generating (x, y) = kG where k is the secret nonce and G is the generator for the curve. Then r = x and ...

View answer
1 answers
1 votes
63 views
Is it possible to create one-time addresses, like in monero?
Accepted answer
0 votes

The construction presented in that paper only assumes that the discrete log and decisional Diffie Hellman problems are hard, which is certainly thought to be true for secp256k1. So yes, in that sense ...

View answer
3 answers
12 votes
14k views
Is it possible to check string variable's length inside the contract?
Accepted answer
19 votes

Just check if bytes(str).length is too big. EDIT: See the answer below if you need to know an exact length of a utf-8 encoded string. This will cost significantly more gas, however. Note that the ...

View answer
5 answers
62 votes
31k views
Why are selfdestructs used in contract programming?
Accepted answer
66 votes

Selfdestructs in Ethereum are an operation (an OPCODE actually) at the EVM level, independent of what language or client you are using. For example, calling selfdestruct(address) sends all of the ...

View answer
1 answers
16 votes
6k views
What does it mean to "run code on the blockchain"? Wouldn't blockchain become huge?
Accepted answer
19 votes

Code is run on the blockchain through the use of smart contracts. Each smart contract has an address, storage, and code. When a transaction is sent to a contract's address, it's code is run on every ...

View answer
1 answers
2 votes
47 views
Can ethereum logs be present while transaction is being mined, then disappear later?
1 votes

Yes, this is possible, and happens all of the time. Small reorganizations (one or two blocks lost) are quite common. The solution is to wait for n blocks after receiving a receipt before acting on ...

View answer
1
2 3 4 5
12