-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better ABI Validation: check type of constructor/call args against abi #278
Comments
The types of futures that accept arguments and need validation are:
For arguments, these are the types of inputs we need to be able to validate:
For raw primitives, we can let ethers do the heavy lifting for us with something like: const iface = new ethers.Interface(artifact.abi);
try {
iface.encodeDeploy([future.constructorArgs])
} catch {
throw new Error('failed validation')
} however, this approach would only work for primitive values, so I think primitives should instead just be accounted for within our custom loop that could look something like this (pseudocode): function validateArgs(artifact: Artifact, functionName: string, args: ArgumentType[]): IgnitionError[] {
// loop through, probably recursively, and resolve to primitive type strings
const argTypes = args.map((arg) => resolveTypeForArg(artifact, arg));
// get an array of primitive type strings representing the valid type for each arg, derived from the ABI and likely with help from ethers
const validTypes = resolveValidTypesForFunctionArgs(artifact, functionName);
// compare each argument against the valid type
let errors = [];
for (let i = 0; i < argTypes.length; i++) {
if (argTypes[i] !== validTypes[i]) {
errors.push(new IgnitionError("invalid arg type"));
}
}
return errors;
} |
@zoeyTM if I am following. During validation we add additional checks to args (either call or constructor) that recursively cross checks the types of the passed values with the ABI's type. Does ethers v6 give us any util functions to help with this? Do you think cross checking the types is extensive custom code? Or is leveraging either ethers/viem the way to go? |
Add to the general validation phase a check that each argument in the call/constructor args of the relevant futures matches the type expected by the abi.
TODO
The text was updated successfully, but these errors were encountered: