Skip to content

Instantly share code, notes, and snippets.

@chejazi
Created June 30, 2016 19:35
Show Gist options
  • Save chejazi/ccfc84342261e61923b05340744145cd to your computer and use it in GitHub Desktop.
Save chejazi/ccfc84342261e61923b05340744145cd to your computer and use it in GitHub Desktop.
contract Inconsistency {
struct Value {
uint badnum;
uint number;
}
struct Container {
uint[] valueIndices;
Value[] values;
}
Container[] containers;
uint[] valueIndices;
uint INDEX_ZERO = 0;
uint public debug;
// Called with params: containerIndex=0, valueIndex=0
function levelIII(uint containerIndex, uint valueIndex) private {
Container container = containers[containerIndex];
Value value = container.values[valueIndex];
// This sets debug to badnum instead of zero
debug = container.valueIndices[value.number];
}
// `for` loop and `INDEX_ZERO` are both necessary to trigger
function LevelII() private {
for (uint i = 0; i < valueIndices.length; i++) {
levelIII(INDEX_ZERO, valueIndices[i]);
}
}
function Trigger() public {
containers.length++;
Container container = containers[0];
uint index = container.values.length;
container.values.push(Value({
badnum: 9000,
number: index
}));
container.valueIndices.length++;
container.valueIndices[0] = index;
valueIndices.length++;
valueIndices[0] = index;
LevelII();
}
// This function and its body are necessary
function DoNotCallButDoNotDelete() public {
LevelII();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment