Skip to content

Instantly share code, notes, and snippets.

@axic
axic / ecverify.sol
Last active May 13, 2024 12:07
Ethereum ECVerify
//
// The new assembly support in Solidity makes writing helpers easy.
// Many have complained how complex it is to use `ecrecover`, especially in conjunction
// with the `eth_sign` RPC call. Here is a helper, which makes that a matter of a single call.
//
// Sample input parameters:
// (with v=0)
// "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad",
// "0xaca7da997ad177f040240cdccf6905b71ab16b74434388c3a72f34fd25d6439346b2bac274ff29b48b3ea6e2d04c1336eaceafda3c53ab483fc3ff12fac3ebf200",
// "0x0e5cb767cce09a7f3ca594df118aa519be5e2b5a"
@axic
axic / EVMASM.md
Last active May 11, 2024 03:13
EVM Assembly Language

EVM Assembly Language

Motivation

The goal is to specify a syntax for an EVM assembly language, which can be used across various tools.

The format should be human readable, map EVM as closely as possible, allow for comments and refrain from complex syntax.

Specification

@axic
axic / FRONTENDS.md
Last active July 1, 2023 09:03
LLVM Frontends

LLVM on the high level could be separated into:

    1. Core (operations which work on the LLVM IR AST)
    1. Optimisers
    1. Backends/targets - these generate the instructions for a given CPU (i.e. x86, ARM, WebAssembly, etc.)

There are many projects creating frontends for LLVM, which are actual compilers outputting LLVM IR.

Some of these include:

  • clang (C and C++)
  • llgo (Go)
/*
* STATICCALL Proxy
*
* It expects the input:
* 256 bit - address
* 256 bit - gas
* 256 bit - value
* n bit - calldata to be proxied
*
* And returns the output:
@axic
axic / standardaccount.sol
Last active June 19, 2022 20:26
EIP101 Standard Account code in Solidity
//
// Implementation of the standard account contract as per EIP101 (Cryptocurrency
// abstraction). See: https://github.com/ethereum/EIPs/issues/28
//
// Written by Alex Beregszaszi, use under the MIT license.
//
contract StandardAccount {
uint256 nextSequence = 1;
pragma solidity ^0.4.13;
library BytesTool {
function memcopy(bytes src, uint srcoffset, bytes dst, uint dstoffset, uint len) pure internal {
assembly {
src := add(src, add(32, srcoffset))
dst := add(dst, add(32, dstoffset))
// copy 32 bytes at once
for
@axic
axic / README.md
Last active December 15, 2021 03:14
ewasm “WRC20” token contract coding challenge

ewasm “WRC20” token contract coding challenge

This document describes a simple contract in pseudocode and gives a couple of test cases for it.

The challenge is designed to be fairly easy to implement in a language of choice, compiled to wasm and interacted with. It is loosely based on the ERC20 token standard, named "WRC20", where the W stands for WebAssembly.

External interface

The contract has two features:

@axic
axic / ReedemableNFT.sol
Created September 14, 2021 22:00
ReedemableNFT, where a curator can issue a redeemable cheque for minting a given token.
// ReedemableNFT, where a curator can issue a redeemable cheque for minting a given token.
//
// The message to be signed is an EIP-712 compatible structured data:
// struct RedeemableNFT {
// address recipient;
// uint256 tokenId;
// }
//
// This message can then signed by the curator and given to the user who submits it.
// The validity of the signature is checked according to EIP-1271 if the signer is a contract,
@axic
axic / BigInt.sol
Created May 9, 2016 18:29
Big number library in Solidity (for modexp)
//
// Big number library in Solidity for the purpose of implementing modexp.
//
// Should have a similar API to https://github.com/ethereum/EIPs/issues/101
//
// Internally bignumbers are represented as an uint array of 128 bit values.
//
// NOTE: it assumes usage with "small" (<256bit) exponents (such as in RSA)
//
@axic
axic / Create2Proxy.sol
Created February 28, 2019 22:37
CREATE2 proxy for constantinople/petersburg
// CREATE2 proxy for constantinople/petersburg which allows easy deploying of
// contracts using the same address on multiple chains.
//
// Idea by @Arachnid. Some code by @axic.
pragma solidity ^0.5.0;
contract Create2Proxy {
function() external payable {
assembly {