package
0.0.0-20231212030111-86af83068773
Repository: https://github.com/blastchain/blast.git
Documentation: pkg.go.dev

# README

ctb-go-ffi

A lightweight binary for utilities accessed via forge's ffi cheatcode in the contracts-bedrock test suite.

├── go-ffi
│   ├── bin: `go-ffi`'s binary
│   ├── trie: Utility for generating random merkle trie roots / inclusion proofs
│   └── diff-testing: Utility for differential testing Solidity implementations against their respective Go implementations.

Usage

To build, run pnpm build:go-ffi from this directory or the contract-bedrock package.

In a Forge Test

To use go-ffi in a forge test, simply invoke the binary via the vm.ffi cheatcode.

function myFFITest() public {
    string[] memory commands = new string[](3);
    commands[0] = "./scripts/go-ffi/go-ffi";
    commands[1] = "trie";
    commands[2] = "valid";
    bytes memory result = vm.ffi(commands);

    // Do something with the result of the command
}

Available Modes

There are two modes available in go-ffi: diff and trie. Each are present as a subcommand to the go-ffi binary, with their own set of variants.

diff

Note Variant required for diff mode.

VariantDescription
decodeVersionedNonceDecodes a versioned nonce and prints the decoded arguments
encodeCrossDomainMessageEncodes a cross domain message and prints the encoded message
hashCrossDomainMessageEncodes and hashes a cross domain message and prints the digest
hashDepositTransactionEncodes and hashes a deposit transaction and prints the digest
encodeDepositTransactionRLP encodes a deposit transaction
hashWithdrawalHashes a withdrawal message and prints the digest
hashOutputRootProofHashes an output root proof and prints the digest
getProveWithdrawalTransactionInputsGenerates the inputs for a getProveWithdrawalTransaction call to the OptimismPortal given a withdrawal message
cannonMemoryProofComputes a merkle proof of Cannon's memory

trie

Note Variant required for trie mode.

VariantDescription
validGenerate a test case with a valid proof of inclusion for the k/v pair in the trie.
extra_proof_elemsGenerate an invalid test case with an extra proof element attached to an otherwise valid proof of inclusion for the passed k/v.
corrupted_proofGenerate an invalid test case where the proof is malformed.
invalid_data_remainderGenerate an invalid test case where a random element of the proof has more bytes than the length designates within the RLP list encoding.
invalid_large_internal_hashGenerate an invalid test case where a long proof element is incorrect for the root.
invalid_internal_node_hashGenerate an invalid test case where a small proof element is incorrect for the root.
prefixed_valid_keyGenerate a valid test case with a key that has been given a random prefix
empty_keyGenerate a valid test case with a proof of inclusion for an empty key.
partial_proofGenerate an invalid test case with a partially correct proof

# Functions

No description provided by the author
Generate an abi-encoded `trieTestCase` of a specified variant.

# Variables

No description provided by the author