Skip to content
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

Confirm if State must be in contract class #3540

Open
gldeng opened this issue Apr 18, 2024 · 0 comments
Open

Confirm if State must be in contract class #3540

gldeng opened this issue Apr 18, 2024 · 0 comments

Comments

@gldeng
Copy link
Contributor

gldeng commented Apr 18, 2024

If we want to explore modular contract, we require states to be accessed in other classes which can be used to compose the final contracts.

But we have rule to require state to be only accessible from the contract class. We may need to disable it temporarily so that we can test out our modular contract ideas.

    private List<ValidationResult> ValidateMethod(ModuleDefinition moduleDefinition, MethodDefinition methodDefinition)
    {
        if (!methodDefinition.HasBody)
            return new List<ValidationResult>();
        var isNotContractImplementation = !methodDefinition.DeclaringType.IsContractImplementation();

        var result = new List<ValidationResult>();
        foreach (var instruction in methodDefinition.Body.Instructions.Where(instruction =>
                     _instructionInjector.IdentifyInstruction(instruction)).ToList())
        {
            // TODO: https://github.com/AElfProject/AElf/issues/3387
            if (isNotContractImplementation)
            {
                result.Add(new MethodCallInjectionValidationResult(
                    $"{_instructionInjector.GetType()} validation failed. Updating state in non-contract class is not allowed."
                ).WithInfo(
                    methodDefinition.Name,
                    methodDefinition.DeclaringType.Namespace,
                    methodDefinition.DeclaringType.FullName,
                    null
                ));
            }
            else if (!_instructionInjector.ValidateInstruction(moduleDefinition, instruction))
            {
                result.Add(new MethodCallInjectionValidationResult(
                    $"{_instructionInjector.GetType()} validation failed.").WithInfo(methodDefinition.Name,
                    methodDefinition.DeclaringType.Namespace, methodDefinition.DeclaringType.FullName, null));
            }
        }

        return result;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant