Library for creating corrupted calldata.

Overview

Scuffed ABI

Package for modifying ABI encoded data. Mostly useful for testing failure cases of ABI decoders.

Given an ethers Contract object, you can build a scuffed contract using the function getScuffedContract.

This will return an object whose keys are the contract's function and which take the same input parameters as their associated functions.

Calling one of these functions will return an object mirroring the structure of the input parameters, with a ReplaceableOffsets object for each value's head, tail or length, as well as parameters for all nested values. See types for more information on data types.

The ReplaceableOffsets type has a function replace which allows you to replace a value after it's been encoded.

Example

Suppose we have the function:

struct SignedTransfer {
  address to;
  uint256 value;
  bytes signature;
}

function validateSignatures(SignedTransfer[] calldata transfers) external;

Then we can use scuffed abi like so:

const scuffed = getScuffedContract(contract);
const scuffedFnCall = scuffed.validateSignatures([{
  to: wallet.address,
  value: 1000,
  signature: sign(defaultAbiCoder.encode(['address', 'bytes'], [wallet.address, 1000]))
}]);
// Modify the offset to the `transfers` array
scuffedFnCall.transfers.head.replace(0x20)
// Modify the length of the signature in the first transfer
scuffedFnCall.transfers[0].signature.length.replace(0x40)
// Modify the offset to the first transfer
scuffedFnCall.transfers[0].head.replace(0)
// Modify `value`
scuffedFnCall.transfers[0].value.replace(500)
// Encode the function calldata
const data = scuffedFnCall.encode()

Types

type ReplaceableOffsets = {
  relative: number;   // position of the parameter relative to its parent
  absolute: number;   // absolute position of the parameter in the encoded args
  replace: (value: BigNumberish) => string; // replace the value in the encoded args
}

Dynamic values will have:

type DynamicOffsets = {
  head: ReplaceableOffsets;
  tail: ReplaceableOffsets;
}

Arrays and bytes parameters will have an additional length: ReplaceableOffsets field.

Static parameters will simply have the ReplaceableOffsets type without a head or tail.

Example

In the example code above, the scuffedFnCall will be structured as:

{
  encode: () => string // Encode the function call with all updated parameters
  encodeArgs: () => string // Encode the input parameters without the selector
  execute: () => Promise<Transaction> // Execute the transaction with the updated parameters
  call: () => Promise<string> // Call the function with the updated parameters
  transfers: {
    length: ReplaceableOffsets
    head: ReplaceableOffsets
    tail: ReplaceableOffsets
    '0': {
      head: ReplaceableOffsets
      tail: ReplaceableOffsets

      to: ReplaceableOffsets
      value: ReplaceableOffsets

      signature: {
        length: ReplaceableOffsets
        head: ReplaceableOffsets
        tail: ReplaceableOffsets
      }
    }
  }
}
You might also like...

📣 A vanilla js library for creating alerts, prompts and confirms.

attention.js This library will be released soon as 1.0 with a whole new codebase! Stay tuned! A vanilla js library for creating alerts, prompts, and c

Apr 21, 2022

A JavaScript library for creating "select-all" checkboxes

SelectAllCheckbox v1.0 See LICENSE for this software's licensing terms. SelectAllCheckbox is a JavaScript library which makes it easy to create "selec

Jul 27, 2021

A lightweight JavaScript library for creating interactive maps and pretty data visualization.

A lightweight JavaScript library for creating interactive maps and pretty data visualization.

Jsvectormap A lightweight Javascript library for creating interactive maps and pretty data visualization. Explore docs . Report bug · View demo · Down

Dec 24, 2022

A simple, lightweight, clean and small library for creating guided product tours for your web app.

A simple, lightweight, clean and small library for creating guided product tours for your web app.

Tourguide.js Simple, lightweight library for creating guided tours for your web, apps and more. A tour guide is a person who provides assistance, info

Dec 12, 2022

Flexible, powerful and modern library for creating the running horizontal blocks effect, also known as ticker or the «marquee effect».

Flexible, powerful and modern library for creating the running horizontal blocks effect, also known as ticker or the «marquee effect».

Cuberto Reeller Flexible, powerful and modern library for creating the running horizontal blocks effect, also known as ticker or the «marquee effect».

Jan 4, 2023

Flexible JavaScript library for creating squircley magic ✨

Flexible JavaScript library for creating squircley magic ✨

squircley.js squircley.js is the core squirclular magic ✨ from https://squircley.app wrapped up into a simple, 0 dependency JavaScript library. squirc

Dec 24, 2022

A dependency-free JavaScript library for creating discreet pop-up notifications.

Polipop A dependency-free JavaScript library for creating discreet pop-up notifications. Demo See demo at minitek.github.io/polipop/. Documentation Se

Aug 15, 2022

A simple easy to use vanilla JavaScript library for creating input fields that accept multiple email addresses

MeiMei - Multiple Email Input MeiMei: A simple easy to use vanilla JavaScript library for creating input fields that accept multiple email addresses.

Apr 13, 2022

A small library for creating typing animations.

A small library for creating typing animations. View a short video demonstration here. Installation npm i tiper-js Usage Initialization is really simp

Nov 5, 2022
Owner
Dillon Kellar
I like to make stuff with Ethereum. Currently building @indexed-finance
Dillon Kellar
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
JavaScript library for creating dynamic content

Gruu Gruu is a small and powerful JavaScript library for creating dynamic content. Using only JavaScript you can create user interfaces that change dy

Marek Łabuz 7 Jun 25, 2021
Atomico a micro-library for creating webcomponents using only functions, hooks and virtual-dom.

Atomico simplifies learning, workflow and maintenance when creating webcomponents. Scalable and reusable interfaces: with Atomico the code is simpler

Atomico 898 Dec 31, 2022
The PatternFly Design Kit is a Sketch library used for creating PatternFly accurate design mockups

PatternFly Design Kit The PatternFly Design Kit is a collection of Sketch assets that make it easy for designers to create high-fidelity design mockup

PatternFly 44 Jan 2, 2023
An open-source library to help with creating expandable text

?? Telescopic Text An open-source library to help with creating expandable text. Inspired by StretchText and TelescopicText. I've been thinking a lot

Jacky Zhao 69 Dec 30, 2022
Node.js library for creating bots and sending/receiving messages using the Whatsapp Cloud API

whatsapp-cloud-api whatsapp-cloud-api is a Node.js library for creating bots and sending/receiving messages using the Whatsapp Cloud API. Contains bui

Tony 81 Jan 2, 2023
A TypeScript library for creating dependency snapshots.

Dependency Submission Toolkit @github/dependency-submission-toolkit is a TypeScript library for creating dependency snapshots and submitting them to t

GitHub 19 Nov 22, 2022
PxLoader is a simple JavasScript library for creating preloaders and resource downloaders for HTML5 apps.

PxLoader is a Javascript library that helps you download images, sound files or anything else you need before you take a specific action on your site

Pixel Lab 1.1k Dec 30, 2022
We are creating a Library that would ensure developers do not reinvent the wheel anymore as far as Authentication is concerned. Developers can easily register and download authentication codes that suits their need at any point.

#AuthWiki Resource Product Documentation Figma Database Schema First Presentation Live Link API Documentation Individual Contributions User Activity U

Zuri Training 17 Dec 2, 2022