Questions tagged [contract-design]

for high-level questions about the choices made during contract construction

Filter by
Sorted by
Tagged with
1
vote
1answer
40 views

how does memory layout work?

I am trying to understand how https://solidity.readthedocs.io/en/v0.7.2/internals/layout_in_memory.html works. function test(uint a) public { uint test1 = 20; uint[1] testArr; testArr[0] = ...
1
vote
1answer
31 views

How is caller's data related to bytecode?

I know that smart contract is deployed as bytecode. When we call a function from application, we use the encoding with the help of ABI and we get some bytes. let's say 220 bytes. These are the bytes ...
1
vote
1answer
224 views

contract inline assembly - return array parts by using assembly

I've a couple of questions. mload function returns the data that resides on the address we pass to mload. Is this correct ? add function is used to give us the address from 0 to whatever we pass. ...
0
votes
1answer
25 views

why separate assignments are better than single?

I've read that: It is more gas efficient to initialize a tightly packed struct with separate assignments instead of a single assignment. Separate assignments makes it easier for the optimizer to ...
1
vote
1answer
57 views

how does contract cost less gas in structs?

I have a couple of questions. we have int types as uint8, uint16, uint32, etc. I read that : Normally there's no benefit to using these sub-types because Solidity reserves 256 bits of storage ...
1
vote
1answer
116 views

Why can smart contracts receive ETH but not other ERC-20 tokens?

From what I've gathered (and I'm new to Ethereum), smart contracts can receive ETH payments and hold them through the receive/fallback blocks, but cannot directly hold ERC-20 tokens, but rather they ...
2
votes
1answer
34 views

Bundling two assets in a contract and issuing shares for them

Say you are tasked with coding a smart contract with the following features: Users can deposit token A and receive liquidity shares in return. The contract starts selling token A for token B ...
1
vote
2answers
138 views

Multi-signature contract with offline signing

Is it possible to create a multi-signature contract that would not require a transaction for every signature (since this is quite expensive for a higher number of transactions)? Is it possible to ...
0
votes
1answer
29 views

Require(…) condition location in wrapped functions

If I'm wrapping functions, like below, does it make a difference whether I check the input argument in the private function or the external one? Will it save me gas cost to do it in the external one ...
0
votes
1answer
23 views

constructor input arguments or hardcoded values? best practice

What is the rationale for choosing to use constructor input arguments over hardcoded values? and what is best practice?
0
votes
1answer
102 views

Prevent Transfer of ERC20 token to contract address?

I want my ERC20 contract to be transferred to EOA addresses only and some specific contract address only. I don't want to lose my tokens by mistakenly transferring to a contract address that cannot ...
0
votes
2answers
315 views

Revert ETH transfer to smart contract

How can I revert a transfer of ETH funds to my smart contract? I would like to instantly revert any ETH being sent to my smart contract.
0
votes
1answer
31 views

Car Traceability

I want to deploy a smart contract for tracing cars. For example, say I am producing 10 cars Now what I want is to create a smart contract for tracing cars. So my smart contract will have three ...
0
votes
1answer
26 views

input argument structure for constructor in remix

how would the structure for an argument to the below constructor look like in remix? constructor( uint256[5] memory _a, uint256[5] memory _b, ) public {...}
0
votes
0answers
21 views

What is the difference in the two mapping structures

