kartikeya sharma
AI Verification · Applied Cryptography · AI Safety

Proving A Function Is One-Way By Assuming It Is Not

Friday, August 21, 2026

CryptographyBitcoin

Last week we looked at one-way functions, and we clearly said that they follow two properties: easy to compute and hard to invert.

If it's easy to compute, then we have a PPT algorithm C such that for all x, which is the input, which comes from a set of n-bit strings, the probability that this algorithm C, when given this input, produces a valid output for our function should be one.

Pr[ C(x) = f(x) ] = 1    for all x ∈ {0,1}n

The second thing, which is the more interesting one: a one-way function has to be hard to invert. We have an input coming from a set of n-bit strings, and when we pass this input into our function, we get y as our output. If we have an adversary who, given only the security parameter and the output, is able to produce a valid input x′ such that when we plug in this x′ we get back the original output, then for it to be hard to invert, this probability has to be negligible.

Pr[ f(x′) = y  :  x ← {0,1}n, y = f(x), x′ ← A(1n, y) ] ≤ negl(n)

The adversary is bounded

PPT is a probabilistic polynomial time algorithm, and all we need to remember for now is that this is pretty much a polynomial function with a randomness tape. It has an infinite source of randomness.

In cryptography, most of the definitions do assume that the adversary is bounded. We don't assume that they have infinite compute power or infinite time, because those are impractical. If the adversary were unbounded, only perfect security could protect against it, and perfect security has its own downsides. Something like the one-time pad is a perfectly secure algorithm, where even if an adversary has infinite time, infinite power, a supercomputer, they still can't break the algorithm. But there are many downsides to the one-time pad. So we don't assume that the adversary is unbounded. That's why we always define the adversary as an algorithm that's polynomially bounded with respect to the input.

Informally, negligible is saying that the probability that any adversary can invert a function should be as good as random guessing. For example, if we have 10 numbers, 1, 2, 3, up to 10, and I picked 3, and I told you to guess what number I picked, the probability that you'll get it right is 1/10. Obviously, everyone can just randomly guess, and if they do break the algorithm in that case, it's not considered a bad thing, because it was still secure within this bound of negligible.

The adversary also gets 1n, which is just n ones in a row. So the adversary does know the size of the input. That's public information.

Multiplication is only a weak one-way function

A strong one-way function is one where the adversary only succeeds with negligible probability. A weak one-way function is one where the adversary may invert f on a significant fraction of inputs, but there is a noticeable set of inputs where the adversary cannot invert.

We looked at this weak one-way function for just multiplication: integer factorization, where the input domain was any n-bit integer. If we have a function f which takes x and y, it just multiplies x and y, and let's call this N. Given N, can we find any x′ and y′ such that f(x′, y′) gives N again? It doesn't have to be the exact x. We have to find any valid input that satisfies this condition.

If N is even, one factor is 2 and the other factor is N/2, and that satisfies our integer factorization. We found two valid factors that, once multiplied, give N.

Here is that trick as an actual adversary. It divides N by 2, or by every prime up to a bound, and wins if anything divides. How much of the input space does it invert, and what happens when the inputs are only allowed to be primes?

Input domain
The adversary tries dividing by
–of inputs inverted
–it cannot invert
–
–
Each square is one random input (x, y), multiplied to N = x · y. A filled square means the adversary found a valid x′, y′ with x′ · y′ = N. 400 fresh samples are drawn every time you change something.

On any integers, dividing by 2 alone wins about three times in four, whatever n is: N is odd only when x and y are both odd. On primes, the same adversary only wins while the primes are small enough to be on its list.

The factoring assumption

If our input domain is not any n-bit integer, but all n-bit prime numbers, then there is a widely believed assumption called the factoring assumption that kicks in. A lot of security is based on this assumption. If anyone is able to disprove this, then many things will break on the internet. There are several one-way functions and several assumptions that go with those one-way functions, and people just have not been able to disprove those assumptions yet, so we believe them to be true right now, but they may be broken in the future.

I'm going to call the set which contains all n-bit prime numbers capital Πn. The factoring assumption states: we have two numbers, p, which comes from our set of all n-bit primes, and q, which also comes from the set of all n-bit primes. We multiply them to produce N, so p · q = N. If we give that N to an adversary, the probability that they can find factors that multiply to give N is, again, negligible. The larger they are, the harder it is.

Pr[ p′ · q′ = N  :  p, q ← Πn, N = p · q, (p′, q′) ← A(N) ] ≤ negl(n)

So what we said so far is: if p and q are any integers, easy-ish to invert. If p and q are primes, very hard to invert.

The proof

