mirror of
https://github.com/corda/corda.git
synced 2025-04-07 19:34:41 +00:00
Move the sandbox code to net.corda
This commit is contained in:
parent
2f02e56893
commit
674e345ba2
@ -11,7 +11,7 @@ This code was written by Ben Evans.
|
||||
|
||||
# Roadmap
|
||||
|
||||
* Thorough code and security review.
|
||||
* Thorough testing, code and security review.
|
||||
* Possibly, a conversion to Kotlin.
|
||||
* Make the instrumentation ahead of time only.
|
||||
* Finalise the chosen subset of the Java platform to expose to contract code.
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.r3cev;
|
||||
package net.corda.sandbox;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -8,7 +8,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static com.r3cev.CandidateMethod.State.*;
|
||||
import static net.corda.sandbox.CandidateMethod.State.*;
|
||||
|
||||
/**
|
||||
* Represents the status of the candidacy of a particular set of candidate methods, i.e. Their progress from
|
||||
@ -172,7 +172,7 @@ public class CandidacyStatus {
|
||||
final Set<String> out = new HashSet<>();
|
||||
for (final String candidateName : candidateMethods.keySet()) {
|
||||
final CandidateMethod candidate = candidateMethods.get(candidateName);
|
||||
if (candidate.getCurrentState() == DISALLOWED) {
|
||||
if (candidate.getCurrentState() == CandidateMethod.State.DISALLOWED) {
|
||||
out.add(candidateName);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.r3cev;
|
||||
package net.corda.sandbox;
|
||||
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.util.HashSet;
|
@ -1,6 +1,6 @@
|
||||
package com.r3cev;
|
||||
package net.corda.sandbox;
|
||||
|
||||
import static com.r3cev.Utils.*;
|
||||
import static net.corda.sandbox.Utils.*;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.r3cev;
|
||||
package net.corda.sandbox;
|
||||
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.r3cev;
|
||||
package net.corda.sandbox;
|
||||
|
||||
import com.r3cev.visitors.CostInstrumentingMethodVisitor;
|
||||
import net.corda.sandbox.visitors.CostInstrumentingMethodVisitor;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
@ -1,7 +1,7 @@
|
||||
package com.r3cev;
|
||||
package net.corda.sandbox;
|
||||
|
||||
import com.r3cev.visitors.CostInstrumentingMethodVisitor;
|
||||
import com.r3cev.visitors.WhitelistCheckingClassVisitor;
|
||||
import net.corda.sandbox.visitors.CostInstrumentingMethodVisitor;
|
||||
import net.corda.sandbox.visitors.WhitelistCheckingClassVisitor;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
@ -1,4 +1,4 @@
|
||||
package com.r3cev;
|
||||
package net.corda.sandbox;
|
||||
|
||||
/**
|
||||
*
|
@ -1,4 +1,4 @@
|
||||
package com.r3cev.costing;
|
||||
package net.corda.sandbox.costing;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
@ -1,4 +1,4 @@
|
||||
package com.r3cev.costing;
|
||||
package net.corda.sandbox.costing;
|
||||
|
||||
/**
|
||||
* This interface is to decouple the actual executable code from the entry point and
|
@ -1,4 +1,4 @@
|
||||
package com.r3cev.costing;
|
||||
package net.corda.sandbox.costing;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
@ -1,13 +1,15 @@
|
||||
package com.r3cev.tools;
|
||||
package net.corda.sandbox.tools;
|
||||
|
||||
import com.r3cev.WhitelistClassLoader;
|
||||
import com.r3cev.visitors.SandboxPathVisitor;
|
||||
import net.corda.sandbox.WhitelistClassLoader;
|
||||
import net.corda.sandbox.visitors.SandboxPathVisitor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import net.corda.sandbox.visitors.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import joptsimple.OptionParser;
|
@ -1,6 +1,6 @@
|
||||
package com.r3cev.visitors;
|
||||
package net.corda.sandbox.visitors;
|
||||
|
||||
import com.r3cev.Utils;
|
||||
import net.corda.sandbox.Utils;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
@ -28,7 +28,7 @@ public final class CostInstrumentingMethodVisitor extends GeneratorAdapter {
|
||||
public CostInstrumentingMethodVisitor(MethodVisitor methodVisitor, int access, String name, String desc) {
|
||||
super(Opcodes.ASM5, methodVisitor, access, name, desc);
|
||||
|
||||
runtimeAccounterTypeName = "com/r3cev/costing/RuntimeCostAccounter";
|
||||
runtimeAccounterTypeName = "net/corda/sandbox/costing/RuntimeCostAccounter";
|
||||
// save other calling parameters as well...?
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.r3cev.visitors;
|
||||
package net.corda.sandbox.visitors;
|
||||
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
@ -1,7 +1,7 @@
|
||||
package com.r3cev.visitors;
|
||||
package net.corda.sandbox.visitors;
|
||||
|
||||
import com.r3cev.Utils;
|
||||
import com.r3cev.WhitelistClassLoader;
|
||||
import net.corda.sandbox.Utils;
|
||||
import net.corda.sandbox.WhitelistClassLoader;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import org.slf4j.Logger;
|
@ -1,19 +1,21 @@
|
||||
package com.r3cev.visitors;
|
||||
package net.corda.sandbox.visitors;
|
||||
|
||||
import com.r3cev.WhitelistClassLoader;
|
||||
import com.r3cev.CandidacyStatus;
|
||||
import net.corda.sandbox.WhitelistClassLoader;
|
||||
import net.corda.sandbox.CandidacyStatus;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.r3cev.CandidateMethod;
|
||||
import com.r3cev.Utils;
|
||||
import net.corda.sandbox.CandidateMethod;
|
||||
import net.corda.sandbox.Utils;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.corda.sandbox.*;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import static com.r3cev.CandidateMethod.State.*;
|
||||
import static net.corda.sandbox.CandidateMethod.State.*;
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
|
||||
/**
|
||||
@ -39,14 +41,14 @@ public final class WhitelistCheckingClassVisitor extends ClassVisitor {
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
currentClassName = name;
|
||||
|
||||
if (resolveState(Utils.convertInternalFormToQualifiedClassName(superName)) == DISALLOWED) {
|
||||
if (resolveState(Utils.convertInternalFormToQualifiedClassName(superName)) == CandidateMethod.State.DISALLOWED) {
|
||||
candidacyStatus.setLoadable(false);
|
||||
candidacyStatus.setReason("Superclass " + superName + " could not be loaded");
|
||||
return;
|
||||
}
|
||||
|
||||
for (final String interfaceName : interfaces) {
|
||||
if (resolveState(Utils.convertInternalFormToQualifiedClassName(interfaceName)) == DISALLOWED) {
|
||||
if (resolveState(Utils.convertInternalFormToQualifiedClassName(interfaceName)) == CandidateMethod.State.DISALLOWED) {
|
||||
candidacyStatus.setLoadable(false);
|
||||
candidacyStatus.setReason("Interface " + interfaceName + " could not be loaded");
|
||||
return;
|
||||
@ -137,7 +139,7 @@ public final class WhitelistCheckingClassVisitor extends ClassVisitor {
|
||||
|
||||
final String toLoadQualified = Utils.convertInternalMethodNameToQualifiedClassName(internalName);
|
||||
if (!Utils.shouldAttemptToTransitivelyLoad(toLoadQualified)
|
||||
|| resolveState(toLoadQualified) == DISALLOWED) {
|
||||
|| resolveState(toLoadQualified) == CandidateMethod.State.DISALLOWED) {
|
||||
referred.disallowed(internalName + " is DISALLOWED");
|
||||
candidacyStatus.setLoadable(false);
|
||||
candidacyStatus.setReason(candidateMethod.getReason());
|
||||
@ -169,14 +171,14 @@ public final class WhitelistCheckingClassVisitor extends ClassVisitor {
|
||||
clz = loader.loadClass(qualifiedClassname);
|
||||
candidacyStatus.decRecursiveCount();
|
||||
} catch (ClassNotFoundException ex) {
|
||||
return DISALLOWED;
|
||||
return CandidateMethod.State.DISALLOWED;
|
||||
}
|
||||
if (clz == null) {
|
||||
LOGGER.error("Couldn't load: " + qualifiedClassname);
|
||||
return DISALLOWED;
|
||||
return CandidateMethod.State.DISALLOWED;
|
||||
}
|
||||
|
||||
return DETERMINISTIC;
|
||||
return CandidateMethod.State.DETERMINISTIC;
|
||||
}
|
||||
|
||||
public CandidacyStatus getCandidacyStatus() {
|
@ -1,14 +1,15 @@
|
||||
package com.r3cev.visitors;
|
||||
package net.corda.sandbox.visitors;
|
||||
|
||||
import com.r3cev.CandidacyStatus;
|
||||
import com.r3cev.CandidateMethod;
|
||||
import net.corda.sandbox.CandidacyStatus;
|
||||
import net.corda.sandbox.CandidateMethod;
|
||||
import net.corda.sandbox.*;
|
||||
import org.objectweb.asm.Handle;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import static com.r3cev.CandidateMethod.State.*;
|
||||
import com.r3cev.Utils;
|
||||
import static net.corda.sandbox.CandidateMethod.State.*;
|
||||
import net.corda.sandbox.Utils;
|
||||
import org.objectweb.asm.Label;
|
||||
|
||||
/**
|
||||
@ -135,12 +136,12 @@ final class WhitelistCheckingMethodVisitor extends MethodVisitor {
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
// Start from the assumption that the method is deterministic, and try to disprove
|
||||
CandidateMethod.State checkState = DETERMINISTIC;
|
||||
CandidateMethod.State checkState = CandidateMethod.State.DETERMINISTIC;
|
||||
final CandidateMethod candidateMethod = candidacyStatus.getCandidateMethod(currentMethodName);
|
||||
if (candidateMethod == null) {
|
||||
throw new IllegalArgumentException(currentMethodName + " not found in CandidacyStatus");
|
||||
}
|
||||
if (candidateMethod.getCurrentState() == DISALLOWED) {
|
||||
if (candidateMethod.getCurrentState() == CandidateMethod.State.DISALLOWED) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -151,13 +152,13 @@ final class WhitelistCheckingMethodVisitor extends MethodVisitor {
|
||||
case DETERMINISTIC:
|
||||
break;
|
||||
case MENTIONED:
|
||||
checkState = MENTIONED;
|
||||
checkState = CandidateMethod.State.MENTIONED;
|
||||
break;
|
||||
case DISALLOWED:
|
||||
checkState = DISALLOWED;
|
||||
checkState = CandidateMethod.State.DISALLOWED;
|
||||
break CHECK;
|
||||
case SCANNED:
|
||||
checkState = MENTIONED;
|
||||
checkState = CandidateMethod.State.MENTIONED;
|
||||
if (referredMethod != candidateMethod)
|
||||
throw new IllegalStateException("Illegal state of method " + referredMethod.getInternalMethodName() + " occurred when visiting method " + currentMethodName);
|
||||
break;
|
||||
@ -168,7 +169,7 @@ final class WhitelistCheckingMethodVisitor extends MethodVisitor {
|
||||
candidateMethod.setCurrentState(checkState);
|
||||
|
||||
// If this methods state hasn't already been determined, it should be set to SCANNED
|
||||
if (candidateMethod.getCurrentState() == MENTIONED)
|
||||
if (candidateMethod.getCurrentState() == CandidateMethod.State.MENTIONED)
|
||||
candidateMethod.scanned();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package sandbox.com.r3cev.costing;
|
||||
package sandbox.net.corda.sandbox.costing;
|
||||
|
||||
/**
|
||||
* A helper class that just forwards any static sandboxed calls to the real runtime
|
||||
@ -10,23 +10,23 @@ package sandbox.com.r3cev.costing;
|
||||
public class RuntimeCostAccounter {
|
||||
|
||||
public static void recordJump() {
|
||||
com.r3cev.costing.RuntimeCostAccounter.recordJump();
|
||||
net.corda.sandbox.costing.RuntimeCostAccounter.recordJump();
|
||||
}
|
||||
|
||||
public static void recordAllocation(final String typeName) {
|
||||
com.r3cev.costing.RuntimeCostAccounter.recordAllocation(typeName);
|
||||
net.corda.sandbox.costing.RuntimeCostAccounter.recordAllocation(typeName);
|
||||
}
|
||||
|
||||
public static void recordArrayAllocation(final int length, final int multiplier) {
|
||||
com.r3cev.costing.RuntimeCostAccounter.recordArrayAllocation(length, multiplier);
|
||||
net.corda.sandbox.costing.RuntimeCostAccounter.recordArrayAllocation(length, multiplier);
|
||||
}
|
||||
|
||||
public static void recordMethodCall() {
|
||||
com.r3cev.costing.RuntimeCostAccounter.recordMethodCall();
|
||||
net.corda.sandbox.costing.RuntimeCostAccounter.recordMethodCall();
|
||||
}
|
||||
|
||||
public static void recordThrow() {
|
||||
com.r3cev.costing.RuntimeCostAccounter.recordThrow();
|
||||
net.corda.sandbox.costing.RuntimeCostAccounter.recordThrow();
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.r3cev;
|
||||
package net.corda.sandbox;
|
||||
|
||||
import com.r3cev.CandidateMethod;
|
||||
import net.corda.sandbox.CandidateMethod;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.r3cev;
|
||||
package net.corda.sandbox;
|
||||
|
||||
class Constants {
|
||||
public final static String INVALID_CLASS = "foobar";
|
@ -1,6 +1,9 @@
|
||||
package com.r3cev;
|
||||
package net.corda.sandbox;
|
||||
|
||||
import net.corda.sandbox.costing.RuntimeCostAccounter;
|
||||
import net.corda.sandbox.costing.*;
|
||||
import org.junit.*;
|
||||
|
||||
import com.r3cev.costing.RuntimeCostAccounter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
@ -45,7 +48,7 @@ public class TestUtils {
|
||||
}
|
||||
|
||||
public static void checkAllCosts(final int allocCost, final int jumpCost, final int invokeCost, final int throwCost) {
|
||||
assertEquals(allocCost, RuntimeCostAccounter.getAllocationCost());
|
||||
Assert.assertEquals(allocCost, RuntimeCostAccounter.getAllocationCost());
|
||||
assertEquals(jumpCost, RuntimeCostAccounter.getJumpCost());
|
||||
assertEquals(invokeCost, RuntimeCostAccounter.getInvokeCost());
|
||||
assertEquals(throwCost, RuntimeCostAccounter.getThrowCost());
|
@ -1,4 +1,4 @@
|
||||
package com.r3cev;
|
||||
package net.corda.sandbox;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
@ -1,7 +1,7 @@
|
||||
package com.r3cev.costing;
|
||||
package net.corda.sandbox.costing;
|
||||
|
||||
import com.r3cev.TestUtils;
|
||||
import com.r3cev.WhitelistClassLoader;
|
||||
import net.corda.sandbox.TestUtils;
|
||||
import net.corda.sandbox.WhitelistClassLoader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URISyntaxException;
|
@ -1,8 +1,8 @@
|
||||
package com.r3cev.costing;
|
||||
package net.corda.sandbox.costing;
|
||||
|
||||
import com.r3cev.TestUtils;
|
||||
import static com.r3cev.TestUtils.*;
|
||||
import com.r3cev.Utils;
|
||||
import net.corda.sandbox.TestUtils;
|
||||
import static net.corda.sandbox.TestUtils.*;
|
||||
import net.corda.sandbox.Utils;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URISyntaxException;
|
Loading…
x
Reference in New Issue
Block a user