New answers tagged

0

Due to their unpredictable size, dynamically-sized array types use a Keccak-256 hash computation to find the starting position of the array data. So in your example: The position of storageArr[0] is at keccak256(uint256(0)) + 0 The position of storageArr[1] is at keccak256(uint256(0)) + 1 The position of storageArr[2] is at keccak256(uint256(0)) + 2 Here ...


0

It has to do with addressing storage. Let's break it down. Consider a bool and an address. The bool takes 1 byte (limitation of optimization) and the address takes 20 bytes. So we need 21 bytes of storage. The EVM uses 32-byte words which are the smallest chunk of storage that is addressable. If you go contract A { mapping(uint => bool) b; mapping(...


2

This is about how the variables are packed together and about how smart the compiler is (hint: not very smart). The compiler only tries to pack subsequent variables together but it can't pack variables which have something else between them. In your first case the variables could all fit inside a single 32 byte slot, but if I'm not mistaken the compiler ...


2

To add to goodvibration's answer, the problem with sending ERC-20 to any contract is that the contract is not aware of that transaction. There's no function that's called when the tokens are received, so it's not possible to assign that balance to a specific sender. This is why things like decentralised exchanges use approve and transferFrom. In this case a ...


1

There's Simple Multisig, by Christian Lundkvist, that requires sending all signatures in a single transaction. It has a execute function that validates the signatures and executes the operation requested: function execute( uint8[] sigV, bytes32[] sigR, bytes32[] sigS, address destination, uint value, bytes data, address ...


2

Yes. You can achieve this by using signatures of the member keys instead of transactions. To achieve this, each members of the multisig can sign a message attesting that they approve of the transaction. They can then give their signatures to a single entity who broadcasts the transaction that includes all the signatures as data. On-chain, the smart contract ...


0

If there is additional code in wrapperForFunction before _function is called, it can save some gas when you call require sooner. If it's just a wrapper for _function and you don't do any additional stuff, the difference in gas is neglectible. Using the following contract, the total transaction cost is 21422 gas according to Remix. contract Example { ...


0

Constructors enable to reuse the smart contract without changing it. Let's take the case of an ERC20 token with the following input parameters : name, symbol, decimals, totalSupply. You can hardcode these values and deploy your contract, it will work fine. Now suppose you need to deploy a new ERC20 with different input characteristics. Well, you will have to ...


0

You should modify the contract's transfer and approve functions to check if the target address is a contract address. If it is, revert the transaction. You can check if an address is a contract address with: function isContract(address _addr) private returns (bool isContract){ uint32 size; assembly { size := extcodesize(_addr) } return (size > ...


0

Any Ether transfers to a contract are automatically reverted, unless explicitly allowed by the contract, e.g. by: using a payable function using a receive or fallback function If a function is called with a non-zero value and it's not payable, the transaction will be reverted. If no function is called (no transaction data), and there is no receive or ...


0

You can make it harder but not impossible. To make it harder you can implement the receive function (https://solidity.readthedocs.io/en/v0.7.0/contracts.html#receive-ether-function) and always revert it if's being called. Of course you shouldn't have other payable functions then. Even if you revert all Ether transfers with a receive function there are three ...


0

You don't need a password system as the user signs the transactions with its private key. If I understand well your use case you want to : The current car owner offers to a next car owner his car with transferOwnership. The next car owner accepts the transaction with acceptOwnership. One solution would be to use the approve/transferFrom pattern of the ...


1

Remix uses JSON notation for the input, and uint256[5] is just an array with a length of 5, so in Remix you can do something like this: [1, 2, 3, 4, 5], [6, 7, 8, 9, 10]


2

From Solidity the documentation: The layout of state variables in storage is considered to be part of the external interface of Solidity due to the fact that storage pointers can be passed to libraries. This means that any change to the rules outlined in this section is considered a breaking change of the language and due to its critical nature should be ...


0

Yes. Jthereum supports writing contracts for the Ethereum blockchain in Java. It is a commercial product targeted at enterprise use. Http://Jthereum.com


1

One solution is to move the contract initialization in a separate function contract Files { ERC20 authorToken; function init(ERC20 token) public { require(address(authorToken) == address(0x0)); authorToken = token; } } contract AuthorToken { Files files; function init(Files f) public { require(address(files) == ...


0

check your test script, there is some problem with parentheses. By the way, I tried to imagine the sense of the script. I guess you call the function set_data(...) as many times as the elements you want to add, but for example if the input is always the same, in particular the Data parameter, then the element will be added only the first time because the Y ...


Top 50 recent answers are included