Skip to content

Instantly share code, notes, and snippets.

chriseth

Block or report user

Report or block chriseth

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@chriseth
chriseth / gist:c95c20393e0dd1063d4366983b4bc4c9
Created May 29, 2019
Solidity to EWasm code generation
View gist:c95c20393e0dd1063d4366983b4bc4c9
Solidity code:
contract c {
function f(uint x) internal returns (uint) {
while (x > 0)
return 2 * f(x - 1);
}
}
Yul IR:
View ERC20.yul
/*******************************************************
* WARNING *
* Solidity to Yul compilation is still EXPERIMENTAL *
* It can result in LOSS OF FUNDS or worse *
* !USE AT YOUR OWN RISK! *
*******************************************************/
object "ERC20_396" {
code {
{
@chriseth
chriseth / input.sol
Created Apr 17, 2019
Sol to Yul compiler
View input.sol
contract C {
function f() public pure returns (uint x) { x = 7; }
}
View create.sol
uint salt = 0x123;
bool success;
// order matters!
bytes memory p = abi.encode(param1, ..., paramn);
bytes memory c = type(C).creationCode;
assembly {
function memCopyPadded(from, to, length) {
for { let i := 0 } lt(i, length) { i := add(i, 0x20) } {
mstore(to, mload(from))
to := add(to, 0x20)
@chriseth
chriseth / Automated Source Code Repository.md
Last active Apr 2, 2019
Automated Source Code Repository
View Automated Source Code Repository.md

To increase decentralization, it would be great to have a verified repository of smart contract source codes. Due to the metadata being part of the bytecode, we should have everything that is needed to actually perform the verification. This repository could be an actual repository on github, where people can create pull requests to have their smart contract code compiled and verified. There could be a CI job that does the verification as follows:

  • fetch the bytecode from the chain via infura or another service
  • install the correct compiler version using npm
  • only flag the PR green, if the compilation output matches the bytecode

If the directory name is the address of the contract, the source code should be easy to find, even if multiple

@chriseth
chriseth / example.yul
Created Dec 20, 2018
Example YUL contract
View example.yul
// Compile the following using ``solc --strict-assembly example.yul``
object "MyContract" {
code {
// this is the constructor.
// store the creator in the first storage slot
sstore(0, caller())
// now return the runtime code using the special functions
datacopy(0, dataoffset("Runtime"), datasize("Runtime"))
return(0, datasize("Runtime"))
}
View EasterHegg Smart Contract Workshop.md

EasterHegg 18 Workshop: Smart Contracts on Ethereum

Requirements:

Coding your first smart contract!

a. Setting up Metamask

@chriseth
chriseth / docdiff.patch
Created Feb 20, 2018
Differences in Solidity documentation between 26ea9ce07cf85849cd881465a4322f14bff87eb8 and a6b52fdc34650c74597c1bcdc5075b6375c62650
View docdiff.patch
diff --git a/docs/abi-spec.rst b/docs/abi-spec.rst
index e39c8861..8095a3b7 100644
--- a/docs/abi-spec.rst
+++ b/docs/abi-spec.rst
@@ -6,17 +6,19 @@
Application Binary Interface Specification
******************************************
-Basic design
+Basic Design
@chriseth
chriseth / MyToken.solidity
Created Dec 19, 2017
MyToken - IULIA example
View MyToken.solidity
contract MyToken {
function MyToken() {
assembly {
// Store the creator at storage slot zero
sstore(0, caller())
}
}
function () payable {
assembly {
// Protection against sending Ether
View Answers.md

Answers to Deep Questions about Solidity

The following list of questions was taken from https://www.reddit.com/r/ethereum/comments/72reba/do_you_have_deep_questions_about_solidity_or_the/

An updated summary on the different ways one could have two contracts interact (DELEGATECALL, STATICCALL, libraries, all that stuff) with clear pros/cons for each (gas cost, whether it requires EVM assembly directives, etc)

Question by /u/drcode

I won't talk about low-level opcodes here because of the brevity of the answer. In general, there are four ways functions can be called in Solidity:

You can’t perform that action at this time.