Skip to content

Instantly share code, notes, and snippets.

View cds-amal's full-sized avatar
🏠
Working from home

cds-amal cds-amal

🏠
Working from home
  • New York City
View GitHub Profile

Keybase proof

I hereby claim:

  • I am cds-amal on github.
  • I am cdsamal (https://keybase.io/cdsamal) on keybase.
  • I have a public key ASB-yxPVj2JE_nOQpOMzEYRgBe4bjhXgltCNRmuatrbB4go

To claim this, I am signing this object:

@cds-amal
cds-amal / rc_refcell_playground.rs
Created March 13, 2026 23:37
Rc<RefCell<T>> shared state in recursive traversal (stable-mir-json spy serializer MVP)
use std::cell::RefCell;
use std::rc::Rc;
/// A simple tree to walk (standing in for our nested serde types).
enum Node {
Leaf(i32),
Named { name: &'static str, children: Vec<Node> },
}
/// Shared mutable state: a context stack ("where am I?") and
package cmd
import (
"bufio"
"context"
"encoding/json"
"fmt"
"io"
"os"
"os/exec"
@cds-amal
cds-amal / .prettierrc.json
Created March 2, 2024 14:19
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.24+commit.e11b9ed9.js&optimize=false&runs=200&gist=
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false

Explain the solidity memory anotation

The memory keyword in Solidity is used to denote a temporary storage location within the Ethereum Virtual Machine (EVM) for variables that are not meant to persist between function calls. This is analogous to RAM in a computer, where data stored in memory is temporary and gets erased after the execution of the function it is used in. The EVM has three primary storage locations for data: storage, memory, and stack.

  • Storage: This is where all the contract's state variables reside. It is persistent across function calls and is more expensive to use due to the cost of writing to the blockchain.
  • Memory: This is used for temporary data. It is cheaper to use than storage because it is erased between function calls, making it suitable for intermediate calculations or temporary data structures.
  • Stack: This is used for small local variables and is almost free to use, but it has a limited capacity.

When you declare a variable with the memory keyword,

@cds-amal
cds-amal / Tvest.sol
Created October 19, 2023 14:55
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.21+commit.d9974bed.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;
contract Empty {
// hi, I'm bar. i was audited
function foo() public {}
function bar() public {}
}
/*
@cds-amal
cds-amal / .prettierrc.json
Created October 12, 2023 02:21
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.21+commit.d9974bed.js&optimize=false&runs=200&gist=
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
@cds-amal
cds-amal / String.yul
Created July 18, 2023 06:20
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
object "YulString" {
code {
// Deploy the contract
datacopy(0, dataoffset("runtime"), datasize("runtime"))
return(0, datasize("runtime"))
}
object "runtime" {
code {
// don't accept value
@cds-amal
cds-amal / Order.sol
Created July 8, 2023 15:47
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.20+commit.a1b79de6.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract A {
function foo() public pure returns (uint) { return bar(); }
function bar() public virtual pure returns (uint) { return 1; }
}
contract B is A { }