Questions tagged [contract-design]
for high-level questions about the choices made during contract construction
1,722
questions
0
votes
1answer
17 views
solidity - allowance delegation - what if the owner spent it already
So userA delegates his tokens to be spent by me to whoever I want. That's great.
let's say userA's balance was 200Token. and he delegated 150 Token to me..
Now, userA can still transfer 180Token to ...
0
votes
1answer
37 views
allowance - why not directly transfering?
I have a couple of questions relating ERC20...
why is allowance needed ? It would be the same as if instead of approving my 10 tokens to some address to spend, I could directly transfer 10 tokens to ...
0
votes
1answer
14 views
Will the parameters in the smart contract function be exposed?
A function in the smart contract needs to accept parameters to execute. If I pass this parameter to the contract, but don’t save the parameter on the chain, is it theoretically transparent on the ...
0
votes
2answers
53 views
Payable and address.transfer for ERC20 token
I am trying to develop forsage like MLM using ethereum smart contract. But I like to use ERC20 token for registration payment and dividends. The ERC20 token is already deployed. I have to use deployed ...
0
votes
0answers
16 views
Mint ERC-1155 Token with user defined variables
I would like to allow users to change the property of their items. Let it be the color.
In my understanding though there is no way of changing the property of an already minted erc-1155 token. ...
1
vote
0answers
20 views
Fine graininess of interface collisions between protocols
While working on integrating the Balancer Exchange protocol in my project, I noticed this interface defined in their exchange proxy:
interface TokenInterface {
function balanceOf(address) external ...
0
votes
1answer
49 views
How does a smart contract hold funds without holding private keys?
I understand that smart contracts:
Don't have private keys
They can hold, receive and spend ether
How does the latter work ? Let's say I want to send 1 eth to a smart contract and leave it locked up ...
2
votes
1answer
542 views
What is DSProxy and how does it work?
Several Ethereum projects use DSProxy to make their protocols more user-friendly. What is DSProxy exactly and how does it work?
1
vote
1answer
46 views
Are newer solidity versions 'safer'? Should I update my existing code to use a newer version?
I have created a set of contracts that will shortly be undergoing an audit. It's a DeFi platform that is intended to hold real value.
The project began as a fork of a fairly old project, that uses ...
0
votes
1answer
27 views
Fungible tokens owned by non-fungible tokens
I'm quite a Noob when it comes to smart contracts, and I'm trying to design a market place.
I will tokenise existing real world assets into ERC 721 tokens. The owner of each ERC721 will be eligible to ...
0
votes
1answer
13 views
Trying to do interaction between 2 contracts. But compilation failure showing should be declared Abstract
WinCon.sol
EnemyCon.sol
To create interaction, I am creating interface for EnemyCon in WinCon.sol, but Remix is throwing compilation error stating "EnemyCon should be marked abstract". I ...
0
votes
0answers
17 views
How to handle refer by register functionality in Dapp with Smart Contract? [duplicate]
I've just started to learn solidity programming..Firstly, I have a register page, in which the metamask opens up an popup and connect the user address to my dapp by registering the user on their ...
1
vote
1answer
180 views
How to register USER in my Smart Contract using Solidity?
I can't figure out how do we register user in smart contract and get the userdata when he/she tries to login after register through our website..I didn't see any article regarding this..Kindly ...
0
votes
1answer
25 views
An attack to my contract similar to ERC-20 approval() exploit
I have
function setNonRecurringFlow(uint256 _child, int256 _remainingSwapCredit) external;
function setRecurringFlow(
uint256 _child,
int256 _maxSwapCredit,
int256 ...
0
votes
1answer
37 views
How to implement owner check in Solidity
Is there any EIP that specifies how to implement function in contract, that let's you call any other function as contract owner, with provided signature?
I don't want to reinvent wheel.
For example:
I ...
2
votes
2answers
132 views
ETH - Pre-Paid smart contract so users don't pay transactions
I'm developing a "corporate" DApp, therefore the employees don't have any reason to "spend" their ether/gas for interacting with the contract...
Is there any way to enable each ...
2
votes
1answer
32 views
the same struct in array and mappings
Let's say I have a struct.
struct test {
uint x;
}
test[] all;
mappings(uint => test) map;
function bla(){
test memory structTest = test(5);
all.push(structTest);
map[10] = structTest;
...
1
vote
1answer
27 views
how to transfer from contract to another account or contract
I have a function:
function sendEther(address payable _to, uint amount) public payable returns (bool) {
bool success = _to.send(amount);
return success;
}
Now, how transferring ...
0
votes
0answers
15 views
solidity call function how gas gets forwarded
It's said that:
someAddress.call.value(y)() will send the provided ether and trigger
code execution. The executed code is given all available gas for
execution making this type of value transfer ...
0
votes
1answer
41 views
how do i pass by reference?
I have a couple of questions.
First:
So, In a function, i created memory array. I want to pass this memory by reference to another function..
function test2() public returns(uint a) {
uint[2] ...
1
vote
0answers
40 views
copy array from storage to memory
uint[2] testStorage;
function assemblyStorage() public returns (uint a, uint b){
testStorage[0] = 5;
testStorage[1] = 10;
uint[2] memory testMemory = testStorage;
...
0
votes
1answer
32 views
Is calling another contract via its address risky?
The below screenshot is from Andreas' book. I don't understand why this programming technique is so risky. See the text in the red block in the image.
We have the .sol file, and the Bytecode on the ...
0
votes
1answer
39 views
why does this contract ask to increase gas limit?
string test;
function assemblyStorage() public payable returns (string memory a){
test = "good";
assembly {
a:=sload(0)
}
}
I am trying to return the string ...
1
vote
0answers
19 views
why do i have to specify memory in arguments?
My function body looks like this:
function element(uint a, uint b, uint[2] memory c) public returns(uint e, uint f, uint g, uint k) {
I am wondering why do I put memory keyword before c ? I know that ...
1
vote
0answers
19 views
why mload(0) returns wrong number?
int x; // Storage slot #0
mapping (uint => uint) y; // Storage slot #1
uint [] z; // Storage slot #2
function element() public returns (uint a, uint b, uint c) {
z.push(45);...
1
vote
0answers
50 views
how do storage and memory variable work?
So, in an ordinary programming language, we have stack and heap.
Reference types such as array gets stored in heap. and the variable which holds the address(pointer) of this array is stored in stack..
...
2
votes
1answer
29 views
where does function variables get created?
function element() public returns (uint) {
uint test = 20;
return test;
}
Where would test variable be created ? in memory or stack ?
The funny thing is from testing assembly, I can see that it'...
1
vote
1answer
44 views
sload. assembly with struct - not working in solidity
struct S {
uint128 a;
uint128 b;
}
S test1;
function assemblyStorage() public returns (uint a, uint b, uint c, uint d, uint f, uint g){
test1 = S(5,10);
assembly {
a:=sload(0)
}
}
...
1
vote
1answer
28 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
27 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
147 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
47 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
66 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
30 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
75 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
26 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
20 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
57 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
183 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
29 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
24 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
22 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
18 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
28 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
93 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
21 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
32 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
29 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 ...