Is the below mapping structure a legit way to create a restricted mapping, or is the latter best practice? mapping(address => SomeStruct)[5] private structs; and mapping(address => mapping(...
2
votes
1answer
23 views

Am I locked to one solc version for upgradeable smart contracts?

I want to use delegatecall to make my contracts upgradeable. Is it true that variable layout may break if I change the solc version and therefore I should use the same Solidity version for all future ...
0
votes
1answer
19 views

Mutual dependency of two contracts

I have the following code in AuthorTokens.sol: Files files; // ... function mintAuthor(address _owner) external { require(msg.sender == files, "System function"); ...
0
votes
0answers
31 views

hardening infinite loops

What is the best way to 'harden' an infinite loop, if you are in a scenario where you would find it necessary to iterate over an array, would it be a best practice to put an assert condition in ...
0
votes
1answer
141 views

How do I count the elements of an array in solidity?

In my project, I want to count the elements of an array as follows: struct Server{ uint sernum; uint num; uint data; } Server [] public datta; function ...
0
votes
1answer
26 views

zero-initialisation of storage values in constructor or gas optimization

is it better to pay extra gas to initialise storage variables that are empty as zeroes in the constructor, or save the gas since the default is zero?
0
votes
1answer
33 views

Else if structure gives the wrong output

I have a little problem with a else if struture that doesn't give out the right result. Here is the code: pragma solidity >=0.5.16; contract SupChain{ enum StateType {A, B, C} ...
0
votes
0answers
50 views

Unbounded loop solidity internals

Under the hood, what happens in an unbounded loop? let's say I'm trying to send tokens to an infinite amount of addresses and end up with an out of gas error. Will the function which executes the ...
0
votes
1answer
29 views

Function not returning address when using web3 provider

I have a contract that works fine when only using remix. I needed to test the block size and block number. here someone suggested me to use ganache which I did but now I don't get the output I'm ...
0
votes
0answers
21 views

Can I make a delegatecall to a Solidity contract that is compiled with a higher compiler version?

Lets say that I have the contracts A and B. A needs to make a delegatecall to B. A is (for some reason) compiled with a compiler version that is lower than B's compiler version. Can I safely assume ...
0
votes
1answer
29 views

The below code gets compiled but when foo is called invalid opcode error is thrown

pragma solidity >=0.5.0 <0.7.0; contract Mycontract{ uint256 a; struct User { string name; } User[] users; function foo() public{ User storage user=users[0]; ...
0
votes
1answer
27 views

why x(function setArr) is not being returned?

pragma solidity >=0.5.0 <0.7.0; contract Example{ uint256[3] x; function setArr(uint256[3] memory y) public returns(uint256[3] memory){ x=y; return getArr(x); } ...
0
votes
0answers
35 views

Deliver a dapp to a client, how to set as owner?

So, as a freelancer that wants to make a smart contract for a client, how do you set such client as the owner of the contract? Would it be setting the owner variable to the eth address of the client, ...
1
vote
1answer
219 views

DApp Development- how to update dapp and keep existing data

Compare to web application that separate the application and database, we can update the application and keep the existing data. Could you suggest me how to update dapp and keep the existing data?
1
vote
1answer
26 views

How does array.length— work?

I'm having trouble understanding why people call array.length-- after deleting an element in an array (as seen in this answer and many others). Why is there need for doing so? When is the length of ...
1
vote
0answers
42 views

msg.sender and tx.origin - how to use them in practice? [duplicate]

I wrote a contract A that uses msg.sender for authentication: When A creates an item it stores msg.sender in itemsOwners mapping (itemOwners[itemId] = msg.sender;). Later A compares msg.sender to ...
0
votes
1answer
86 views

Issue with dynamic matrices in solidity

I have a matrix in solidity like that string x[][] I'm trying to write functions to return rows and colums The following code works well: // SPDX-License-Identifier: unlicensed pragma solidity ^0.6.0; ...
2
votes
0answers
41 views

Is gas cost of external calls included in gas cost of the main call?

When I call external methods of other contracts from my contract, is the gas fee of these calls included in the gas fee displayed by MetaMask? My transaction reverts (execution reverted) for an ...
0
votes
1answer
34 views

What is the cost of inter-contract calls?

I have a contract with methods to create items and add them to categories. I want to create a wrapper contract that would combine several calls into one: create an item and add it to several ...
1
vote
1answer
43 views

When a contract calls other contracts, is it an atomic operation?

If a contract calls several external methods of other contract(s), is it as a whole one atomic transaction (reverted as a whole if an exception happens)?
1
vote
1answer
197 views

Is Solidity being replaced as the de facto standard for smart contract development?

Is Solidity being replaced by languages such as Rust or other programming languages for smart contract development?
4
votes
1answer
226 views

How is Chainlink decentralized? [closed]

I believe one of the main criticisms of chainlink is that it is not decentralized enough, adding more nodes would be a big step in a positive direction. When I pull data through a node, that node ...
0
votes
1answer
32 views

When would one want to use a linked library?

My understanding is that if a smart contract consumes a library that only has internal functions, then the compiler will embed the library into the contract bytecode. At the lowest level, there is no ...
0
votes
1answer
56 views

how create address for each ethereum user [duplicate]

I have a group of Ethereum users how do I create an address for each user to send their data on the network?? I want a way to create addresses for each user??
0
votes
1answer
68 views

Deleting an array in storage (>= 0.6.0)

I need to add elements to a resizable myArray and then delete the myArray. I don't know what the length of myArray will be before the loop, and it's not possible to resize a memory array; that leaves ...
0
votes
1answer
22 views

When using mapping, why use an address over bytes32?

From an end user standpoint, they will never want to use the address for searching for mapped data when they could just submit a username for function parameters, so is there any specific reason why ...
0
votes
1answer
56 views

how different users write their data in ethereum network?

How a number of blockchain users save their data in the blockchain network using ethereum. Meaning more than one user sends his data using Python to save it in blockchain networl ?? How do I ...
0
votes
0answers
33 views

Compile error. Fallback function error

I use pragma 0.6.2. I am trying copile in truffle code which contain this lines: fallback() external payable{} I an getting error: The payable fallback function is defined here. fallback() external ...
0
votes
0answers
197 views

How do i withdraw Eth from a contract i created

New to blockchain.. havent a clue.. I managed to create a new contract with Eth. I moved money from MyEtherum Wallet to Metamask and into a contract, somehow? I have no coding experience but need ...
2
votes
1answer
36 views

Is the May 2017 contract creation attack still possible?

In May 2017, an "attacker" created a contract that attempts to create many other contracts(using many JUMPDEST operations in the creation bytecode) until it runs out of gas. I see the gas ...
0
votes
2answers
76 views

How do I give every user Ethereum an address and does it affect security

I have a project with Ethereum Blockchain the users send the data to the server and the server writes the data in the blockchain network My question is how do I represent the server in the smart ...
0
votes
1answer
81 views

Transfer money between contracts

I'm quite new at smart contracts/Solidity, which I'm learning for a postgraduate course. In one of the assignments, we have to implement a little competitive game (something like the game of Seven ...
0
votes
0answers
27 views

ERC-20 token with identitfication

I would like to create a generic ERC-20 token with identification. The token would only be transferred to previously identified addresses. The way identification is implemented should be as decoupled ...
0
votes
1answer
42 views

Should Try-Catch error handling be avoided for security? [closed]

What implications can it have to the security of a function if the content of it is wrapped into try-catch statements?
5
votes
2answers
145 views

Graph traversals on Ethereum, at scale

I read the Efficient Solidity storage pattern for a directional weighted graph thread, but that deals with storing graphs. I'm interested in techniques for how to traverse graphs in Solidity, at scale....
3
votes
1answer
247 views

SPDX license when importing other people's contracts

Since Solidity 0.6.8, the compiler started throwing warnings if a contract isn't annotated with a SPDX license identifier: // SPDX-License-Identifier: MIT contract MyContract { ... } Suppose ...

1 2 3
4
5
36