Gas Optimization Tips
Minimize on-chain dataUse librariesUse ERC1167Turn on the Solidity optimizerUse eventsUse literal instead of computed valuesAvoid to copy arrays in memoryAvoid for-loop over dynamic rangesOptimize order of variable declarationUse eth-gas-reporter
EIP-712: Quick Intro and Use case
https://eips.ethereum.org/EIPS/eip-712 Abstract This is a standard for hashing and signing of typed structured data as opposed to just bytestrings. It includes a theoretical framework for correctness of encoding functions, specification of structured data similar to and compatible with Solidity structs, safe hashing algorithm for instances of those structures, safe inclusion of those instances in the set of signable messages, an extensible mechanism for domain separation, new RPC call eth_sig...
How Tornado Cash works
Tornado Cash is a coin mixer that you can use to anonymize your Ethereum transactions. Because of the logic of the blockchain, every transaction is public. If you have some ETH on your account, you cannot transfer it anonymously, because anybody can follow your transaction history on the blockchain. Coin mixers, like Tornado Cash, can solve this privacy problem by breaking the on-chain link between the source and the destination address by using ZKP.Deposit:Users deposit the same amount of ET...
Blockchain Developer
Gas Optimization Tips
Minimize on-chain dataUse librariesUse ERC1167Turn on the Solidity optimizerUse eventsUse literal instead of computed valuesAvoid to copy arrays in memoryAvoid for-loop over dynamic rangesOptimize order of variable declarationUse eth-gas-reporter
EIP-712: Quick Intro and Use case
https://eips.ethereum.org/EIPS/eip-712 Abstract This is a standard for hashing and signing of typed structured data as opposed to just bytestrings. It includes a theoretical framework for correctness of encoding functions, specification of structured data similar to and compatible with Solidity structs, safe hashing algorithm for instances of those structures, safe inclusion of those instances in the set of signable messages, an extensible mechanism for domain separation, new RPC call eth_sig...
How Tornado Cash works
Tornado Cash is a coin mixer that you can use to anonymize your Ethereum transactions. Because of the logic of the blockchain, every transaction is public. If you have some ETH on your account, you cannot transfer it anonymously, because anybody can follow your transaction history on the blockchain. Coin mixers, like Tornado Cash, can solve this privacy problem by breaking the on-chain link between the source and the destination address by using ZKP.Deposit:Users deposit the same amount of ET...
Share Dialog
Share Dialog
Blockchain Developer

Subscribe to Hicss

Subscribe to Hicss
<100 subscribers
<100 subscribers
1.
If we know the size of the bytes we want to store, the best approach is to use the fixed size byte array type
To initialize a fixed size byte array, we need to specify the size of how many bytes we would like to store.
bytes1 b1 = hex"41";
Bytes can be initialized with either a hex string hex"41" or a hex value 0X41 which is the letter A according to ASCII.
2.
Fixed size bytes can be passed between smart contracts in the Solidity programming language.
3.bytes and bytes32
Bytes is a dynamic array of bytes. It's shorthand for byte[] and you'll see examples of a bytes being treated as an array in code from time to time. myByte[x]. It can have a length of zero and you can do things like append a byte to the end.
Bytes32 is exactly 32 bytes long. It takes exactly one 32-byte word to represent a bytes32 because there's no need to set any space aside to encode the length. The length is always 32. A bytes with 32 bytes of data needs additional encoding to deal with variable length.
4.Converting to bytes
Converting a string to bytes is a straightforward task. We need to initialize bytes passing in the string type. In return, we get a dynamic array of bytes.
bytes memory stringBytes = bytes("This is string");
If we want to convert to the bytes32 type, we need to go to the assembly level and write the string on the memory.
bytes32 result;
assembly {
result := mload(add("This is string", 32))
}
Keep in mind that we can write only up to 32 bytes.
5.Converting from bytes
In Solidity language, we can convert back the string value to a dynamic size array of bytes. We can’t convert to fixed string bytes because the string type has an unknown size.
bytes memory bytesData = hex"41";
string memory stringData = string(bytesData);
1.
If we know the size of the bytes we want to store, the best approach is to use the fixed size byte array type
To initialize a fixed size byte array, we need to specify the size of how many bytes we would like to store.
bytes1 b1 = hex"41";
Bytes can be initialized with either a hex string hex"41" or a hex value 0X41 which is the letter A according to ASCII.
2.
Fixed size bytes can be passed between smart contracts in the Solidity programming language.
3.bytes and bytes32
Bytes is a dynamic array of bytes. It's shorthand for byte[] and you'll see examples of a bytes being treated as an array in code from time to time. myByte[x]. It can have a length of zero and you can do things like append a byte to the end.
Bytes32 is exactly 32 bytes long. It takes exactly one 32-byte word to represent a bytes32 because there's no need to set any space aside to encode the length. The length is always 32. A bytes with 32 bytes of data needs additional encoding to deal with variable length.
4.Converting to bytes
Converting a string to bytes is a straightforward task. We need to initialize bytes passing in the string type. In return, we get a dynamic array of bytes.
bytes memory stringBytes = bytes("This is string");
If we want to convert to the bytes32 type, we need to go to the assembly level and write the string on the memory.
bytes32 result;
assembly {
result := mload(add("This is string", 32))
}
Keep in mind that we can write only up to 32 bytes.
5.Converting from bytes
In Solidity language, we can convert back the string value to a dynamic size array of bytes. We can’t convert to fixed string bytes because the string type has an unknown size.
bytes memory bytesData = hex"41";
string memory stringData = string(bytesData);
No activity yet