Skip to content

Instantly share code, notes, and snippets.

@blue-note
Forked from 0xekez/Gas Free CosmWasm.md
Created January 31, 2023 01:26
Show Gist options
  • Save blue-note/2a9c2344085e5b3fb10276db48d6f28d to your computer and use it in GitHub Desktop.
Save blue-note/2a9c2344085e5b3fb10276db48d6f28d to your computer and use it in GitHub Desktop.

Here is describe a simple system for interacting with CosmWasm contracts without paying gas. Instead of submitting transactions to a RPC node, addresses submit a signed ExecuteMsg to a third party and that party relays those messages to the appropriate smart contract. This third party may censor but not forge messages, and messages may be submitted as regular transactions to circumvent any censorship by the third party.

Specifically...

Messages have the format:

{
	"payload": {
		"nonce": u64,
		"msg": ExecuteMsg,
		"expiration": Option<Timestamp>,
	},
	"signature": Binary,
	"pk": secp256,
}

To accept one of these messages from a smart contract:

  1. Validate that the payload is validly signed, or error.
  2. Validate that the payload has the correct nonce, or error.
  3. Validate that the payload has not expired, or error.
  4. Set the message sender to the address corresponding to the provided public key.
  5. Call back into the contract's execute handler with this new sender and message.
// validate signature
let nonces: Map<String, u64> = Map::new("nonces");
let nonce = nonces.load(deps.storage, msg.pk)?;
deps.api.secp256k1_verify(msg.payload, msg.signature, msg.pk)?;
if msg.payload.nonce != nonce {
    return Err(NogasError::InvalidNonce)
}
if msg.payload.expiration.is_expired(&env.block) {
    return Err(NogasError::ExpiredPayload)
}
nonces.save(deps.storage, msg.pk, nonce + 1)?;

// call back into execute
info.sender = pk_to_addr(msg.pk)?;
execute(deps, info, env, msg.payload.msg)

This is permissionless in that any address may submit these signed messages.

Execution

image

Execution can happen in two ways:

  1. Benevolent DAO DAO user paying gas volunteers to batch some pending messages with their own.
  2. Centralized server picks up message and pushes it to the chain.

Some design goals for the server:

  1. Incredibly well instrumented.
  2. Easy to tune anti-spam knobs.

I contend that it is near impossible to predict and prevent all spam. We are best served by deploying a well instrumented piece of software, watching it run, and then adding rules where the data says they make sense.

Conclusion

This makes the onboarding steps for DAO DAO:

  1. Install keplr

Which I feel is in line with our goal of making the DAO in DAO DAO DAO quiet.

I suggest that we start with casting votes only. This lets us not worry about the potential liability of executing a proposal that does some dark web money laundering, and makes the most common DAO DAO action free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment