Skip to content

Instantly share code, notes, and snippets.

View CJ42's full-sized avatar

Jean Cvllr CJ42

View GitHub Profile
@CJ42
CJ42 / TimeWatchValid.sol
Last active July 18, 2022 19:00
valid storage pointer
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "./Timers.sol";
contract TimeWatch {
Timers.Timestamp timer;
function startTimer(uint64 _deadline) public {
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "./Timers.sol";
contract RaceTournament {
mapping(address => Timers.Timestamp) racers;
function startRacerTimer(address _racer, uint64 _deadline) public {
@CJ42
CJ42 / ExamplesSchemas.md
Last active July 19, 2022 18:11
Examples of ERC725Y JSON Schemas to describe ERC725Y data keys for LUKSO Buidl Hackathon workshop

Examples of ERC725Y JSON Schemas to describe ERC725Y data keys for LUKSO Buidl Hackathon workshop

{
    "name": "MyProfile",
    "key": "0xd7a3703d6cb893710a4b495319d35de0b7efc070bc705c285266f6c06725ccf2",
    "keyType": "Singleton",
    "valueType": "string",
    "valueContent": "URL"
},
@CJ42
CJ42 / mVoting.sol
Last active July 21, 2022 07:19
explaining that elementary type copy and storage references do not in Solidity
pragma solidity ^0.8.0;
contract Voting {
uint256 votesCount;
struct Vote {
bool hasVoted;
string vote;
}
@CJ42
CJ42 / TestingMsize.sol
Last active August 31, 2022 21:07
Solidity code snippet to better explain the difference between the MSIZE opcode vs the free memory pointer
pragma solidity ^0.8.0;
contract TestingMsize {
function test()
public
pure
returns (
uint256 freeMemBefore,
uint256 freeMemAfter,
@CJ42
CJ42 / MemoryBetweenCalls.sol
Last active July 26, 2022 17:37
Run this example in Remix + debug it to show that memory is erased between function calls
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Source {
Target target;
constructor(Target _target) {
target = _target;
}
@CJ42
CJ42 / ExternalCall.asm
Created July 26, 2022 18:24
Show the changes of execution context by the EVM when calling external contract (Fresh instance of Memory obtained)
; ...
057 SLOAD ; load the value for `target` state variable from storage
; ...
; more stack manipulation
; ...
; ...
; ...
; ...
; ...
; ...
@CJ42
CJ42 / reduce-truffle-artifacts.js
Last active August 18, 2022 07:00
The contract JSON ABIs generated by Truffle contain sensitive and private informations: the File system path of the developer’s computer/machine. This scripts remove these sensitive entries and reduces by quite few MB the size of the contracts JSON ABIs in the process. (original source: https://github.com/ERC725Alliance/ERC725/pull/71/commits/1b…
/**
* This script removes source + AST entries inside the JSON artifacts generated by `truffle conpile`
* It will make artifacts files smaller in size (truffle generated ABI files usually
* contain around 5,000 to 20,000 lines).
*
* It is useful when deploying to a package registry like npm, as it helps to:
* - optimize package size
* - generate safer to use artifacts, as some artifact files contain sensitive informations
* (they key "sourcePath" in the artifacts generated by truffle contains the File system path
* of the user that compiled the contracts via `truffle compile` command)
@CJ42
CJ42 / AllAboutCalldata.sol
Created September 6, 2022 16:25
Solidity example to show that calldata is read-only and cannot be modified.
pragma solidity ^0.8.0;
contract AllAboutCalldata {
function manipulateMemory(string memory input) public pure returns (string memory) {
// you CAN modify arguments passed with data location 'memory'
// you can add data in the string
input = string.concat(input, " - All About Solidity");
@CJ42
CJ42 / jsonurl.js
Created September 19, 2022 15:01
Hardhat task to create a LSP2 valueType of JSONURL
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
const SampleProfile = require("./SampleProfile.json");
async function main() {
// Hardhat always runs the compile task when running scripts with its command