Let's try to prove why this is true. I'm showing you a proof because most proofs in cryptography rely on this way of proving things, which is proving by contradiction. Initially, I found this also pretty confusing, but I think I'm starting to get the hang of it.

  1. Assume f is not a one-way function. If it's not a one-way function, that means the adversary can find p and q such that when they are multiplied, they give the original N, where N = f(p, q). It implies that this adversary is able to find a valid preimage with high probability. Remember, when we talk about an adversary, we're talking about an algorithm. The adversary is a probabilistic polynomial time algorithm.
  2. Construct B to violate the factoring assumption. This algorithm B uses A to break the factoring assumption. It takes in the output, which is the product of two primes, and invokes A on input N. The adversary A outputs p′ and q′. First of all, we don't even know if they're prime, so B checks if p′ and q′ are prime. This can be done pretty fast, in polynomial time. If you use something like Python, you can just call a function, but inside, they are using very fast algorithms to do a primality test. Then we also check if, when we multiply p′ and q′, we get N, which was given to B in the first place. If both of these are true, then output our factors p′, q′. If one is no or two is no, then just output something like fail.
  3. B runs in polynomial time. Primality testing is a polynomial time algorithm, and A is always a polynomially time-bounded algorithm. Both of these run in polynomial time; therefore, this whole algorithm runs in polynomial time. And the success probability of this algorithm B is at least the success probability of A, which we know is high. B is like a hollow function. It's just using A, with one more function.
  4. B is a polynomial algorithm which can find the factors of a number that is the product of two primes, with high probability, in polynomial time. That violates the factoring assumption, which shows that our initial assumption, that f is not a one-way function, is false. And since it's false, f must be a one-way function.

You can see how this whole proof relied on the factoring assumption being true. We call these proofs by contradiction. We basically try to assume the opposite thing. Then we show what happens when the opposite thing is true. And then we look at our strongly believed assumptions, like in this case the factoring assumption, and we say: hey, wait a minute. If this was true, it violates the factoring assumption. So it must be false.

Opening the input space back up

What we've created is a strong one-way function, but it only works over this special input domain, which is primes. Very informally, what you could do is open up the input domain to all integers again, similar to our weak one-way function, and have an algorithm that runs a primality test on the inputs, which runs in polynomial time. If the inputs p, q are prime, then run the function f(p, q) = p · q. Otherwise, just output fail.

We just added an extra layer. We allow the user to send in any numbers, but we're only going to actually do the multiplication if they are primes. The rest still remains true, because we know that if they are primes, then we have a proof that says that it is a one-way function.

Weak one-way functions are not useless

There's a proof that says any weak one-way function can be converted into a strong one-way function. The person who showed this is Yao.

Suppose you have your input x. Now you break the input into smaller chunks. This x becomes x1, x2, x3, and so on. The more chunks you can break it into, the better the security is. Assume that the adversary can invert, let's just say, 70% of the time. I'm making this up. Run the weak one-way function on the first chunk, second chunk, third chunk, and so on, until we have run the weak one-way function on all of x.

Since we've broken it up into many chunks, they basically have to invert this successfully and this and this. It's not or, it's and. Even if they fail on a single piece of the input, security holds. Their success probability is the probability of inverting one chunk, raised to the power k, where k is how many chunks you split it into. In this case, it's 0.7k, and as we split it into more chunks, it drops and drops and drops until it also becomes negligible.

f′(x1, x2, …, xk) = f(x1) || f(x2) || … || f(xk)   ⇒   Pr[invert f′] = 0.7k

Someone asked how we can assume the function itself can be split up like that. x is from the input space. It's basically bits. You can keep it large so it can be split into chunks. The input is just a large n-bit binary string.

So how many chunks does it take? Below, the adversary's chance on the whole input is put in the same terms as guessing a number I picked.

–success on all k chunks
–as good as guessing 1 in
–chunks to reach 2−128
–
The dashed lines mark 2−80 and 2−128, two common thresholds for "negligible" in practice. The curve is a straight line on a log scale because each chunk multiplies the adversary's chance by the same factor.

At 70% per chunk, 249 chunks are enough to make the adversary's chance smaller than 2−128. Even an adversary that wins 99% of the time on one chunk is pushed under that line, it just takes about nine thousand chunks.

Where this goes next

To my knowledge, Bitcoin security does not rely on the factoring assumption. But there is this other one-way function that Bitcoin does use actively, and that's what this has all been leading up to: the discrete log problem. First you choose a prime p; the larger it is, the safer. Then you also choose a generator g in a special group, which is the multiplicative group. It's easy to calculate gx mod p, but given the generator, the prime, and y, which are all public information, finding an x such that gx = y mod p is hard.

easy:   y = gx mod p      hard:   given (g, p, y), find x
← Back to all articles